Skip to content

Commit

Permalink
🔥 add support aux_heat
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Mar 2, 2021
1 parent 4bee34b commit cff53c7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
28 changes: 27 additions & 1 deletion custom_components/xiaomi_miot/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(self, config: dict, miot_service: MiotService):

self._prop_power = miot_service.bool_property('on')
self._prop_mode = miot_service.get_property('mode')
self._prop_heater = miot_service.bool_property('heater')
self._prop_target_temp = miot_service.get_property('target_temperature')
self._prop_target_humi = miot_service.get_property('target_humidity')
self._prop_fan_level = miot_service.get_property('fan_level', 'heat_level')
Expand All @@ -110,7 +111,7 @@ def __init__(self, config: dict, miot_service: MiotService):
self._prop_vertical_swing = None
if self._fan_control:
self._prop_fan_power = self._fan_control.get_property('on')
self._prop_fan_level = self._fan_control.get_property('fan_level', 'heat_level')
self._prop_fan_level = self._fan_control.get_property('fan_level', 'heat_level') or self._prop_fan_level
self._prop_horizontal_swing = self._fan_control.get_property('horizontal_swing')
self._prop_horizontal_angle = self._fan_control.get_property('horizontal_angle')
self._prop_vertical_swing = self._fan_control.get_property('vertical_swing')
Expand Down Expand Up @@ -138,6 +139,8 @@ def __init__(self, config: dict, miot_service: MiotService):
self._supported_features |= SUPPORT_FAN_MODE
if self._prop_horizontal_swing or self._prop_vertical_swing:
self._supported_features |= SUPPORT_SWING_MODE
if self._prop_heater and miot_service.name in ['air_conditioner', 'air_condition_outlet']:
self._supported_features |= SUPPORT_AUX_HEAT

self._state_attrs.update({'entity_class': self.__class__.__name__})
self._power_modes = ['blow', 'heating', 'ventilation']
Expand Down Expand Up @@ -588,6 +591,29 @@ def set_swing_mode(self, swing_mode: str):
ret = self.set_property(mk, mv)
return ret

@property
def is_aux_heat(self):
"""Return true if aux heater."""
if self._prop_heater:
return self._prop_heater.from_dict(self._state_attrs) and self.hvac_mode in [
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
]
raise NotImplementedError

def turn_aux_heat_on(self):
"""Turn auxiliary heater on."""
if self._prop_heater:
return self.set_property(self._prop_heater.full_name, True)
return False

def turn_aux_heat_off(self):
"""Turn auxiliary heater off."""
if self._prop_heater:
return self.set_property(self._prop_heater.full_name, False)
return False


class ClimateModeSubEntity(MiotModesSubEntity):
def __init__(self, parent: MiotClimateEntity, miot_property: MiotProperty, option=None):
Expand Down
9 changes: 7 additions & 2 deletions custom_components/xiaomi_miot/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ def __init__(self, parent, miot_property: MiotProperty, option=None):

@property
def is_on(self):
if self._prop_power and self._miot_service.name in ['air_conditioner']:
self._state = self._state and self._prop_power.from_dict(self._state_attrs)
if self._miot_service.name in ['air_conditioner']:
if self._prop_power:
self._state = self._state and self._prop_power.from_dict(self._state_attrs)
if self._miot_property.name in ['heater']:
self.update_attrs({
'warning': 'heater of air_conditioner is deprecated, please use aux_heat in climate entity.',
}, update_parent=False)
return self._state

def set_parent_property(self, val):
Expand Down

0 comments on commit cff53c7

Please sign in to comment.