basnijholt / adaptive-lighting

Adaptive Lighting custom component for Home Assistant
https://basnijholt.github.io/adaptive-lighting/
Apache License 2.0
1.71k stars 127 forks source link

Test that switch is on before updating time listeners #936

Closed droans closed 4 months ago

droans commented 4 months ago

Calling adaptive_lighting.change_switch_settings while the lights are off will cause the below errors to appear in your HA logs:

2024-02-21 11:04:29.042 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/adaptive_lighting/switch.py", line 1132, in _async_update_at_interval_action
    await self._update_attrs_and_maybe_adapt_lights(
  File "/config/custom_components/adaptive_lighting/switch.py", line 1361, in _update_attrs_and_maybe_adapt_lights
    assert self.is_on
AssertionError

These errors appear about every 90 seconds, I assume more or less depending on the set transition time.

It appears this is because the function handle_change_switch_settings will always make a call to _update_time_interval_listener, even when the switch is off.

This PR just adds a single line to check if the switch is on before calling the above function.

basnijholt commented 4 months ago

@all-contributors please add @droans for code

allcontributors[bot] commented 4 months ago

@basnijholt

I've put up a pull request to add @droans! :tada:

basnijholt commented 4 months ago

Thanks a lot for fixing this!