Skip to content

Commit

Permalink
change default state to OFF
Browse files Browse the repository at this point in the history
fixed light power sensor
  • Loading branch information
litinoveweedle committed Sep 27, 2024
1 parent aff94b8 commit fa27343
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions custom_components/smartir/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion custom_components/smartir/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fa27343

Please sign in to comment.