-
Notifications
You must be signed in to change notification settings - Fork 524
Hue: fix issue with small color temp increments #2771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at least I am a consistent bad speller 🥲 |
||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| local function do_color_action(driver, bridge_device, group, args, aux) | ||
| local hue, sat = (args.args.color.hue / 100), (args.args.color.saturation / 100) | ||
| if hue == 1 then -- 0 and 360 degrees are equivalent in HSV, but not in our conversion function | ||
|
|
@@ -135,7 +135,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| local function do_setHue_action(driver, bridge_device, group, args, aux) | ||
| local currentSaturation = aux[Fields.COLOR_SATURATION] or 0 | ||
| args.args.color = { | ||
|
|
@@ -149,7 +149,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| local function do_setSaturation_action(driver, bridge_device, group, args, aux) | ||
| local currentHue = aux[Fields.COLOR_HUE] or 0 | ||
| args.args.color = { | ||
|
|
@@ -163,8 +163,9 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| local function do_color_temp_action(driver, bridge_device, group, args, aux) | ||
| local capabilities = require "st.capabilities" | ||
| local kelvin = args.args.temperature | ||
|
|
||
| local grouped_light_id = group.grouped_light_rid | ||
|
|
@@ -185,6 +186,29 @@ local function do_color_temp_action(driver, bridge_device, group, args, aux) | |
| local clamped_kelvin = st_utils.clamp_value(kelvin, min, Consts.MAX_TEMP_KELVIN) | ||
| local mirek = math.floor(utils.kelvin_to_mirek(clamped_kelvin)) | ||
|
|
||
| local all_same_mirek = true | ||
| for _, device in ipairs(group.devices) do | ||
| local current_color_temp = device:get_latest_state("main", capabilities.colorTemperature.ID, capabilities.colorTemperature.colorTemperature.NAME) | ||
| if current_color_temp then | ||
| local current_mirek = math.floor(utils.kelvin_to_mirek(current_color_temp)) | ||
| if current_mirek ~= mirek then | ||
| all_same_mirek = false | ||
| break | ||
| end | ||
| else | ||
| all_same_mirek = false | ||
| break | ||
| end | ||
| end | ||
|
|
||
| if all_same_mirek and #group.devices > 0 then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather then checking if they are all the same mirek, I wonder if we want to track all the devices that have the same mirek and then emit the event for all of those devices. I'm not sure how this interaction works with the grouped lighting but it seems like if only one device had the same mirek then the bridge might not send anything for that specific device.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah good call. When I was testing it I had all my bulbs at the same color temp value and neglected to think of the case where they are at different values initially. |
||
| log.debug(string.format("Color temp change to %dK results in same mirek value (%d) for all devices in group, emitting events directly", clamped_kelvin, mirek)) | ||
| for _, device in ipairs(group.devices) do | ||
| device:emit_event(capabilities.colorTemperature.colorTemperature(clamped_kelvin)) | ||
| end | ||
| return | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar reasoning as above for not returning early here. |
||
| end | ||
|
|
||
| local resp, err = hue_api:set_grouped_light_color_temp(grouped_light_id, mirek) | ||
|
|
||
| if not resp or (resp.errors and #resp.errors == 0) then | ||
|
|
@@ -203,7 +227,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| function GroupedLightCommandHandlers.switch_on_handler(driver, bridge_device, group, args, aux) | ||
| do_switch_action(driver, bridge_device, group, args) | ||
| end | ||
|
|
@@ -212,7 +236,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| function GroupedLightCommandHandlers.switch_off_handler(driver, bridge_device, group, args, aux) | ||
| do_switch_action(driver, bridge_device, group, args) | ||
| end | ||
|
|
@@ -221,7 +245,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| function GroupedLightCommandHandlers.switch_level_handler(driver, bridge_device, group, args, aux) | ||
| do_switch_level_action(driver, bridge_device, group, args) | ||
| end | ||
|
|
@@ -230,7 +254,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| function GroupedLightCommandHandlers.set_color_handler(driver, bridge_device, group, args, aux) | ||
| do_color_action(driver, bridge_device, group, args, aux) | ||
| end | ||
|
|
@@ -239,7 +263,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| function GroupedLightCommandHandlers.set_hue_handler(driver, bridge_device, group, args, aux) | ||
| do_setHue_action(driver, bridge_device, group, args, aux) | ||
| end | ||
|
|
@@ -248,7 +272,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| function GroupedLightCommandHandlers.set_saturation_handler(driver, bridge_device, group, args, aux) | ||
| do_setSaturation_action(driver, bridge_device, group, args, aux) | ||
| end | ||
|
|
@@ -257,7 +281,7 @@ end | |
| ---@param bridge_device HueBridgeDevice | ||
| ---@param group table | ||
| ---@param args table | ||
| ---@param aux table auxilary data needed for the command that the devices all had in common | ||
| ---@param aux table auxiliary data needed for the command that the devices all had in common | ||
| function GroupedLightCommandHandlers.set_color_temp_handler(driver, bridge_device, group, args, aux) | ||
| do_color_temp_action(driver, bridge_device, group, args, aux) | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should still send the command to the bridge and not return early here. It might be possible that the user changed the temp in the hue app and we never emitted an event for the change so we might actually be changing it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point!