Skip to content

Commit 9bbd9f5

Browse files
committed
zigbee-switch: Filter incorrect network type
A small number of zwave devices failed to migrate correctly and ended up as zwave devices attached to the zigbee switch driver. This change adds a subdriver (non_zigbee_devices) which handles non-zigbee devices safely without crashing the driver. https://smartthings.atlassian.net/browse/CHAD-16558
1 parent 32685fb commit 9bbd9f5

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ local zigbee_switch_driver_template = {
140140
capabilities.motionSensor
141141
},
142142
sub_drivers = {
143+
lazy_load_if_possible("non_zigbee_devices"),
143144
lazy_load_if_possible("hanssem"),
144145
lazy_load_if_possible("aqara"),
145146
lazy_load_if_possible("aqara-light"),
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
-- Copyright 2025 SmartThings
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
15+
-- This is a patch for the zigbee-switch driver to fix https://smartthings.atlassian.net/browse/CHAD-16558
16+
-- Several hubs were found that had zigbee switch drivers hosting zwave devices.
17+
-- This patch works around it until hubcore 0.59 is released with
18+
-- https://smartthings.atlassian.net/browse/CHAD-16552
19+
20+
local st_device = require "st.device"
21+
local log = require "log"
22+
23+
local function can_handle(opts, driver, device)
24+
if device.network_type ~= st_device.NETWORK_TYPE_ZIGBEE and device.network_type ~= st_device.NETWORK_TYPE_CHILD then
25+
return true, require("non_zigbee_devices")
26+
end
27+
return false
28+
end
29+
30+
local function device_added(driver, device, event)
31+
log.info(string.format("Non zigbee device added: %s", device))
32+
end
33+
34+
local function device_init(driver, device, event)
35+
log.info(string.format("Non zigbee device init: %s", device))
36+
end
37+
38+
local function do_configure(driver, device)
39+
log.info(string.format("Non zigbee do configure: %s", device))
40+
end
41+
42+
local function info_changed(driver, device, event, args)
43+
log.info(string.format("Non zigbee infoChanged: %s", device))
44+
end
45+
46+
local non_zigbee_devices = {
47+
NAME = "non zigbee devices filter",
48+
lifecycle_handlers = {
49+
init = device_init,
50+
added = device_added,
51+
doConfigure = do_configure,
52+
infoChanged = info_changed
53+
},
54+
can_handle = can_handle
55+
}
56+
57+
return non_zigbee_devices
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- Copyright 2025 SmartThings
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
15+
local test = require "integration_test"
16+
local t_utils = require "integration_test.utils"
17+
local dkjson = require 'dkjson'
18+
19+
-- This test attempts to add a zwave device to this zigbee switch driver
20+
-- Once the monkey-patch is removed with hubcore 59 is released with:
21+
-- https://smartthings.atlassian.net/browse/CHAD-16552
22+
local mock_device = test.mock_device.build_test_zwave_device({
23+
profile = t_utils.get_profile_definition("on-off-level.yml"),
24+
})
25+
26+
local function test_init()
27+
test.mock_device.add_test_device(mock_device)
28+
end
29+
30+
test.set_test_init_function(test_init)
31+
32+
-- Just validating that the driver doesn't crash is enough to validate
33+
-- that the work-around is effective in ignoring the incorrect device kind
34+
test.register_coroutine_test("zwave_device_handled", function()
35+
test.mock_device.add_test_device(mock_device)
36+
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
37+
test.wait_for_events()
38+
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "init" })
39+
test.wait_for_events()
40+
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
41+
mock_device:expect_metadata_update({provisioning_state = "PROVISIONED"})
42+
test.wait_for_events()
43+
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "infoChanged", dkjson.encode(mock_device.raw_st_data) })
44+
test.wait_for_events()
45+
end,
46+
nil
47+
)
48+
49+
test.register_message_test(
50+
"Capability command for incorrect protocol",
51+
{
52+
channel = "capability",
53+
direction = "receive",
54+
message = { mock_device.id, { capability = "switch", component = "main", command = "on", args = { } } }
55+
}
56+
)
57+
58+
test.run_registered_tests()

0 commit comments

Comments
 (0)