From bf435374d22130b254e74f5b9bf0d6a0339d5b97 Mon Sep 17 00:00:00 2001 From: topsworld Date: Tue, 17 Dec 2024 20:50:01 +0800 Subject: [PATCH] fix: water heater entity add STATE_OFF --- custom_components/xiaomi_home/water_heater.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/custom_components/xiaomi_home/water_heater.py b/custom_components/xiaomi_home/water_heater.py index 1828316d..bcf158d8 100644 --- a/custom_components/xiaomi_home/water_heater.py +++ b/custom_components/xiaomi_home/water_heater.py @@ -53,6 +53,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.components.water_heater import ( + STATE_OFF, ATTR_TEMPERATURE, WaterHeaterEntity, WaterHeaterEntityFeature @@ -116,6 +117,7 @@ def __init__( if isinstance(prop.value_range, dict): self._attr_min_temp = prop.value_range['min'] self._attr_max_temp = prop.value_range['max'] + self._attr_precision = prop.value_range['step'] if ( self._attr_temperature_unit is None and prop.external_unit @@ -149,6 +151,7 @@ def __init__( self._attr_supported_features |= ( WaterHeaterEntityFeature.OPERATION_MODE) self._prop_mode = prop + self._attr_operation_list.append(STATE_OFF) async def async_turn_on(self) -> None: """Turn the water heater on.""" @@ -167,6 +170,12 @@ async def async_set_operation_mode(self, operation_mode: str) -> None: """Set the operation mode of the water heater. Must be in the operation_list. """ + if operation_mode == STATE_OFF: + await self.set_property_async(prop=self._prop_on, value=False) + return + if self.get_prop_value(prop=self._prop_on) is False: + await self.set_property_async( + prop=self._prop_on, value=True, update=False) await self.set_property_async( prop=self._prop_mode, value=self.__get_mode_value(description=operation_mode)) @@ -188,6 +197,8 @@ def target_temperature(self) -> Optional[float]: @property def current_operation(self) -> Optional[str]: """Return the current mode.""" + if self.get_prop_value(prop=self._prop_on) is False: + return STATE_OFF return self.__get_mode_description( key=self.get_prop_value(prop=self._prop_mode))