Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: water heater entity add STATE_OFF #107

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions custom_components/xiaomi_home/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
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,
WaterHeaterEntityFeature
Expand Down Expand Up @@ -114,8 +116,6 @@ def __init__(
# temperature
if prop.name == 'temperature':
if isinstance(prop.value_range, dict):
self._attr_min_temp = prop.value_range['min']
self._attr_max_temp = prop.value_range['max']
if (
self._attr_temperature_unit is None
and prop.external_unit
Expand All @@ -128,6 +128,9 @@ def __init__(
self.entity_id)
# target-temperature
if prop.name == 'target-temperature':
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:
self._attr_temperature_unit = prop.external_unit
self._attr_supported_features |= (
Expand All @@ -149,6 +152,9 @@ 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:
"""Turn the water heater on."""
Expand All @@ -167,6 +173,15 @@ 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 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)
await self.set_property_async(
prop=self._prop_mode,
value=self.__get_mode_value(description=operation_mode))
Expand All @@ -188,6 +203,10 @@ 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
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
Loading