Skip to content

Commit

Permalink
fix: water heater entity add STATE_OFF
Browse files Browse the repository at this point in the history
  • Loading branch information
topsworld committed Dec 17, 2024
1 parent 8a1e464 commit ac136d9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 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_OFF,
ATTR_TEMPERATURE,
WaterHeaterEntity,
WaterHeaterEntityFeature
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand All @@ -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))
Expand All @@ -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))

Expand Down

0 comments on commit ac136d9

Please sign in to comment.