Skip to content

Commit

Permalink
Avoid resync when value is not changing
Browse files Browse the repository at this point in the history
When using this with Adaptive lighting, during the day the light keeps beeping due to reaching the end of its range every 90s.
This is because Adaptive lighting is trying to adjust the brightness and color temperature, but they are not actually moving because of the limited number of steps.
Putting the resync code inside the condition that we actually need to move the brightness should prevent this, and only resync when we are actually changing to the end of the range.
  • Loading branch information
make-all committed Jan 23, 2023
1 parent 19bb035 commit bf36ae0
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions custom_components/smartir/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,16 @@ async def async_turn_on(self, **params):
did_something = True
if steps < 0:
cmd = CMD_COLORMODE_WARMER
# if we are heading for the lowest value, take the opportunity
# to resync by issuing enough commands to go the full range.
if new_color_temp == 0:
steps = len(self._colortemps)
else:
steps = abs(steps)
steps = abs(steps)
else:
cmd = CMD_COLORMODE_COLDER
# If we are heading for the highest value, take the opportunity
# to resync by issuing enough commands to go the full range.
if new_color_temp == len(self._colortemps) - 1:
steps = len(self._colortemps)

if steps > 0 and cmd:
# If we are heading for the highest or lowest value,
# take the opportunity to resync by issuing enough
# commands to go the full range.
if new_color_temp == len(self._colortemps) - 1 or new_color_temp == 0:
steps = len(self._colortemps)
self._colortemp = self._colortemps[new_color_temp]
await self.send_command(cmd, steps)

Expand All @@ -314,16 +310,19 @@ async def async_turn_on(self, **params):
steps = new_brightness - old_brightness
if steps < 0:
cmd = CMD_BRIGHTNESS_DECREASE
if new_brightness == 0:
steps = len(self._colortemps)
else:
steps = abs(steps)
steps = abs(steps)
else:
cmd = CMD_BRIGHTNESS_INCREASE
if new_brightness == len(self._brightnesses) - 1:
steps = len(self._colortemps)

if steps > 0 and cmd:
# If we are heading for the highest or lowest value,
# take the opportunity to resync by issuing enough
# commands to go the full range.
if (
new_brightness == len(self._brightnesses) - 1
or new_brightness == 0
):
steps = len(self._colortemps)
did_something = True
self._brightness = self._brightnesses[new_brightness]
await self.send_command(cmd, steps)
Expand Down

0 comments on commit bf36ae0

Please sign in to comment.