diff --git a/custom_components/smartir/climate.py b/custom_components/smartir/climate.py index 9ebcc9fb..799ec995 100644 --- a/custom_components/smartir/climate.py +++ b/custom_components/smartir/climate.py @@ -125,6 +125,7 @@ def __init__(self, hass, config, device_data): self._current_fan_mode = self._fan_modes[0] self._current_swing_mode = None self._last_on_operation = None + self._last_operation = None self._current_temperature = None self._current_humidity = None @@ -166,6 +167,9 @@ async def async_added_to_hass(self): if 'last_on_operation' in last_state.attributes: self._last_on_operation = last_state.attributes['last_on_operation'] + if 'last_operation' in last_state.attributes: + self._last_operation = last_state.attributes['last_operation'] + if self._temperature_sensor: async_track_state_change(self.hass, self._temperature_sensor, self._async_temp_sensor_changed) @@ -243,6 +247,11 @@ def last_on_operation(self): """Return the last non-idle operation ie. heat, cool.""" return self._last_on_operation + @property + def last_operation(self): + """Return the last operation ie. heat, cool.""" + return self._last_operation + @property def fan_modes(self): """Return the list of available fan modes.""" @@ -283,6 +292,7 @@ def extra_state_attributes(self): """Platform specific attributes.""" return { 'last_on_operation': self._last_on_operation, + 'last_operation': self._last_operation, 'device_code': self._device_code, 'manufacturer': self._manufacturer, 'supported_models': self._supported_models, @@ -322,8 +332,11 @@ async def async_set_hvac_mode(self, hvac_mode): if not hvac_mode == HVAC_MODE_OFF: self._last_on_operation = hvac_mode - + await self.send_command() + + self._last_operation = hvac_mode + await self.async_update_ha_state() async def async_set_fan_mode(self, fan_mode): @@ -366,7 +379,7 @@ async def send_command(self): await self._controller.send(self._commands['off']) return - if 'on' in self._commands: + if 'on' in self._commands and self._last_operation == 'off': await self._controller.send(self._commands['on']) await asyncio.sleep(self._delay)