Skip to content

Commit

Permalink
fix: water heater STATE_ON
Browse files Browse the repository at this point in the history
  • Loading branch information
SusanPhevos committed Jan 7, 2025
1 parent d65fe32 commit 56e9f1d
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions custom_components/xiaomi_home/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class WaterHeater(MIoTServiceEntity, WaterHeaterEntity):
_prop_target_temp: Optional[MIoTSpecProperty]
_prop_mode: Optional[MIoTSpecProperty]

_mode_list: Optional[dict[Any, Any]]
_mode_map: Optional[dict[int, str]]

def __init__(
self, miot_device: MIoTDevice, entity_data: MIoTEntityData
Expand All @@ -102,6 +102,7 @@ def __init__(
super().__init__(miot_device=miot_device, entity_data=entity_data)
self._attr_temperature_unit = None
self._attr_supported_features = WaterHeaterEntityFeature(0)
self._attr_operation_list = None
self._prop_on = None
self._prop_temp = None
self._prop_target_temp = None
Expand Down Expand Up @@ -145,15 +146,17 @@ def __init__(
_LOGGER.error(
'mode value_list is None, %s', self.entity_id)
continue
self._mode_list = {
self._mode_map = {
item['value']: item['description']
for item in prop.value_list}
self._attr_operation_list = list(self._mode_list.values())
self._attr_operation_list = list(self._mode_map.values())
self._attr_supported_features |= (
WaterHeaterEntityFeature.OPERATION_MODE)
self._prop_mode = prop
if not self._attr_operation_list:
if self._attr_operation_list is None:
self._attr_operation_list = [STATE_ON]
else:
self._attr_operation_list.append(STATE_ON)
self._attr_operation_list.append(STATE_OFF)

async def async_turn_on(self) -> None:
Expand Down Expand Up @@ -184,7 +187,8 @@ async def async_set_operation_mode(self, operation_mode: str) -> None:
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))
value=self.get_map_value(
map_=self._mode_map, description=operation_mode))

async def async_turn_away_mode_on(self) -> None:
"""Set the water heater to away mode."""
Expand All @@ -207,20 +211,4 @@ def current_operation(self) -> Optional[str]:
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))

def __get_mode_description(self, key: int) -> Optional[str]:
"""Convert mode value to description."""
if self._mode_list is None:
return None
return self._mode_list.get(key, None)

def __get_mode_value(self, description: str) -> Optional[int]:
"""Convert mode description to value."""
if self._mode_list is None:
return None
for key, value in self._mode_list.items():
if value == description:
return key
return None
return self._mode_map[self.get_prop_value(prop=self._prop_mode)]

0 comments on commit 56e9f1d

Please sign in to comment.