Skip to content

Commit e50ed78

Browse files
committed
fix: Enforce bounds on color temp in line with profile
1 parent e3f5d08 commit e50ed78

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

drivers/SmartThings/philips-hue/src/handlers.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ local function do_color_temp_action(driver, device, args)
148148
return
149149
end
150150

151-
local clamped_kelvin = st_utils.clamp_value(
152-
kelvin, HueApi.MIN_TEMP_KELVIN, HueApi.MAX_TEMP_KELVIN
153-
)
151+
local min = device:get_field(Fields.MIN_KELVIN) or HueApi.MIN_TEMP_KELVIN_WHITE_AMBIANCE
152+
local clamped_kelvin = st_utils.clamp_value(kelvin, min, HueApi.MAX_TEMP_KELVIN)
154153
local mirek = math.floor(handlers.kelvin_to_mirek(clamped_kelvin))
155154

156155
local resp, err = hue_api:set_light_color_temp(light_id, mirek)

drivers/SmartThings/philips-hue/src/hue/api.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ PhilipsHueApi.__gc = function(self)
4141
end
4242

4343
PhilipsHueApi.MIN_CLIP_V2_SWVERSION = 1948086000
44-
PhilipsHueApi.MIN_TEMP_KELVIN = 2000
44+
PhilipsHueApi.MIN_TEMP_KELVIN_COLOR_AMBIANCE = 2000
45+
PhilipsHueApi.MIN_TEMP_KELVIN_WHITE_AMBIANCE = 2200
4546
PhilipsHueApi.MAX_TEMP_KELVIN = 6500
4647
PhilipsHueApi.APPLICATION_KEY_HEADER = APPLICATION_KEY_HEADER
4748

drivers/SmartThings/philips-hue/src/hue/fields.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ local Fields = {
2323
HUE_DEVICE_ID = "hue_device_id",
2424
IPV4 = "ipv4",
2525
MIN_DIMMING = "mindim",
26+
MIN_KELVIN = "mintemp",
2627
MODEL_ID = "modelid",
2728
PARENT_DEVICE_ID = "parent_device_id_local",
2829
RESOURCE_ID = "rid"

drivers/SmartThings/philips-hue/src/init.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ local function emit_light_status_events(light_device, light)
7878
if light.color_temperature.mirek_valid then
7979
mirek = light.color_temperature.mirek
8080
end
81-
light_device:emit_event(
82-
capabilities.colorTemperature.colorTemperature(math.floor(handlers.mirek_to_kelvin(mirek)))
81+
local min = light_device:get_field(Fields.MIN_KELVIN) or HueApi.MIN_TEMP_KELVIN_WHITE_AMBIANCE
82+
local kelvin = math.floor(
83+
st_utils.clamp_value(handlers.mirek_to_kelvin(mirek), min, HueApi.MAX_TEMP_KELVIN)
8384
)
85+
light_device:emit_event(capabilities.colorTemperature.colorTemperature(kelvin))
8486
end
8587

8688
if light.color then
@@ -501,6 +503,14 @@ end
501503
---@param driver HueDriver
502504
---@param device HueDevice
503505
local function init_light(driver, device)
506+
local caps = device.profile.components.main.capabilities
507+
if caps.colorTemperature then
508+
if caps.colorControl then
509+
device:set_field(Fields.MIN_KELVIN, HueApi.MIN_TEMP_KELVIN_COLOR_AMBIANCE, { persist = true })
510+
else
511+
device:set_field(Fields.MIN_KELVIN, HueApi.MIN_TEMP_KELVIN_WHITE_AMBIANCE, { persist = true})
512+
end
513+
end
504514
local device_light_resource_id = device:get_field(Fields.RESOURCE_ID) or device.device_network_id
505515
local hue_device_id = device:get_field(Fields.HUE_DEVICE_ID)
506516
if not driver.light_id_to_device[device_light_resource_id] then

0 commit comments

Comments
 (0)