Fix available for Mill (#58510)

This commit is contained in:
Daniel Hjelseth Høyer 2021-10-27 11:10:54 +02:00 committed by GitHub
parent ac08d05b76
commit 91b07cce20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -84,6 +84,8 @@ class MillHeater(CoordinatorEntity, ClimateEntity):
super().__init__(coordinator) super().__init__(coordinator)
self._available = False
self._id = heater.device_id self._id = heater.device_id
self._attr_unique_id = heater.device_id self._attr_unique_id = heater.device_id
self._attr_name = heater.name self._attr_name = heater.name
@ -131,6 +133,11 @@ class MillHeater(CoordinatorEntity, ClimateEntity):
) )
await self.coordinator.async_request_refresh() await self.coordinator.async_request_refresh()
@property
def available(self) -> bool:
"""Return True if entity is available."""
return super().available and self._available
@callback @callback
def _handle_coordinator_update(self) -> None: def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator.""" """Handle updated data from the coordinator."""
@ -139,7 +146,7 @@ class MillHeater(CoordinatorEntity, ClimateEntity):
@callback @callback
def _update_attr(self, heater): def _update_attr(self, heater):
self._attr_available = heater.available self._available = heater.available
self._attr_extra_state_attributes = { self._attr_extra_state_attributes = {
"open_window": heater.open_window, "open_window": heater.open_window,
"heating": heater.is_heating, "heating": heater.is_heating,

View File

@ -124,6 +124,7 @@ class MillSensor(CoordinatorEntity, SensorEntity):
self._id = mill_device.device_id self._id = mill_device.device_id
self.entity_description = entity_description self.entity_description = entity_description
self._available = False
self._attr_name = f"{mill_device.name} {entity_description.name}" self._attr_name = f"{mill_device.name} {entity_description.name}"
self._attr_unique_id = f"{mill_device.device_id}_{entity_description.key}" self._attr_unique_id = f"{mill_device.device_id}_{entity_description.key}"
@ -144,7 +145,12 @@ class MillSensor(CoordinatorEntity, SensorEntity):
self._update_attr(self.coordinator.data[self._id]) self._update_attr(self.coordinator.data[self._id])
self.async_write_ha_state() self.async_write_ha_state()
@property
def available(self) -> bool:
"""Return True if entity is available."""
return super().available and self._available
@callback @callback
def _update_attr(self, device): def _update_attr(self, device):
self._attr_available = device.available self._available = device.available
self._attr_native_value = getattr(device, self.entity_description.key) self._attr_native_value = getattr(device, self.entity_description.key)