Skip to content

Fix brightness dropped when color_temp is set alongside it in turn_on() - #167

Open
imwithsam wants to merge 1 commit into
nikshriv:mainfrom
imwithsam:fix/combo-control-brightness-and-color-temp
Open

Fix brightness dropped when color_temp is set alongside it in turn_on()#167
imwithsam wants to merge 1 commit into
nikshriv:mainfrom
imwithsam:fix/combo-control-brightness-and-color-temp

Conversation

@imwithsam

Copy link
Copy Markdown

Summary

Follow-up to #122 ("Adaptive Lighting not working") - this fixes the actual root cause rather than working around it.

turn_on()'s elif chain (in both CyncRoom and CyncSwitch) only calls combo_control() for RGB-mode changes (color_tone=254) or brightness-only changes with a "no color" marker (color_tone=255). The color_tone byte is never actually populated with a real color-temperature value anywhere in the codebase, even though combo_control()'s own packet format already supports it - color_tone is sent through as a raw byte, and (confirmed via live testing) the device firmware accepts a real 0-100 color-temp percentage there just as happily as the 254/255 mode markers.

Whenever attr_ct was set, execution fell through to the color-temp-only branch, which sends two legacy single-attribute commands (hub.turn_on + hub.set_color_temp) and never looks at attr_br at all. So any call setting brightness and color_temp together - e.g. Adaptive Lighting's apply, or any client sending both attributes in one light.turn_on - silently lost the brightness change.

Fix

Add a combo_control() branch for the brightness+color_temp case, using the real color-temp percentage (the same 0-100 conversion already used by the existing color-temp-only branch) instead of a mode marker.

Testing

Verified live against a real Home Assistant instance, with Adaptive Lighting temporarily disabled to isolate the call:

  • light.turn_on(brightness=180, color_temp_kelvin=3200) -> landed as brightness 181 (expected rounding from the 0-100% round-trip), color_temp exactly 3200K
  • light.turn_on(brightness=90, color_temp_kelvin=5500) -> landed as brightness 89 (same expected rounding), color_temp exactly 5500K

Both in a single atomic call, no errors in debug logs. This was previously investigated in #122 with a documented separate_turn_on_commands Adaptive Lighting workaround (splitting the call into two); this fix addresses the actual root cause, so that workaround is no longer necessary going forward (though harmless to leave enabled for anyone who already has it set).

turn_on()'s elif chain (in both CyncRoom and CyncSwitch) only calls
combo_control() for RGB-mode changes (color_tone=254) or brightness-only
changes with a "no color" marker (color_tone=255) - the color_tone byte
is never actually populated with a real color-temperature value anywhere
in the codebase, even though combo_control()'s own packet format already
supports it (color_tone is sent as a raw byte, and the device firmware
happily accepts 0-100 there instead of just the 254/255 mode markers).

Whenever attr_ct was set, the code fell through to the ct-only branch,
which sends two legacy single-attribute commands (hub.turn_on +
hub.set_color_temp) and never looks at attr_br at all - so any call that
set brightness and color_temp together (e.g. Adaptive Lighting's `apply`,
or any client sending both attributes in one light.turn_on) silently lost
the brightness change.

Fix: add a combo_control() branch for the brightness+color_temp case,
using the real color-temp percentage (the same 0-100 conversion already
used by the existing color-temp-only branch) instead of a mode marker.

## Testing

Verified live against a real Home Assistant instance with Adaptive
Lighting temporarily disabled to isolate the call: sent
light.turn_on(brightness=180, color_temp_kelvin=3200) and
light.turn_on(brightness=90, color_temp_kelvin=5500) as single calls -
both landed exactly (brightness within normal 0-100% round-trip rounding,
color_temp exact) in one atomic packet, no errors in debug logs. This was
previously reported (see nikshriv#122) with a documented `separate_turn_on_commands`
workaround in Adaptive Lighting; this fix addresses the actual root cause
so the workaround is no longer necessary (though harmless to leave enabled).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant