From fa27343fadd088817e97a81d138955574e09508f Mon Sep 17 00:00:00 2001 From: litinoveweedle <15144712+litinoveweedle@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:30:31 +0200 Subject: [PATCH] change default state to OFF fixed light power sensor --- custom_components/smartir/climate.py | 2 +- custom_components/smartir/fan.py | 2 +- custom_components/smartir/light.py | 20 ++++++++++---------- custom_components/smartir/media_player.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/custom_components/smartir/climate.py b/custom_components/smartir/climate.py index d1ae78c9..e56c0075 100644 --- a/custom_components/smartir/climate.py +++ b/custom_components/smartir/climate.py @@ -114,7 +114,7 @@ def __init__(self, hass, config, device_data): self._power_sensor_restore_state = config.get(CONF_POWER_SENSOR_RESTORE_STATE) self._temperature_unit = hass.config.units.temperature_unit - self._state = STATE_UNKNOWN + self._state = STATE_OFF self._hvac_mode = None self._preset_mode = None self._fan_mode = None diff --git a/custom_components/smartir/fan.py b/custom_components/smartir/fan.py index e8ffb0cc..693c3a8b 100644 --- a/custom_components/smartir/fan.py +++ b/custom_components/smartir/fan.py @@ -90,7 +90,7 @@ def __init__(self, hass, config, device_data): self._power_sensor_delay = config.get(CONF_POWER_SENSOR_DELAY) self._power_sensor_restore_state = config.get(CONF_POWER_SENSOR_RESTORE_STATE) - self._state = STATE_UNKNOWN + self._state = STATE_OFF self._speed = None self._oscillating = None self._on_by_remote = False diff --git a/custom_components/smartir/light.py b/custom_components/smartir/light.py index 9fe08150..8f783bfa 100644 --- a/custom_components/smartir/light.py +++ b/custom_components/smartir/light.py @@ -90,7 +90,7 @@ def __init__(self, hass, config, device_data): self._power_sensor_delay = config.get(CONF_POWER_SENSOR_DELAY) self._power_sensor_restore_state = config.get(CONF_POWER_SENSOR_RESTORE_STATE) - self._power = STATE_ON + self._state = STATE_OFF self._brightness = None self._colortemp = None self._on_by_remote = False @@ -144,7 +144,7 @@ async def async_added_to_hass(self): last_state = await self.async_get_last_state() if last_state is not None: - self._power = last_state.state + self._state = last_state.state if ATTR_BRIGHTNESS in last_state.attributes: self._brightness = last_state.attributes[ATTR_BRIGHTNESS] if ATTR_COLOR_TEMP_KELVIN in last_state.attributes: @@ -186,7 +186,7 @@ def max_color_temp_kelvin(self): @property def is_on(self): - return self._power == STATE_ON or self._on_by_remote + return self._state == STATE_ON or self._on_by_remote @property def brightness(self): @@ -207,8 +207,8 @@ def extra_state_attributes(self): async def async_turn_on(self, **params): did_something = False # Turn the light on if off - if self._power != STATE_ON and not self._on_by_remote: - self._power = STATE_ON + if self._state != STATE_ON and not self._on_by_remote: + self._state = STATE_ON did_something = True await self.send_command(CMD_POWER_ON) @@ -245,7 +245,7 @@ async def async_turn_on(self, **params): # when a nightlight is fitted for brightness of 1 if params.get(ATTR_BRIGHTNESS) == 1 and CMD_NIGHTLIGHT in self._commands: self._brightness = 1 - self._power = STATE_ON + self._state = STATE_ON did_something = True await self.send_command(CMD_NIGHTLIGHT) @@ -286,13 +286,13 @@ async def async_turn_on(self, **params): # If we do have such monitoring, avoid issuing the command in case # on and off are the same remote code. if not did_something and not self._on_by_remote: - self._power = STATE_ON + self._state = STATE_ON await self.send_command(CMD_POWER_ON) self.async_write_ha_state() async def async_turn_off(self): - self._power = STATE_OFF + self._state = STATE_OFF await self.send_command(CMD_POWER_OFF) self.async_write_ha_state() @@ -325,12 +325,12 @@ async def _async_power_sensor_changed( if old_state is not None and new_state.state == old_state.state: return - if new_state.state == STATE_ON and self._state == STATE_OFF: + if new_state.state == STATE_ON and self._state != STATE_ON: self._state = STATE_ON self._on_by_remote = True elif new_state.state == STATE_OFF: self._on_by_remote = False - if self._state == STATE_ON: + if self._state != STATE_OFF: self._state = STATE_OFF self.async_write_ha_state() diff --git a/custom_components/smartir/media_player.py b/custom_components/smartir/media_player.py index bce3e116..332b8f5c 100644 --- a/custom_components/smartir/media_player.py +++ b/custom_components/smartir/media_player.py @@ -87,7 +87,7 @@ def __init__(self, hass, config, device_data): self._power_sensor_restore_state = config.get(CONF_POWER_SENSOR_RESTORE_STATE) self._device_class = config.get(CONF_DEVICE_CLASS) - self._state = STATE_UNKNOWN + self._state = STATE_OFF self._sources_list = [] self._source = None self._on_by_remote = False