Skip to content

Commit

Permalink
♨️ improve water_heater (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Mar 5, 2021
1 parent fb7215e commit 132822e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions custom_components/xiaomi_miot/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def __init__(self, config, miot_service: MiotService, **kwargs):
super().__init__(name, self._device, miot_service, config=config)
self._add_entities = config.get('add_entities') or {}

self._prop_status = miot_service.get_property('status')
self._prop_mode = miot_service.get_property('mode')
self._prop_modes = miot_service.get_properties('mode', 'water_level')
self._prop_temperature = miot_service.get_property('temperature', 'indoor_temperature')
self._prop_target_temp = miot_service.get_property('target_temperature')
Expand All @@ -88,8 +90,30 @@ async def async_update(self):
if not self._available:
return
if self._prop_power:
if not self._prop_power.readable and self._prop_status:
# https://github.com/al-one/hass-xiaomi-miot/issues/30
val = self._prop_status.from_dict(self._state_attrs)
off = val in self._prop_status.list_search('Off')
self.update_attrs({
self._prop_power.full_name: not off,
})
self._update_sub_entities(self._prop_power.name)

@property
def state(self):
"""Return the current state."""
sta = self.current_operation
mds = []
if self._prop_mode:
mds = self._prop_mode.list_descriptions()
if sta is None or sta not in mds:
if self._prop_status:
val = self._prop_status.from_dict(self._state_attrs)
sta = self._prop_status.list_description(val)
if sta:
sta = str(sta).lower()
return sta

@property
def current_operation(self):
"""Return current operation ie. eco, electric, performance, ..."""
Expand Down

0 comments on commit 132822e

Please # to comment.