Skip to content

Commit 0843dc6

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 patched driver.lua which includes a mechanism to filter devices when building device info which don't match device type filters added to the driver. https://smartthings.atlassian.net/browse/CHAD-16558
1 parent 32685fb commit 0843dc6

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 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 non_zigbee_devices = {
43+
NAME = "non zigbee devices filter",
44+
lifecycle_handlers = {
45+
init = device_init,
46+
added = device_added,
47+
doConfigure = do_configure
48+
},
49+
can_handle = can_handle
50+
}
51+
52+
return non_zigbee_devices
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
18+
-- This test attempts to add a zwave device to this zigbee switch driver
19+
-- Once the monkey-patch is removed with hubcore 59 is released with:
20+
-- https://smartthings.atlassian.net/browse/CHAD-16552
21+
local mock_device = test.mock_device.build_test_zwave_device({
22+
profile = t_utils.get_profile_definition("on-off-level.yml"),
23+
})
24+
25+
-- Just validating that the driver doesn't crash is enough to validate
26+
-- that the work-around is effective in ignoring the incorrect device kind
27+
test.register_coroutine_test("mismatched_device_kind_ignored", function()
28+
test.mock_device.add_test_device(mock_device)
29+
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
30+
test.wait_for_events()
31+
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "init" })
32+
test.wait_for_events()
33+
end,
34+
nil
35+
)
36+
37+
test.run_registered_tests()

0 commit comments

Comments
 (0)