Use shorthand attributes in SPC (#100217)

pull/58707/head^2
Joost Lekkerkerker 2023-09-12 18:01:05 +02:00 committed by GitHub
parent 4e202eb376
commit 71c4f675e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 15 deletions

View File

@ -64,6 +64,7 @@ class SpcAlarm(alarm.AlarmControlPanelEntity):
"""Initialize the SPC alarm panel.""" """Initialize the SPC alarm panel."""
self._area = area self._area = area
self._api = api self._api = api
self._attr_name = area.name
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Call for adding new entities.""" """Call for adding new entities."""
@ -80,11 +81,6 @@ class SpcAlarm(alarm.AlarmControlPanelEntity):
"""Call update method.""" """Call update method."""
self.async_schedule_update_ha_state(True) self.async_schedule_update_ha_state(True)
@property
def name(self) -> str:
"""Return the name of the device."""
return self._area.name
@property @property
def changed_by(self) -> str: def changed_by(self) -> str:
"""Return the user the last change was triggered by.""" """Return the user the last change was triggered by."""

View File

@ -53,6 +53,8 @@ class SpcBinarySensor(BinarySensorEntity):
def __init__(self, zone: Zone) -> None: def __init__(self, zone: Zone) -> None:
"""Initialize the sensor device.""" """Initialize the sensor device."""
self._zone = zone self._zone = zone
self._attr_name = zone.name
self._attr_device_class = _get_device_class(zone.type)
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Call for adding new entities.""" """Call for adding new entities."""
@ -69,17 +71,7 @@ class SpcBinarySensor(BinarySensorEntity):
"""Call update method.""" """Call update method."""
self.async_schedule_update_ha_state(True) self.async_schedule_update_ha_state(True)
@property
def name(self) -> str:
"""Return the name of the device."""
return self._zone.name
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Whether the device is switched on.""" """Whether the device is switched on."""
return self._zone.input == ZoneInput.OPEN return self._zone.input == ZoneInput.OPEN
@property
def device_class(self) -> BinarySensorDeviceClass | None:
"""Return the device class."""
return _get_device_class(self._zone.type)