adaptive-lighting/custom_components/adaptive_lighting
Roee Hendel 6cebe14a69
fix: merge last_service_data across split calls to fix detect_non_ha_changes with separate_turn_on_commands (#1426)
* test: regression test — AL must not override manual brightness with separate_turn_on_commands

End-to-end scenario: user adjusts brightness via a directly-bound Zigbee
switch (e.g. IKEA RODRET).  No HA service call is made; ZHA reports the new
brightness via async_update_entity.  On the next adaptation interval AL must
detect the change and stop overriding the user's brightness.

The test verifies the user-visible symptom: after two adaptation cycles
following a simulated direct-Zigbee brightness change, the light's brightness
must still be the manually set value — not AL's own target.

NOTE: this test FAILS on the current code.  It is committed here to document
the bug before the fix is applied in the next commit.

* fix: merge last_service_data across split calls to fix detect_non_ha_changes with separate_turn_on_commands

When separate_turn_on_commands=True, each adaptation cycle makes two
light.turn_on calls (brightness, then color_temp).  Previously each call
overwrote last_service_data[light], so after the cycle only the color_temp
key remained.  _attributes_have_changed() then saw old_brightness=None and
silently skipped the brightness comparison, so a manually-set brightness was
never detected and AL kept overriding it.

Fix: merge instead of overwrite so all split-call attributes accumulate:

    self.manager.last_service_data[light] = {
        **self.manager.last_service_data.get(light, {}),
        **service_data,
    }

* test: add intermediate assertions to regression test

Two assertions were promised in the PR description but missing:
1. After the force-adapt, assert that last_service_data contains BOTH
   brightness AND color — directly proving the merge fix works.
2. After the first non-forced update, assert that BRIGHTNESS is in
   manual_control — proving detection fired, not just that the final
   state is right.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor: remove spurious comments, trim test docstring and assertions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor: strip verbose comments from test, trim assert messages

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* test: add message to bare assert
2026-03-16 15:54:53 -07:00
..
translations Fix regression: lights not adapting when turned on by automation (#1380) 2026-01-12 13:40:55 +01:00
__init__.py Code cleanup (#1348) 2025-12-12 13:37:42 -08:00
_docs_helpers.py Individual manual control of brightness and color (#1356) 2025-12-22 22:55:16 -08:00
adaptation_utils.py Individual manual control of brightness and color (#1356) 2025-12-22 22:55:16 -08:00
color_and_brightness.py Code cleanup (#1348) 2025-12-12 13:37:42 -08:00
config_flow.py Code cleanup (#1348) 2025-12-12 13:37:42 -08:00
const.py Fix regression: lights not adapting when turned on by automation (#1380) 2026-01-12 13:40:55 +01:00
docs_gen.py Migrate to markdown-code-runner's built-in include_section() (#1417) 2026-01-26 09:01:50 +01:00
hass_utils.py Friendly names (#1258) 2025-11-27 12:01:05 -08:00
helpers.py Friendly names (#1258) 2025-11-27 12:01:05 -08:00
manifest.json Bump to v1.30.1 (#1384) 2026-01-12 13:46:19 +01:00
services.yaml Individual manual control of brightness and color (#1356) 2025-12-22 22:55:16 -08:00
strings.json Fix regression: lights not adapting when turned on by automation (#1380) 2026-01-12 13:40:55 +01:00
switch.py fix: merge last_service_data across split calls to fix detect_non_ha_changes with separate_turn_on_commands (#1426) 2026-03-16 15:54:53 -07:00