Skip to content

Commit

Permalink
fix: add STATE_ON to devices that not define mode
Browse files Browse the repository at this point in the history
  • Loading branch information
topsworld committed Dec 17, 2024
1 parent 1fd5e8e commit 189060d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions custom_components/xiaomi_home/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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))

Expand Down

0 comments on commit 189060d

Please sign in to comment.