custom_components/smartir/climate.py
async def async_added_to_hass(self):
        """Run when entity about to be added."""
        await super().async_added_to_hass()

        last_state = await self.async_get_last_state()

        if last_state:
            self._hvac_mode = last_state.state
            self._current_fan_mode = last_state.attributes['fan_mode']
            self._target_temperature = last_state.attributes['temperature']
            self._current_swing_mode = last_state.attributes.get('swing_mode')
            self._last_on_operation = last_state.attributes.get('last_on_operation')

        if self._temperature_sensor:
            async_track_state_change(self.hass, self._temperature_sensor,
                                     self._async_temp_sensor_changed)

            temp_sensor_state = self.hass.states.get(self._temperature_sensor)
            if temp_sensor_state and temp_sensor_state.state != STATE_UNKNOWN:
                self._async_update_temp(temp_sensor_state)

        if self._humidity_sensor:
            async_track_state_change(self.hass, self._humidity_sensor,
                                     self._async_humidity_sensor_changed)

            humidity_sensor_state = self.hass.states.get(self._humidity_sensor)
            if humidity_sensor_state and humidity_sensor_state.state != STATE_UNKNOWN:
                self._async_update_humidity(humidity_sensor_state)

        if self._power_sensor:
            async_track_state_change(self.hass, self._power_sensor,
                                     self._async_power_sensor_changed)
Run when entity about to be added.
Run when entity about to be added.
Run when entity about to be added .
async def async_added_to_hass(self):
        await super().async_added_to_hass()
        last_state = await self.async_get_last_state()
        if last_state:
            self._hvac_mode = last_state.state
            self._current_fan_mode = last_state.attributes['fan_mode']
            self._target_temperature = last_state.attributes['temperature']
            self._current_swing_mode = last_state.attributes.get('swing_mode')
            self._last_on_operation = last_state.attributes.get('last_on_operation')
        if self._temperature_sensor:
            async_track_state_change(self.hass, self._temperature_sensor,
                                     self._async_temp_sensor_changed)
            temp_sensor_state = self.hass.states.get(self._temperature_sensor)
            if temp_sensor_state and temp_sensor_state.state != STATE_UNKNOWN:
                self._async_update_temp(temp_sensor_state)
        if self._humidity_sensor:
            async_track_state_change(self.hass, self._humidity_sensor,
                                     self._async_humidity_sensor_changed)
            humidity_sensor_state = self.hass.states.get(self._humidity_sensor)
            if humidity_sensor_state and humidity_sensor_state.state != STATE_UNKNOWN:
                self._async_update_humidity(humidity_sensor_state)
        if self._power_sensor:
            async_track_state_change(self.hass, self._power_sensor,
                                     self._async_power_sensor_changed)
async def async_added_to_hass ( self ) : await super ( ) . async_added_to_hass ( ) last_state = await self . async_get_last_state ( ) if last_state : self . _hvac_mode = last_state . state self . _current_fan_mode = last_state . attributes [ 'fan_mode' ] self . _target_temperature = last_state . attributes [ 'temperature' ] self . _current_swing_mode = last_state . attributes . get ( 'swing_mode' ) self . _last_on_operation = last_state . attributes . get ( 'last_on_operation' ) if self . _temperature_sensor : async_track_state_change ( self . hass , self . _temperature_sensor , self . _async_temp_sensor_changed ) temp_sensor_state = self . hass . states . get ( self . _temperature_sensor ) if temp_sensor_state and temp_sensor_state . state != STATE_UNKNOWN : self . _async_update_temp ( temp_sensor_state ) if self . _humidity_sensor : async_track_state_change ( self . hass , self . _humidity_sensor , self . _async_humidity_sensor_changed ) humidity_sensor_state = self . hass . states . get ( self . _humidity_sensor ) if humidity_sensor_state and humidity_sensor_state . state != STATE_UNKNOWN : self . _async_update_humidity ( humidity_sensor_state ) if self . _power_sensor : async_track_state_change ( self . hass , self . _power_sensor , self . _async_power_sensor_changed )
Run when entity about to be added.
Run when entity about to be added .
"""Run when entity about to be added."""
self