Skip to content

Commit 10f2454

Browse files
committed
CHAD-17063: Zigbee-button lazy load subdrivers
1 parent 5a96c15 commit 10f2454

File tree

108 files changed

+821
-1104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+821
-1104
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local is_aqara_products = function(opts, driver, device)
5+
local FINGERPRINTS = require "aqara.fingerprints"
6+
if FINGERPRINTS[device:get_model()] and FINGERPRINTS[device:get_model()].mfr == device:get_manufacturer() then
7+
return true, require("aqara")
8+
end
9+
return false
10+
end
11+
12+
return is_aqara_products
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local FINGERPRINTS = {
5+
["lumi.remote.b1acn02"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2032", quantity = 1 }, -- Aqara Wireless Mini Switch T1
6+
["lumi.remote.acn003"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2032", quantity = 1 }, -- Aqara Wireless Remote Switch E1 (Single Rocker)
7+
["lumi.remote.b186acn03"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2032", quantity = 1 }, -- Aqara Wireless Remote Switch T1 (Single Rocker)
8+
["lumi.remote.b286acn03"] = { mfr = "LUMI", btn_cnt = 3, type = "CR2032", quantity = 1 }, -- Aqara Wireless Remote Switch T1 (Double Rocker)
9+
["lumi.remote.b18ac1"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2450", quantity = 1 }, -- Aqara Wireless Remote Switch H1 (Single Rocker)
10+
["lumi.remote.b28ac1"] = { mfr = "LUMI", btn_cnt = 3, type = "CR2450", quantity = 1 } -- Aqara Wireless Remote Switch H1 (Double Rocker)
11+
}
12+
13+
return FINGERPRINTS

drivers/SmartThings/zigbee-button/src/aqara/init.lua

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
-- Copyright 2024 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.
1+
-- Copyright 2024 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
144

155
local battery_defaults = require "st.zigbee.defaults.battery_defaults"
166
local clusters = require "st.zigbee.zcl.clusters"
@@ -34,14 +24,7 @@ local MULTISTATE_INPUT_CLUSTER_ID = 0x0012
3424
local PRESENT_ATTRIBUTE_ID = 0x0055
3525

3626
local COMP_LIST = { "button1", "button2", "all" }
37-
local AQARA_REMOTE_SWITCH = {
38-
["lumi.remote.b1acn02"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2032", quantity = 1 }, -- Aqara Wireless Mini Switch T1
39-
["lumi.remote.acn003"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2032", quantity = 1 }, -- Aqara Wireless Remote Switch E1 (Single Rocker)
40-
["lumi.remote.b186acn03"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2032", quantity = 1 }, -- Aqara Wireless Remote Switch T1 (Single Rocker)
41-
["lumi.remote.b286acn03"] = { mfr = "LUMI", btn_cnt = 3, type = "CR2032", quantity = 1 }, -- Aqara Wireless Remote Switch T1 (Double Rocker)
42-
["lumi.remote.b18ac1"] = { mfr = "LUMI", btn_cnt = 1, type = "CR2450", quantity = 1 }, -- Aqara Wireless Remote Switch H1 (Single Rocker)
43-
["lumi.remote.b28ac1"] = { mfr = "LUMI", btn_cnt = 3, type = "CR2450", quantity = 1 } -- Aqara Wireless Remote Switch H1 (Double Rocker)
44-
}
27+
local FINGERPRINTS = require "aqara.fingerprints"
4528

4629
local configuration = {
4730
{
@@ -65,7 +48,7 @@ local configuration = {
6548
local function present_value_attr_handler(driver, device, value, zb_rx)
6649
if value.value < 0xFF then
6750
local end_point = zb_rx.address_header.src_endpoint.value
68-
local btn_evt_cnt = AQARA_REMOTE_SWITCH[device:get_model()].btn_cnt or 1
51+
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
6952
local evt = capabilities.button.button.held({ state_change = true })
7053
if value.value == 1 then
7154
evt = capabilities.button.button.pushed({ state_change = true })
@@ -110,7 +93,7 @@ local function battery_level_handler(driver, device, value, zb_rx)
11093
end
11194

11295
local function mode_switching_handler(driver, device, value, zb_rx)
113-
local btn_evt_cnt = AQARA_REMOTE_SWITCH[device:get_model()].btn_cnt or 1
96+
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
11497
local allow = device.preferences[MODE_CHANGE] or false
11598
if allow then
11699
local mode = device:get_field(MODE) or 1
@@ -139,14 +122,6 @@ local function mode_switching_handler(driver, device, value, zb_rx)
139122
end
140123
end
141124

142-
local is_aqara_products = function(opts, driver, device)
143-
local isAqaraProducts = false
144-
if AQARA_REMOTE_SWITCH[device:get_model()] and AQARA_REMOTE_SWITCH[device:get_model()].mfr == device:get_manufacturer() then
145-
isAqaraProducts = true
146-
end
147-
return isAqaraProducts
148-
end
149-
150125
local function device_init(driver, device)
151126
battery_defaults.build_linear_voltage_init(2.6, 3.0)(driver, device)
152127
if configuration ~= nil then
@@ -157,11 +132,11 @@ local function device_init(driver, device)
157132
end
158133

159134
local function added_handler(self, device)
160-
local btn_evt_cnt = AQARA_REMOTE_SWITCH[device:get_model()].btn_cnt or 1
135+
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
161136
local mode = device:get_field(MODE) or 0
162137
local model = device:get_model()
163-
local type = AQARA_REMOTE_SWITCH[device:get_model()].type or "CR2032"
164-
local quantity = AQARA_REMOTE_SWITCH[device:get_model()].quantity or 1
138+
local type = FINGERPRINTS[device:get_model()].type or "CR2032"
139+
local quantity = FINGERPRINTS[device:get_model()].quantity or 1
165140

166141
if mode == 0 then
167142
if model == "lumi.remote.b18ac1" or model == "lumi.remote.b28ac1" then
@@ -233,7 +208,7 @@ local aqara_wireless_switch_handler = {
233208
}
234209
}
235210
},
236-
can_handle = is_aqara_products
211+
can_handle = require("aqara.can_handle"),
237212
}
238213

239214
return aqara_wireless_switch_handler

drivers/SmartThings/zigbee-button/src/button_utils.lua

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
-- Copyright 2022 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.
1+
-- Copyright 2022 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
143

154
local capabilities = require "st.capabilities"
165
local log = require "log"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local function can_handle_zigbee_dimming_remote(opts, driver, device, ...)
5+
local FINGERPRINTS = require("dimming-remote.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
8+
return true, require("dimming-remote")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return can_handle_zigbee_dimming_remote
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local ZIBEE_DIMMING_SWITCH_FINGERPRINTS = {
5+
{ mfr = "OSRAM", model = "LIGHTIFY Dimming Switch" },
6+
{ mfr = "CentraLite", model = "3130" }
7+
}
8+
9+
return ZIBEE_DIMMING_SWITCH_FINGERPRINTS

drivers/SmartThings/zigbee-button/src/dimming-remote/init.lua

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
-- Copyright 2022 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.
1+
-- Copyright 2022 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
144

155
local zcl_clusters = require "st.zigbee.zcl.clusters"
166
local capabilities = require "st.capabilities"
@@ -22,19 +12,7 @@ local battery_defaults = require "st.zigbee.defaults.battery_defaults"
2212

2313
local button_utils = require "button_utils"
2414

25-
local ZIBEE_DIMMING_SWITCH_FINGERPRINTS = {
26-
{ mfr = "OSRAM", model = "LIGHTIFY Dimming Switch" },
27-
{ mfr = "CentraLite", model = "3130" }
28-
}
2915

30-
local function can_handle_zigbee_dimming_remote(opts, driver, device, ...)
31-
for _, fingerprint in ipairs(ZIBEE_DIMMING_SWITCH_FINGERPRINTS) do
32-
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
33-
return true
34-
end
35-
end
36-
return false
37-
end
3816

3917
local function button_pushed_handler(button_number)
4018
return function(self, device, value, zb_rx)
@@ -84,7 +62,7 @@ local dimming_remote = {
8462
}
8563
}
8664
},
87-
can_handle = can_handle_zigbee_dimming_remote
65+
can_handle = require("dimming-remote.can_handle"),
8866
}
8967

9068
return dimming_remote
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local function can_handle_ewelink_button(opts, driver, device, ...)
5+
local FINGERPRINTS = require("ewelink.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
8+
return true, require("ewelink")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return can_handle_ewelink_button
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local EWELINK_BUTTON_FINGERPRINTS = {
5+
{ mfr = "eWeLink", model = "WB01" },
6+
{ mfr = "eWeLink", model = "SNZB-01P" }
7+
}
8+
9+
return EWELINK_BUTTON_FINGERPRINTS
Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
-- Copyright 2022 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.
1+
-- Copyright 2022 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
144

155
local capabilities = require "st.capabilities"
166
local clusters = require "st.zigbee.zcl.clusters"
@@ -19,19 +9,7 @@ local device_management = require "st.zigbee.device_management"
199
local OnOff = clusters.OnOff
2010
local button = capabilities.button.button
2111

22-
local EWELINK_BUTTON_FINGERPRINTS = {
23-
{ mfr = "eWeLink", model = "WB01" },
24-
{ mfr = "eWeLink", model = "SNZB-01P" }
25-
}
2612

27-
local function can_handle_ewelink_button(opts, driver, device, ...)
28-
for _, fingerprint in ipairs(EWELINK_BUTTON_FINGERPRINTS) do
29-
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
30-
return true
31-
end
32-
end
33-
return false
34-
end
3513

3614
local function do_configure(driver, device)
3715
device:configure()
@@ -61,7 +39,7 @@ local ewelink_button = {
6139
}
6240
}
6341
},
64-
can_handle = can_handle_ewelink_button
42+
can_handle = require("ewelink.can_handle"),
6543
}
6644

67-
return ewelink_button
45+
return ewelink_button

0 commit comments

Comments
 (0)