adaptive-lighting/custom_components/adaptive_lighting
Bas Nijholt 68e243c87e
Fix infinite loop when disabling SimpleSwitch entities (#1296)
* Add regression tests for SimpleSwitch initial state bug

Adds tests that verify SimpleSwitch._state is set immediately in __init__
rather than waiting for async_added_to_hass(). These tests currently FAIL
because _state is None after __init__, which causes an infinite loop in
_setup_listeners when the entity is disabled (since async_added_to_hass
is never called for disabled entities).

Regression tests for: https://github.com/basnijholt/adaptive-lighting/issues/1264

* Fix infinite loop when disabling SimpleSwitch entities

The issue was that SimpleSwitch._state was initialized to None in __init__,
but only set to a boolean value in async_added_to_hass(). When an entity
is disabled, async_added_to_hass() is never called, so _state stayed None.

The _setup_listeners() method has a while loop that waits for
_state is not None for all SimpleSwitch children (sleep_mode_switch,
adapt_brightness_switch, adapt_color_switch). With _state stuck at None,
this created an infinite loop.

The fix sets _state to initial_state directly in __init__ instead of
waiting for async_added_to_hass() to set it. The async_added_to_hass()
will still properly restore state from the last session or set based
on initial_state as before.

Fixes: https://github.com/basnijholt/adaptive-lighting/issues/1264
2025-11-27 09:30:01 -08:00
..
translations Translations update from Hosted Weblate (#1160) 2025-06-15 21:38:10 -07:00
__init__.py fix: async entry setup (#1141) 2025-01-01 14:19:31 -08:00
_docs_helpers.py Style with ruff and logging (#643) 2023-07-23 14:24:22 -07:00
adaptation_utils.py [pre-commit.ci] pre-commit autoupdate (#972) 2025-01-01 23:28:15 -08:00
color_and_brightness.py [pre-commit.ci] pre-commit autoupdate (#1163) 2025-06-15 21:55:36 -07:00
config_flow.py Fix setting config_entry directly in ≥2024.12 (#1155) 2025-01-01 16:46:11 -08:00
const.py Fix trailing spaces in const.py: restore correct one, remove incorrect one (#1148) 2025-01-01 14:18:54 -08:00
hass_utils.py Fix HA 2025.12 breaking (#1291) 2025-11-27 08:05:30 -08:00
helpers.py [pre-commit.ci] pre-commit autoupdate (#882) 2024-02-05 14:13:13 -08:00
manifest.json Bump to 1.27.0 for fixes in 2025.12 (#1293) 2025-11-27 09:06:41 -08:00
services.yaml Use markdown-code-runner==2.1.0 (#1152) 2025-01-01 16:19:08 -08:00
strings.json Use markdown-code-runner==2.1.0 (#1152) 2025-01-01 16:19:08 -08:00
switch.py Fix infinite loop when disabling SimpleSwitch entities (#1296) 2025-11-27 09:30:01 -08:00