Skip to content

Commit

Permalink
🔧 improve for miir.aircondition
Browse files Browse the repository at this point in the history
  • Loading branch information
al-one committed Apr 29, 2022
1 parent df93485 commit 95a3ba6
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions custom_components/xiaomi_miot/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,12 @@ def __init__(self, config: dict, miot_service: MiotService):

self._attr_hvac_mode = None
self._hvac_modes = {
HVAC_MODE_OFF: {'list': ['Off', 'Idle', 'None']},
HVAC_MODE_OFF: {'list': ['Off', 'Idle', 'None'], 'action': CURRENT_HVAC_OFF},
HVAC_MODE_AUTO: {'list': ['Auto', 'Manual', 'Normal']},
HVAC_MODE_COOL: {'list': ['Cool']},
HVAC_MODE_HEAT: {'list': ['Heat']},
HVAC_MODE_DRY: {'list': ['Dry']},
HVAC_MODE_FAN_ONLY: {'list': ['Fan']},
HVAC_MODE_COOL: {'list': ['Cool'], 'action': CURRENT_HVAC_COOL},
HVAC_MODE_HEAT: {'list': ['Heat'], 'action': CURRENT_HVAC_HEAT},
HVAC_MODE_DRY: {'list': ['Dry'], 'action': CURRENT_HVAC_DRY},
HVAC_MODE_FAN_ONLY: {'list': ['Fan'], 'action': CURRENT_HVAC_FAN},
}
self._attr_hvac_modes = []
self._prop_mode = miot_service.get_property('ir_mode')
Expand All @@ -728,18 +728,24 @@ def __init__(self, config: dict, miot_service: MiotService):
self._attr_hvac_modes.append(mk)

self._attr_current_temperature = None
self._attr_temperature_unit = None
self._attr_max_temp = DEFAULT_MAX_TEMP
self._attr_min_temp = DEFAULT_MIN_TEMP
self._attr_target_temperature_step = 1
self._prop_temperature = miot_service.get_property('ir_temperature')
if self._prop_temperature:
self._supported_features |= SUPPORT_TARGET_TEMPERATURE
self._attr_temperature_unit = self._prop_temperature.unit_of_measurement
self._attr_target_temperature_step = self._prop_temperature.range_step() or 1
self._attr_max_temp = self._prop_temperature.range_max() or DEFAULT_MAX_TEMP
self._attr_min_temp = self._prop_temperature.range_min() or DEFAULT_MIN_TEMP
self._attr_target_temperature_high = self._attr_max_temp
self._attr_target_temperature_low = self._attr_min_temp
self._attr_target_temperature = int((self._attr_max_temp - self._attr_min_temp) / 1.2) + self._attr_min_temp
self._attr_target_temperature_high = self._attr_max_temp
self._attr_target_temperature_low = self._attr_min_temp
self._attr_target_temperature = int((self._attr_max_temp - self._attr_min_temp) / 1.2) + self._attr_min_temp

self._fan_modes = {}
self._attr_fan_modes = []
self._attr_fan_mode = None
self._act_fan_down = miot_service.get_action('fan_speed_down')
if self._act_fan_down:
self._fan_modes[self._act_fan_down.friendly_desc] = self._act_fan_down
Expand All @@ -748,14 +754,17 @@ def __init__(self, config: dict, miot_service: MiotService):
self._fan_modes[self._act_fan_up.friendly_desc] = self._act_fan_up
if self._fan_modes:
self._supported_features |= SUPPORT_FAN_MODE
self._attr_fan_mode = None
self._attr_fan_modes = list(self._fan_modes.keys())

async def async_update(self):
self.update_bind_sensor()
if ATTR_CURRENT_TEMPERATURE in self._state_attrs:
self._attr_current_temperature = self._state_attrs.get(ATTR_CURRENT_TEMPERATURE)

@property
def is_on(self):
return self.hvac_mode not in [None, HVAC_MODE_OFF]

def turn_on(self, **kwargs):
"""Turn the entity on."""
if not self._act_turn_on:
Expand Down Expand Up @@ -785,6 +794,18 @@ def set_hvac_mode(self, hvac_mode):
self._attr_hvac_mode = hvac_mode
return ret

@property
def hvac_action(self):
"""Return the current running hvac operation if supported.
Need to be one of CURRENT_HVAC_*.
"""
if not self.is_on:
return CURRENT_HVAC_OFF
hvac = self.hvac_mode
if hvac is None:
return CURRENT_HVAC_IDLE
return self._hvac_modes.get(hvac, {}).get('action')

def set_temperature(self, **kwargs):
"""Set new target temperature."""
if ATTR_HVAC_MODE in kwargs:
Expand Down

0 comments on commit 95a3ba6

Please sign in to comment.