Use shorthand attributes for Elmax (#99277)

This commit is contained in:
Joost Lekkerkerker 2023-08-30 12:07:55 +02:00 committed by GitHub
parent 7d70b42e4a
commit a4818c5f54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 33 deletions

View File

@ -60,12 +60,9 @@ async def async_setup_entry(
class ElmaxSensor(ElmaxEntity, BinarySensorEntity): class ElmaxSensor(ElmaxEntity, BinarySensorEntity):
"""Elmax Sensor entity implementation.""" """Elmax Sensor entity implementation."""
_attr_device_class = BinarySensorDeviceClass.DOOR
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if the binary sensor is on.""" """Return true if the binary sensor is on."""
return self.coordinator.get_zone_state(self._device.endpoint_id).opened return self.coordinator.get_zone_state(self._device.endpoint_id).opened
@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this device, from component DEVICE_CLASSES."""
return BinarySensorDeviceClass.DOOR

View File

@ -157,35 +157,16 @@ class ElmaxEntity(CoordinatorEntity[ElmaxCoordinator]):
super().__init__(coordinator=coordinator) super().__init__(coordinator=coordinator)
self._panel = panel self._panel = panel
self._device = elmax_device self._device = elmax_device
self._panel_version = panel_version self._attr_unique_id = elmax_device.endpoint_id
self._client = coordinator.http_client self._attr_name = elmax_device.name
self._attr_device_info = DeviceInfo(
@property identifiers={(DOMAIN, panel.hash)},
def panel_id(self) -> str: name=panel.get_name_by_user(
"""Retrieve the panel id.""" coordinator.http_client.get_authenticated_username()
return self._panel.hash
@property
def unique_id(self) -> str | None:
"""Provide a unique id for this entity."""
return self._device.endpoint_id
@property
def name(self) -> str | None:
"""Return the entity name."""
return self._device.name
@property
def device_info(self) -> DeviceInfo:
"""Return device specific attributes."""
return DeviceInfo(
identifiers={(DOMAIN, self._panel.hash)},
name=self._panel.get_name_by_user(
self.coordinator.http_client.get_authenticated_username()
), ),
manufacturer="Elmax", manufacturer="Elmax",
model=self._panel_version, model=panel_version,
sw_version=self._panel_version, sw_version=panel_version,
) )
@property @property

View File

@ -68,7 +68,7 @@ class ElmaxSwitch(ElmaxEntity, SwitchEntity):
return self.coordinator.get_actuator_state(self._device.endpoint_id).opened return self.coordinator.get_actuator_state(self._device.endpoint_id).opened
async def _wait_for_state_change(self) -> bool: async def _wait_for_state_change(self) -> bool:
"""Refresh data and wait until the state state changes.""" """Refresh data and wait until the state changes."""
old_state = self.coordinator.get_actuator_state(self._device.endpoint_id).opened old_state = self.coordinator.get_actuator_state(self._device.endpoint_id).opened
# Wait a bit at first to let Elmax cloud assimilate the new state. # Wait a bit at first to let Elmax cloud assimilate the new state.