From 189060dd864e83b476f03edd8e2fb217f9ab6012 Mon Sep 17 00:00:00 2001 From: topsworld Date: Tue, 17 Dec 2024 21:30:55 +0800 Subject: [PATCH] fix: add STATE_ON to devices that not define mode --- custom_components/xiaomi_home/water_heater.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/custom_components/xiaomi_home/water_heater.py b/custom_components/xiaomi_home/water_heater.py index a6217ae..ee6a91d 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_ON, STATE_OFF, ATTR_TEMPERATURE, WaterHeaterEntity, @@ -151,6 +152,8 @@ def __init__( self._attr_supported_features |= ( WaterHeaterEntityFeature.OPERATION_MODE) self._prop_mode = prop + if not self._attr_operation_list: + self._attr_operation_list = [STATE_ON] self._attr_operation_list.append(STATE_OFF) async def async_turn_on(self) -> None: @@ -173,6 +176,9 @@ async def async_set_operation_mode(self, operation_mode: str) -> None: if operation_mode == STATE_OFF: await self.set_property_async(prop=self._prop_on, value=False) return + if operation_mode == STATE_ON: + await self.set_property_async(prop=self._prop_on, value=True) + 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) @@ -199,6 +205,8 @@ def current_operation(self) -> Optional[str]: """Return the current mode.""" if self.get_prop_value(prop=self._prop_on) is False: return STATE_OFF + if not self._prop_mode and self.get_prop_value(prop=self._prop_on): + return STATE_ON return self.__get_mode_description( key=self.get_prop_value(prop=self._prop_mode))