From ed2a506b9010fe9999737fd4817f507521bc8cbf Mon Sep 17 00:00:00 2001 From: Samson Brock Date: Thu, 20 Aug 2026 05:30:27 +0000 Subject: [PATCH] Fix brightness being dropped when color_temp is set alongside 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 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 #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). --- custom_components/cync_lights/cync_hub.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/custom_components/cync_lights/cync_hub.py b/custom_components/cync_lights/cync_hub.py index fdc677a..9b3289e 100644 --- a/custom_components/cync_lights/cync_hub.py +++ b/custom_components/cync_lights/cync_hub.py @@ -415,6 +415,13 @@ async def turn_on(self, attr_rgb, attr_br, attr_ct) -> None: self.hub.combo_control(True, round(attr_br*100/255), 255, [255,255,255], controller, self.mesh_id, seq) elif attr_rgb is not None and attr_br is None: self.hub.combo_control(True, self.brightness, 254, attr_rgb, controller, self.mesh_id, seq) + elif attr_ct is not None and attr_br is not None: + # combo_control accepts a real 0-100 color-temp percentage in its + # color_tone byte (not just the 254=RGB/255=none mode markers used + # above), so brightness+color_temp can be sent atomically instead of + # as two separate calls (which silently dropped brightness before). + color_temp = round(100*((attr_ct - self.min_color_temp_kelvin) / (self.max_color_temp_kelvin - self.min_color_temp_kelvin))) + self.hub.combo_control(True, round(attr_br*100/255), color_temp, [0,0,0], controller, self.mesh_id, seq) elif attr_ct is not None: self.hub.turn_on(controller, self.mesh_id, seq) # Cync uses the range 0% to 100% to set the color temp, so we need to @@ -567,6 +574,9 @@ async def turn_on(self, attr_rgb, attr_br, attr_ct) -> None: self.hub.combo_control(True, round(attr_br*100/255), 255, [255,255,255], controller, self.mesh_id, seq) elif attr_rgb is not None and attr_br is None: self.hub.combo_control(True, self.brightness, 254, attr_rgb, controller, self.mesh_id, seq) + elif attr_ct is not None and attr_br is not None: + color_temp = round(100*((attr_ct - self.min_color_temp_kelvin) /(self.max_color_temp_kelvin - self.min_color_temp_kelvin))) + self.hub.combo_control(True, round(attr_br*100/255), color_temp, [0,0,0], controller, self.mesh_id, seq) elif attr_ct is not None: # Cync uses the range 0% to 100% to set the color temp, so we need to # calculate the percentage of the color temp range that is being requested