Skip to content

Commit d942b6e

Browse files
committed
CHAD-17428: Native handle registration for zigbee stateless step capabilities
1 parent 2023b46 commit d942b6e

4 files changed

Lines changed: 104 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ local OPTIONS_MASK = 0x01 -- default: The `ExecuteIfOff` option is overriden
1313
local IGNORE_COMMAND_IF_OFF = 0x00 -- default: the command will not be executed if the device is off
1414

1515
local function step_color_temperature_by_percent_handler(driver, device, cmd)
16+
if type(device.register_native_capability_cmd_handler) == "function" then
17+
device:register_native_capability_cmd_handler(cmd.capability, cmd.command)
18+
end
1619
local step_percent_change = cmd.args and cmd.args.stepSize or 0
1720
if step_percent_change == 0 then return end
1821
local step_mode = step_percent_change > 0 and clusters.ColorControl.types.CcStepMode.DOWN or clusters.ColorControl.types.CcStepMode.UP
@@ -42,6 +45,9 @@ local function step_color_temperature_by_percent_handler(driver, device, cmd)
4245
end
4346

4447
local function step_level_handler(driver, device, cmd)
48+
if type(device.register_native_capability_cmd_handler) == "function" then
49+
device:register_native_capability_cmd_handler(cmd.capability, cmd.command)
50+
end
4551
local step_size = st_utils.round((cmd.args and cmd.args.stepSize or 0)/100.0 * 254)
4652
if step_size == 0 then return end
4753
local step_mode = step_size > 0 and clusters.Level.types.MoveStepMode.UP or clusters.Level.types.MoveStepMode.DOWN

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ test.register_message_test(
308308
{ capability = "statelessColorTemperatureStep", component = "main", command = "stepColorTemperatureByPercent", args = { 20 } }
309309
}
310310
},
311+
{
312+
channel = "devices",
313+
direction = "send",
314+
message = {
315+
"register_native_capability_cmd_handler",
316+
{ device_uuid = mock_device.id, capability_id = "statelessColorTemperatureStep", capability_cmd_id = "stepColorTemperatureByPercent" }
317+
}
318+
},
311319
{
312320
channel = "zigbee",
313321
direction = "send",
@@ -324,6 +332,14 @@ test.register_message_test(
324332
{ capability = "statelessColorTemperatureStep", component = "main", command = "stepColorTemperatureByPercent", args = { 90 } }
325333
}
326334
},
335+
{
336+
channel = "devices",
337+
direction = "send",
338+
message = {
339+
"register_native_capability_cmd_handler",
340+
{ device_uuid = mock_device.id, capability_id = "statelessColorTemperatureStep", capability_cmd_id = "stepColorTemperatureByPercent" }
341+
}
342+
},
327343
{
328344
channel = "zigbee",
329345
direction = "send",
@@ -340,6 +356,14 @@ test.register_message_test(
340356
{ capability = "statelessColorTemperatureStep", component = "main", command = "stepColorTemperatureByPercent", args = { -50 } }
341357
}
342358
},
359+
{
360+
channel = "devices",
361+
direction = "send",
362+
message = {
363+
"register_native_capability_cmd_handler",
364+
{ device_uuid = mock_device.id, capability_id = "statelessColorTemperatureStep", capability_cmd_id = "stepColorTemperatureByPercent" }
365+
}
366+
},
343367
{
344368
channel = "zigbee",
345369
direction = "send",
@@ -362,6 +386,14 @@ test.register_message_test(
362386
{ capability = "statelessSwitchLevelStep", component = "main", command = "stepLevel", args = { 25 } }
363387
}
364388
},
389+
{
390+
channel = "devices",
391+
direction = "send",
392+
message = {
393+
"register_native_capability_cmd_handler",
394+
{ device_uuid = mock_device.id, capability_id = "statelessSwitchLevelStep", capability_cmd_id = "stepLevel" }
395+
}
396+
},
365397
{
366398
channel = "zigbee",
367399
direction = "send",
@@ -378,6 +410,14 @@ test.register_message_test(
378410
{ capability = "statelessSwitchLevelStep", component = "main", command = "stepLevel", args = { -50 } }
379411
}
380412
},
413+
{
414+
channel = "devices",
415+
direction = "send",
416+
message = {
417+
"register_native_capability_cmd_handler",
418+
{ device_uuid = mock_device.id, capability_id = "statelessSwitchLevelStep", capability_cmd_id = "stepLevel" }
419+
}
420+
},
381421
{
382422
channel = "zigbee",
383423
direction = "send",
@@ -394,6 +434,14 @@ test.register_message_test(
394434
{ capability = "statelessSwitchLevelStep", component = "main", command = "stepLevel", args = { 100 } }
395435
}
396436
},
437+
{
438+
channel = "devices",
439+
direction = "send",
440+
message = {
441+
"register_native_capability_cmd_handler",
442+
{ device_uuid = mock_device.id, capability_id = "statelessSwitchLevelStep", capability_cmd_id = "stepLevel" }
443+
}
444+
},
397445
{
398446
channel = "zigbee",
399447
direction = "send",

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ test.register_message_test(
161161
{ capability = "statelessSwitchLevelStep", component = "main", command = "stepLevel", args = { 25 } }
162162
}
163163
},
164+
{
165+
channel = "devices",
166+
direction = "send",
167+
message = {
168+
"register_native_capability_cmd_handler",
169+
{ device_uuid = mock_device.id, capability_id = "statelessSwitchLevelStep", capability_cmd_id = "stepLevel" }
170+
}
171+
},
164172
{
165173
channel = "zigbee",
166174
direction = "send",
@@ -177,6 +185,14 @@ test.register_message_test(
177185
{ capability = "statelessSwitchLevelStep", component = "main", command = "stepLevel", args = { -50 } }
178186
}
179187
},
188+
{
189+
channel = "devices",
190+
direction = "send",
191+
message = {
192+
"register_native_capability_cmd_handler",
193+
{ device_uuid = mock_device.id, capability_id = "statelessSwitchLevelStep", capability_cmd_id = "stepLevel" }
194+
}
195+
},
180196
{
181197
channel = "zigbee",
182198
direction = "send",
@@ -193,6 +209,14 @@ test.register_message_test(
193209
{ capability = "statelessSwitchLevelStep", component = "main", command = "stepLevel", args = { 100 } }
194210
}
195211
},
212+
{
213+
channel = "devices",
214+
direction = "send",
215+
message = {
216+
"register_native_capability_cmd_handler",
217+
{ device_uuid = mock_device.id, capability_id = "statelessSwitchLevelStep", capability_cmd_id = "stepLevel" }
218+
}
219+
},
196220
{
197221
channel = "zigbee",
198222
direction = "send",
@@ -324,6 +348,14 @@ test.register_message_test(
324348
{ capability = "statelessColorTemperatureStep", component = "main", command = "stepColorTemperatureByPercent", args = { 20 } }
325349
}
326350
},
351+
{
352+
channel = "devices",
353+
direction = "send",
354+
message = {
355+
"register_native_capability_cmd_handler",
356+
{ device_uuid = mock_device.id, capability_id = "statelessColorTemperatureStep", capability_cmd_id = "stepColorTemperatureByPercent" }
357+
}
358+
},
327359
{
328360
channel = "zigbee",
329361
direction = "send",
@@ -340,6 +372,14 @@ test.register_message_test(
340372
{ capability = "statelessColorTemperatureStep", component = "main", command = "stepColorTemperatureByPercent", args = { 90 } }
341373
}
342374
},
375+
{
376+
channel = "devices",
377+
direction = "send",
378+
message = {
379+
"register_native_capability_cmd_handler",
380+
{ device_uuid = mock_device.id, capability_id = "statelessColorTemperatureStep", capability_cmd_id = "stepColorTemperatureByPercent" }
381+
}
382+
},
343383
{
344384
channel = "zigbee",
345385
direction = "send",
@@ -356,6 +396,14 @@ test.register_message_test(
356396
{ capability = "statelessColorTemperatureStep", component = "main", command = "stepColorTemperatureByPercent", args = { -50 } }
357397
}
358398
},
399+
{
400+
channel = "devices",
401+
direction = "send",
402+
message = {
403+
"register_native_capability_cmd_handler",
404+
{ device_uuid = mock_device.id, capability_id = "statelessColorTemperatureStep", capability_cmd_id = "stepColorTemperatureByPercent" }
405+
}
406+
},
359407
{
360408
channel = "zigbee",
361409
direction = "send",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ test.register_coroutine_test(
157157
function()
158158
test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot")
159159
test.socket.capability:__queue_receive({mock_device.id, { capability = "statelessColorTemperatureStep", component = "main", command = "stepColorTemperatureByPercent", args = { 20 } } })
160+
mock_device:expect_native_cmd_handler_registration("statelessColorTemperatureStep", "stepColorTemperatureByPercent")
160161

161162
test.socket.zigbee:__expect_send(
162163
{
@@ -173,6 +174,7 @@ test.register_coroutine_test(
173174
function()
174175
test.timer.__create_and_queue_test_time_advance_timer(1, "oneshot")
175176
test.socket.capability:__queue_receive({mock_device.id, { capability = "statelessSwitchLevelStep", component = "main", command = "stepLevel", args = { 25 } } })
177+
mock_device:expect_native_cmd_handler_registration("statelessSwitchLevelStep", "stepLevel")
176178

177179
test.socket.zigbee:__expect_send(
178180
{

0 commit comments

Comments
 (0)