Skip to content

Commit a84be11

Browse files
committed
Use native & default handlers for ZLL devices
1 parent 5b2c048 commit a84be11

File tree

12 files changed

+52
-20
lines changed

12 files changed

+52
-20
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ local IKEA_XY_COLOR_BULB_FINGERPRINTS = {
3535
}
3636

3737
local function can_handle_ikea_xy_color_bulb(opts, driver, device)
38-
return (IKEA_XY_COLOR_BULB_FINGERPRINTS[device:get_manufacturer()] or {})[device:get_model()] or false
38+
local can_handle = (IKEA_XY_COLOR_BULB_FINGERPRINTS[device:get_manufacturer()] or {})[device:get_model()]
39+
if can_handle then
40+
local subdriver = require("ikea-xy-color-bulb")
41+
return true, subdriver
42+
else
43+
return false
44+
end
3945
end
4046

4147
local device_init = function(self, device)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ end
3131

3232
local function lazy_load_if_possible(sub_driver_name)
3333
-- gets the current lua libs api version
34-
3534
-- version 9 will include the lazy loading functions
3635
if version.api >= 9 then
3736
return ZigbeeDriver.lazy_load_sub_driver(require(sub_driver_name))
@@ -105,7 +104,8 @@ local zigbee_switch_driver_template = {
105104
lazy_load_if_possible("zigbee-dimming-light"),
106105
lazy_load_if_possible("white-color-temp-bulb"),
107106
lazy_load_if_possible("rgbw-bulb"),
108-
lazy_load_if_possible("zll-dimmer-bulb"),
107+
(version.api < 16) and lazy_load_if_possible("zll-dimmer-bulb") or nil,
108+
lazy_load_if_possible("ikea-xy-color-bulb"),
109109
lazy_load_if_possible("zll-polling"),
110110
lazy_load_if_possible("zigbee-switch-power"),
111111
lazy_load_if_possible("ge-link-bulb"),

drivers/SmartThings/zigbee-switch/src/lifecycle_handlers/device_added.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ end
2727

2828
return function(driver, device, event)
2929
local clusters = require "st.zigbee.zcl.clusters"
30+
local ZLL_PROFILE_ID = 0xC05E
3031
local device_lib = require "st.device"
32+
local version = require "version"
3133

3234
local main_endpoint = device:get_endpoint(clusters.OnOff.ID)
3335
if is_mcd_device(device) == false and device.network_type == device_lib.NETWORK_TYPE_ZIGBEE then
@@ -53,4 +55,7 @@ return function(driver, device, event)
5355
end
5456
end
5557
end
58+
if version.api > 15 and device:get_profile_id() == ZLL_PROFILE_ID then
59+
device:refresh()
60+
end
5661
end

drivers/SmartThings/zigbee-switch/src/lifecycle_handlers/do_configure.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
local capabilities = require "st.capabilities"
1616
return function(self, device)
17-
device:refresh()
17+
local ZLL_PROFILE_ID = 0xC05E
18+
local version = require "version"
19+
if version.api < 16 or (version.api > 15 and device:get_profile_id() ~= ZLL_PROFILE_ID) then
20+
device:refresh()
21+
end
1822
device:configure()
1923

2024
-- Additional one time configuration

drivers/SmartThings/zigbee-switch/src/test/test_sengled_dimmer_bulb_with_motion_sensor.lua

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ local test = require "integration_test"
1616
local capabilities = require "st.capabilities"
1717
local clusters = require "st.zigbee.zcl.clusters"
1818
local t_utils = require "integration_test.utils"
19+
local version = require "version"
1920
local zigbee_test_utils = require "integration_test.zigbee_test_utils"
2021

2122
local OnOff = clusters.OnOff
2223
local Level = clusters.Level
2324
local IASZone = clusters.IASZone
24-
local IasEnrollResponseCode = IASZone.types.EnrollResponseCode
2525

2626
local mock_device = test.mock_device.build_test_zigbee_device(
2727
{ profile = t_utils.get_profile_definition("on-off-level-motion-sensor.yml"),
@@ -31,7 +31,8 @@ local mock_device = test.mock_device.build_test_zigbee_device(
3131
id = 1,
3232
manufacturer = "sengled",
3333
model = "E13-N11",
34-
server_clusters = { 0x0006, 0x0008, 0x0500 }
34+
server_clusters = { 0x0006, 0x0008, 0x0500 },
35+
profile_id = 0xC05E
3536
}
3637
}
3738
}
@@ -76,14 +77,6 @@ test.register_coroutine_test(
7677
mock_device.id,
7778
IASZone.attributes.ZoneStatus:configure_reporting(mock_device, 30, 300, 1)
7879
})
79-
test.socket.zigbee:__expect_send({
80-
mock_device.id,
81-
IASZone.attributes.IASCIEAddress:write(mock_device, zigbee_test_utils.mock_hub_eui)
82-
})
83-
test.socket.zigbee:__expect_send({
84-
mock_device.id,
85-
IASZone.server.commands.ZoneEnrollResponse(mock_device, IasEnrollResponseCode.SUCCESS, 0x00)
86-
})
8780
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
8881
end
8982
)
@@ -116,6 +109,7 @@ test.register_coroutine_test(
116109
test.socket.zigbee:__set_channel_ordering("relaxed")
117110
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
118111
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "on", args = {} } })
112+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "on") end
119113

120114
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device) })
121115

@@ -134,6 +128,7 @@ test.register_coroutine_test(
134128
test.socket.zigbee:__set_channel_ordering("relaxed")
135129
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
136130
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "off", args = {} } })
131+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "off") end
137132

138133
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.Off(mock_device) })
139134

@@ -152,6 +147,7 @@ test.register_coroutine_test(
152147
test.socket.zigbee:__set_channel_ordering("relaxed")
153148
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
154149
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switchLevel", component = "main", command = "setLevel", args = { 57 } } })
150+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switchLevel", "setLevel") end
155151

156152
test.socket.zigbee:__expect_send({ mock_device.id, Level.server.commands.MoveToLevelWithOnOff(mock_device, 144, 0xFFFF) })
157153

drivers/SmartThings/zigbee-switch/src/test/test_zll_color_temp_bulb.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
local test = require "integration_test"
1616
local clusters = require "st.zigbee.zcl.clusters"
1717
local t_utils = require "integration_test.utils"
18+
local version = require "version"
1819
local zigbee_test_utils = require "integration_test.zigbee_test_utils"
1920

2021
local OnOff = clusters.OnOff
@@ -83,6 +84,7 @@ test.register_coroutine_test(
8384
test.socket.zigbee:__set_channel_ordering("relaxed")
8485
test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot")
8586
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "on", args = {} } })
87+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "on") end
8688
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device)})
8789
test.wait_for_events()
8890
test.mock_time.advance_time(2)
@@ -98,6 +100,7 @@ test.register_coroutine_test(
98100
test.socket.zigbee:__set_channel_ordering("relaxed")
99101
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
100102
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "off", args = {} } })
103+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "off") end
101104
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.Off(mock_device)})
102105
test.wait_for_events()
103106
test.mock_time.advance_time(2)
@@ -113,6 +116,7 @@ test.register_coroutine_test(
113116
test.socket.zigbee:__set_channel_ordering("relaxed")
114117
test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot")
115118
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switchLevel", component = "main", command = "setLevel", args = {50} } })
119+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switchLevel", "setLevel") end
116120
test.socket.zigbee:__expect_send({ mock_device.id, Level.commands.MoveToLevelWithOnOff(mock_device, math.floor(50 / 100.0 * 254), 0xFFFF)})
117121
test.wait_for_events()
118122
test.mock_time.advance_time(2)
@@ -128,6 +132,7 @@ test.register_coroutine_test(
128132
test.socket.zigbee:__set_channel_ordering("relaxed")
129133
test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot")
130134
test.socket.capability:__queue_receive({ mock_device.id, { capability = "colorTemperature", component = "main", command = "setColorTemperature", args = {200} } })
135+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("colorTemperature", "setColorTemperature") end
131136
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device)})
132137
test.socket.zigbee:__expect_send({ mock_device.id, ColorControl.commands.MoveToColorTemperature(mock_device, 5000, 0x0000)})
133138
test.wait_for_events()

drivers/SmartThings/zigbee-switch/src/test/test_zll_dimmer_bulb.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
local test = require "integration_test"
1616
local clusters = require "st.zigbee.zcl.clusters"
1717
local t_utils = require "integration_test.utils"
18+
local version = require "version"
1819
local zigbee_test_utils = require "integration_test.zigbee_test_utils"
1920

2021
local OnOff = clusters.OnOff
@@ -121,6 +122,7 @@ test.register_coroutine_test(
121122
test.socket.zigbee:__set_channel_ordering("relaxed")
122123
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
123124
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "on", args = {} } })
125+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "on") end
124126

125127
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device) })
126128

@@ -138,6 +140,7 @@ test.register_coroutine_test(
138140
test.socket.zigbee:__set_channel_ordering("relaxed")
139141
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
140142
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "off", args = {} } })
143+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "off") end
141144

142145
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.Off(mock_device) })
143146

@@ -155,6 +158,7 @@ test.register_coroutine_test(
155158
test.socket.zigbee:__set_channel_ordering("relaxed")
156159
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
157160
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switchLevel", component = "main", command = "setLevel", args = { 57 } } })
161+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switchLevel", "setLevel") end
158162

159163
test.socket.zigbee:__expect_send({ mock_device.id, Level.server.commands.MoveToLevelWithOnOff(mock_device, 144, 0xFFFF) })
160164

drivers/SmartThings/zigbee-switch/src/test/test_zll_rgb_bulb.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local test = require "integration_test"
1616
local capabilities = require "st.capabilities"
1717
local clusters = require "st.zigbee.zcl.clusters"
1818
local t_utils = require "integration_test.utils"
19+
local version = require "version"
1920
local zigbee_test_utils = require "integration_test.zigbee_test_utils"
2021

2122
local OnOff = clusters.OnOff
@@ -149,6 +150,7 @@ test.register_coroutine_test(
149150
test.socket.zigbee:__set_channel_ordering("relaxed")
150151
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
151152
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "on", args = {} } })
153+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "on") end
152154

153155
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device) })
154156

@@ -168,6 +170,7 @@ test.register_coroutine_test(
168170
test.socket.zigbee:__set_channel_ordering("relaxed")
169171
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
170172
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "off", args = {} } })
173+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "off") end
171174

172175
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.Off(mock_device) })
173176

@@ -187,6 +190,7 @@ test.register_coroutine_test(
187190
test.socket.zigbee:__set_channel_ordering("relaxed")
188191
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
189192
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switchLevel", component = "main", command = "setLevel", args = { 57 } } })
193+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switchLevel", "setLevel") end
190194

191195
test.socket.zigbee:__expect_send({ mock_device.id, Level.server.commands.MoveToLevelWithOnOff(mock_device, 144, 0xFFFF) })
192196

drivers/SmartThings/zigbee-switch/src/test/test_zll_rgbw_bulb.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
local test = require "integration_test"
1616
local clusters = require "st.zigbee.zcl.clusters"
1717
local t_utils = require "integration_test.utils"
18+
local version = require "version"
1819
local zigbee_test_utils = require "integration_test.zigbee_test_utils"
1920

2021
local OnOff = clusters.OnOff
@@ -140,6 +141,7 @@ test.register_coroutine_test(
140141
test.socket.zigbee:__set_channel_ordering("relaxed")
141142
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
142143
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "on", args = {} } })
144+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "on") end
143145

144146
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device) })
145147

@@ -160,6 +162,7 @@ test.register_coroutine_test(
160162
test.socket.zigbee:__set_channel_ordering("relaxed")
161163
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
162164
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switch", component = "main", command = "off", args = {} } })
165+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switch", "off") end
163166

164167
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.Off(mock_device) })
165168

@@ -180,6 +183,7 @@ test.register_coroutine_test(
180183
test.socket.zigbee:__set_channel_ordering("relaxed")
181184
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
182185
test.socket.capability:__queue_receive({ mock_device.id, { capability = "switchLevel", component = "main", command = "setLevel", args = { 57 } } })
186+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("switchLevel", "setLevel") end
183187

184188
test.socket.zigbee:__expect_send({ mock_device.id, Level.server.commands.MoveToLevelWithOnOff(mock_device, 144, 0xFFFF) })
185189

@@ -200,6 +204,7 @@ test.register_coroutine_test(
200204
test.socket.zigbee:__set_channel_ordering("relaxed")
201205
test.timer.__create_and_queue_test_time_advance_timer(2, "oneshot")
202206
test.socket.capability:__queue_receive({ mock_device.id, { capability = "colorTemperature", component = "main", command = "setColorTemperature", args = {200} } })
207+
if version.api > 15 then mock_device:expect_native_cmd_handler_registration("colorTemperature", "setColorTemperature") end
203208

204209
test.socket.zigbee:__expect_send({ mock_device.id, OnOff.commands.On(mock_device)})
205210
test.socket.zigbee:__expect_send({ mock_device.id, ColorControl.commands.MoveToColorTemperature(mock_device, 5000, 0x0000)})

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ local function can_handle_zigbee_dimming_light(opts, driver, device)
8585
return false
8686
end
8787

88+
local function do_configure(driver, device)
89+
device:refresh()
90+
device:configure()
91+
end
92+
8893
local function device_init(driver, device)
8994
for _,attribute in ipairs(DIMMING_LIGHT_CONFIGURATION) do
9095
device:add_configured_attribute(attribute)
@@ -99,7 +104,8 @@ local zigbee_dimming_light = {
99104
NAME = "Zigbee Dimming Light",
100105
lifecycle_handlers = {
101106
init = configurations.power_reconfig_wrapper(device_init),
102-
added = device_added
107+
added = device_added,
108+
doConfigure = do_configure
103109
},
104110
sub_drivers = {
105111
require("zigbee-dimming-light/osram-iqbr30"),

0 commit comments

Comments
 (0)