From 91b07cce20a909915de373fe9bf66b8086048317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hjelseth=20H=C3=B8yer?= Date: Wed, 27 Oct 2021 11:10:54 +0200 Subject: [PATCH] Fix available for Mill (#58510) --- homeassistant/components/mill/climate.py | 9 ++++++++- homeassistant/components/mill/sensor.py | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/mill/climate.py b/homeassistant/components/mill/climate.py index 0361322222b..3cc8d58abda 100644 --- a/homeassistant/components/mill/climate.py +++ b/homeassistant/components/mill/climate.py @@ -84,6 +84,8 @@ class MillHeater(CoordinatorEntity, ClimateEntity): super().__init__(coordinator) + self._available = False + self._id = heater.device_id self._attr_unique_id = heater.device_id self._attr_name = heater.name @@ -131,6 +133,11 @@ class MillHeater(CoordinatorEntity, ClimateEntity): ) await self.coordinator.async_request_refresh() + @property + def available(self) -> bool: + """Return True if entity is available.""" + return super().available and self._available + @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" @@ -139,7 +146,7 @@ class MillHeater(CoordinatorEntity, ClimateEntity): @callback def _update_attr(self, heater): - self._attr_available = heater.available + self._available = heater.available self._attr_extra_state_attributes = { "open_window": heater.open_window, "heating": heater.is_heating, diff --git a/homeassistant/components/mill/sensor.py b/homeassistant/components/mill/sensor.py index d11a3e43cf2..1b9e84eafa8 100644 --- a/homeassistant/components/mill/sensor.py +++ b/homeassistant/components/mill/sensor.py @@ -124,6 +124,7 @@ class MillSensor(CoordinatorEntity, SensorEntity): self._id = mill_device.device_id self.entity_description = entity_description + self._available = False self._attr_name = f"{mill_device.name} {entity_description.name}" 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.async_write_ha_state() + @property + def available(self) -> bool: + """Return True if entity is available.""" + return super().available and self._available + @callback def _update_attr(self, device): - self._attr_available = device.available + self._available = device.available self._attr_native_value = getattr(device, self.entity_description.key)