Skip to content

Commit 8855768

Browse files
committed
CHAD-12653 Zigbee: Add support for reading ColorTemperatureRange
update fingerprints pointing to specific ranges
1 parent 5f76622 commit 8855768

27 files changed

Lines changed: 154 additions & 20 deletions

File tree

drivers/SmartThings/zigbee-switch/src/aqara/multi-switch/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ end
8686
local aqara_multi_switch_handler = {
8787
NAME = "Aqara Multi Switch Handler",
8888
lifecycle_handlers = {
89-
init = configurations.power_reconfig_wrapper(device_init),
89+
init = configurations.reconfig_wrapper(device_init),
9090
added = device_added
9191
},
9292
can_handle = require("aqara.multi-switch.can_handle"),
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Copyright 2026 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local capabilities = require "st.capabilities"
5+
6+
return function(opts, driver, device)
7+
if device:supports_capability(capabilities.colorTemperature) then
8+
local subdriver = require("color_temp_range_handlers")
9+
return true, subdriver
10+
end
11+
return false
12+
end
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
-- Copyright 2026 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local capabilities = require "st.capabilities"
5+
local clusters = require "st.zigbee.zcl.clusters"
6+
local utils = require "st.utils"
7+
local KELVIN_MAX = "_max_kelvin"
8+
local KELVIN_MIN = "_min_kelvin"
9+
local MIREDS_CONVERSION_CONSTANT = 1000000
10+
local COLOR_TEMPERATURE_KELVIN_MAX = 15000
11+
local COLOR_TEMPERATURE_KELVIN_MIN = 1000
12+
local COLOR_TEMPERATURE_MIRED_MAX = utils.round(MIREDS_CONVERSION_CONSTANT/COLOR_TEMPERATURE_KELVIN_MIN) -- 1000
13+
local COLOR_TEMPERATURE_MIRED_MIN = utils.round(MIREDS_CONVERSION_CONSTANT/COLOR_TEMPERATURE_KELVIN_MAX) -- 67
14+
15+
local function color_temp_min_mireds_handler(driver, device, value, zb_rx)
16+
local temp_in_mired = value.value
17+
local endpoint = zb_rx.address_header.src_endpoint.value
18+
if temp_in_mired == nil then
19+
return
20+
end
21+
if (temp_in_mired < COLOR_TEMPERATURE_MIRED_MIN or temp_in_mired > COLOR_TEMPERATURE_MIRED_MAX) then
22+
device.log.warn_with({hub_logs = true}, string.format("Device reported a color temperature %d mired outside of sane range of %.2f-%.2f", temp_in_mired, COLOR_TEMPERATURE_MIRED_MIN, COLOR_TEMPERATURE_MIRED_MAX))
23+
return
24+
end
25+
local temp_in_kelvin = utils.round(MIREDS_CONVERSION_CONSTANT / temp_in_mired)
26+
device:set_field(KELVIN_MAX..endpoint, temp_in_kelvin)
27+
local min = device:get_field(KELVIN_MIN..endpoint)
28+
if min ~= nil then
29+
if temp_in_kelvin > min then
30+
device:emit_event_for_endpoint(endpoint, capabilities.colorTemperature.colorTemperatureRange({ value = {minimum = min, maximum = temp_in_kelvin}}))
31+
else
32+
device.log.warn_with({hub_logs = true}, string.format("Device reported a max color temperature %d K that is not higher than the reported min color temperature %d K", min, temp_in_kelvin))
33+
end
34+
end
35+
end
36+
37+
local function color_temp_max_mireds_handler(driver, device, value, zb_rx)
38+
local temp_in_mired = value.value
39+
local endpoint = zb_rx.address_header.src_endpoint.value
40+
if temp_in_mired == nil then
41+
return
42+
end
43+
if (temp_in_mired < COLOR_TEMPERATURE_MIRED_MIN or temp_in_mired > COLOR_TEMPERATURE_MIRED_MAX) then
44+
device.log.warn_with({hub_logs = true}, string.format("Device reported a color temperature %d mired outside of sane range of %.2f-%.2f", temp_in_mired, COLOR_TEMPERATURE_MIRED_MIN, COLOR_TEMPERATURE_MIRED_MAX))
45+
return
46+
end
47+
local temp_in_kelvin = utils.round(MIREDS_CONVERSION_CONSTANT / temp_in_mired)
48+
device:set_field(KELVIN_MIN..endpoint, temp_in_kelvin)
49+
local max = device:get_field(KELVIN_MAX..endpoint)
50+
if max ~= nil then
51+
if temp_in_kelvin < max then
52+
device:emit_event_for_endpoint(endpoint, capabilities.colorTemperature.colorTemperatureRange({ value = {minimum = temp_in_kelvin, maximum = max}}))
53+
else
54+
device.log.warn_with({hub_logs = true}, string.format("Device reported a min color temperature %d K that is not lower than the reported max color temperature %d K", temp_in_kelvin, max))
55+
end
56+
end
57+
end
58+
59+
local color_temp_range_handlers = {
60+
NAME = "Color temp range handlers",
61+
zigbee_handlers = {
62+
attr = {
63+
[clusters.ColorControl.ID] = {
64+
[clusters.ColorControl.attributes.ColorTempPhysicalMinMireds.ID] = color_temp_min_mireds_handler,
65+
[clusters.ColorControl.attributes.ColorTempPhysicalMaxMireds.ID] = color_temp_max_mireds_handler
66+
}
67+
}
68+
},
69+
can_handle = require("color_temp_range_handlers.can_handle")
70+
}
71+
72+
return color_temp_range_handlers

drivers/SmartThings/zigbee-switch/src/configurations/init.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,26 @@ configurations.handle_reporting_config_response = function(driver, device, zb_me
8484
end
8585
end
8686

87-
configurations.power_reconfig_wrapper = function(orig_function)
87+
configurations.reconfig_wrapper = function(orig_function)
8888
local new_init = function(driver, device)
8989
local config_version = device:get_field(CONFIGURATION_VERSION_KEY)
9090
if config_version == nil or config_version < driver.current_config_version then
9191
if driver._reconfig_timer == nil then
9292
driver._reconfig_timer = driver:call_with_delay(5*60, configurations.check_and_reconfig_devices, "reconfig_power_devices")
9393
end
9494
end
95+
96+
local capabilities = require "st.capabilities"
97+
for id, _ in pairs(device.profile.components) do
98+
if device:supports_capability(capabilities.colorTemperature, id) and
99+
device:get_latest_state(id, capabilities.colorTemperature.ID, capabilities.colorTemperature.colorTemperatureRange.NAME) == nil then
100+
local clusters = require "st.zigbee.zcl.clusters"
101+
driver:call_with_delay(5*60, function()
102+
device:send_to_component(id, clusters.ColorControl.attributes.ColorTempPhysicalMinMireds:read(device))
103+
device:send_to_component(id, clusters.ColorControl.attributes.ColorTempPhysicalMaxMireds:read(device))
104+
end)
105+
end
106+
end
95107
orig_function(driver, device)
96108
end
97109
return new_init

drivers/SmartThings/zigbee-switch/src/ezex/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ end
1212
local ezex_switch_handler = {
1313
NAME = "ezex switch handler",
1414
lifecycle_handlers = {
15-
init = configurations.power_reconfig_wrapper(do_init)
15+
init = configurations.reconfig_wrapper(do_init)
1616
},
1717
can_handle = require("ezex.can_handle"),
1818
}

drivers/SmartThings/zigbee-switch/src/frient-IO/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ local frient_bridge_handler = {
478478
},
479479
lifecycle_handlers = {
480480
added = added_handler,
481-
init = init_handler,
481+
init = configurationMap.reconfig_wrapper(init_handler),
482482
doConfigure = configure_handler,
483483
infoChanged = info_changed_handler
484484
},

drivers/SmartThings/zigbee-switch/src/frient/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ local frient_smart_plug = {
152152
},
153153
},
154154
lifecycle_handlers = {
155-
init = device_init,
155+
init = configurationMap.reconfig_wrapper(device_init),
156156
doConfigure = do_configure,
157157
added = device_added,
158158
},

drivers/SmartThings/zigbee-switch/src/hanssem/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ local HanssemSwitch = {
5050
NAME = "Zigbee Hanssem Switch",
5151
lifecycle_handlers = {
5252
added = device_added,
53-
init = configurations.power_reconfig_wrapper(device_init)
53+
init = configurations.reconfig_wrapper(device_init)
5454
},
5555
can_handle = require("hanssem.can_handle"),
5656
}

drivers/SmartThings/zigbee-switch/src/ikea-xy-color-bulb/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ end
147147
local ikea_xy_color_bulb = {
148148
NAME = "IKEA XY Color Bulb",
149149
lifecycle_handlers = {
150-
init = configurationMap.power_reconfig_wrapper(device_init)
150+
init = configurationMap.reconfig_wrapper(device_init)
151151
},
152152
capability_handlers = {
153153
[capabilities.colorControl.ID] = {

drivers/SmartThings/zigbee-switch/src/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ local zigbee_switch_driver_template = {
8080
},
8181
current_config_version = 1,
8282
lifecycle_handlers = {
83-
init = configurationMap.power_reconfig_wrapper(device_init),
83+
init = configurationMap.reconfig_wrapper(device_init),
8484
added = lazy_handler("lifecycle_handlers.device_added"),
8585
infoChanged = lazy_handler("lifecycle_handlers.info_changed"),
8686
doConfigure = lazy_handler("lifecycle_handlers.do_configure"),

0 commit comments

Comments
 (0)