Skip to content

Commit 658e57b

Browse files
authored
Merge pull request #2518 from SmartThingsCommunity/chore/zwave-switch-ll-refactor
zwave-switch lazy loading of sub drivers refactor
2 parents d6dbbcf + 622aefa commit 658e57b

File tree

140 files changed

+860
-1785
lines changed

Some content is hidden

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

140 files changed

+860
-1785
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
5+
--- Determine whether the passed device is Aeon smart strip
6+
---
7+
--- @param driver Driver driver instance
8+
--- @param device Device device isntance
9+
--- @return boolean true if the device proper, else false
10+
local function can_handle_aeon_smart_strip(opts, driver, device, ...)
11+
local fingerprints = {
12+
{mfr = 0x0086, prod = 0x0003, model = 0x000B}, -- Aeon Smart Strip DSC11-ZWUS
13+
}
14+
for _, fingerprint in ipairs(fingerprints) do
15+
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
16+
local subdriver = require("aeon-smart-strip")
17+
return true, subdriver
18+
end
19+
end
20+
return false
21+
end
22+
23+
24+
return can_handle_aeon_smart_strip

drivers/SmartThings/zwave-switch/src/aeon-smart-strip/init.lua

Lines changed: 3 additions & 33 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 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
143

154
local capabilities = require "st.capabilities"
165
--- @type st.zwave.CommandClass
@@ -24,29 +13,10 @@ local Meter = (require "st.zwave.CommandClass.Meter")({ version = 3 })
2413
--- @type st.zwave.CommandClass.SwitchBinary
2514
local SwitchBinary = (require "st.zwave.CommandClass.SwitchBinary")({ version = 2 })
2615

27-
local AEON_SMART_STRIP_FINGERPRINTS = {
28-
{mfr = 0x0086, prod = 0x0003, model = 0x000B}, -- Aeon Smart Strip DSC11-ZWUS
29-
}
30-
3116
local ENERGY_UNIT_KWH = "kWh"
3217
local ENERGY_UNIT_KVAH = "kVAh"
3318
local POWER_UNIT_WATT = "W"
3419

35-
--- Determine whether the passed device is Aeon smart strip
36-
---
37-
--- @param driver Driver driver instance
38-
--- @param device Device device isntance
39-
--- @return boolean true if the device proper, else false
40-
local function can_handle_aeon_smart_strip(opts, driver, device, ...)
41-
for _, fingerprint in ipairs(AEON_SMART_STRIP_FINGERPRINTS) do
42-
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
43-
local subdriver = require("aeon-smart-strip")
44-
return true, subdriver
45-
end
46-
end
47-
return false
48-
end
49-
5020
local function binary_event_helper(self, device, cmd)
5121
local value = cmd.args.value and cmd.args.value or cmd.args.target_value
5222
local event = value == SwitchBinary.value.OFF_DISABLE and capabilities.switch.switch.off() or capabilities.switch.switch.on()
@@ -108,7 +78,7 @@ local aeon_smart_strip = {
10878
[Meter.REPORT] = meter_report_handler
10979
}
11080
},
111-
can_handle = can_handle_aeon_smart_strip,
81+
can_handle = require("aeon-smart-strip.can_handle"),
11282
}
11383

11484
return aeon_smart_strip
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local function can_handle(opts, driver, device, ...)
5+
local fingerprints = {
6+
{ mfr = 0x0086, model = 0x004E }
7+
}
8+
9+
for _, fingerprint in ipairs(fingerprints) do
10+
if device:id_match(fingerprint.mfr, nil, fingerprint.model) then
11+
local subdriver = require("aeotec-heavy-duty")
12+
return true, subdriver
13+
end
14+
end
15+
return false
16+
end
17+
18+
return can_handle

drivers/SmartThings/zwave-switch/src/aeotec-heavy-duty/init.lua

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
-- Author: CommanderQ
2-
--
3-
-- Copyright 2021 SmartThings
4-
--
5-
-- Licensed under the Apache License, Version 2.0 (the "License");
6-
-- you may not use this file except in compliance with the License.
7-
-- You may obtain a copy of the License at
8-
--
9-
-- http://www.apache.org/licenses/LICENSE-2.0
10-
--
11-
-- Unless required by applicable law or agreed to in writing, software
12-
-- distributed under the License is distributed on an "AS IS" BASIS,
13-
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
-- See the License for the specific language governing permissions and
15-
-- limitations under the License.
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
163

174
local capabilities = require "st.capabilities"
185
--- @type st.zwave.CommandClass.Meter
@@ -29,20 +16,6 @@ local LAST_REPORT_TIME = "LAST_REPORT_TIME"
2916
local POWER_UNIT_WATT = "W"
3017
local ENERGY_UNIT_KWH = "kWh"
3118

32-
local FINGERPRINTS = {
33-
{ mfr = 0x0086, model = 0x004E }
34-
}
35-
36-
local function can_handle(opts, driver, device, ...)
37-
for _, fingerprint in ipairs(FINGERPRINTS) do
38-
if device:id_match(fingerprint.mfr, nil, fingerprint.model) then
39-
local subdriver = require("aeotec-heavy-duty")
40-
return true, subdriver
41-
end
42-
end
43-
return false
44-
end
45-
4619
local function emit_power_consumption_report_event(device, value, channel)
4720
-- powerConsumptionReport report interval
4821
local current_time = os.time()
@@ -128,7 +101,7 @@ local driver_template = {
128101
lifecycle_handlers = {
129102
infoChanged = info_changed
130103
},
131-
can_handle = can_handle
104+
can_handle = require("aeotec-heavy-duty.can_handle")
132105
}
133106

134-
return driver_template;
107+
return driver_template;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
5+
local function can_handle(opts, driver, device, ...)
6+
local fingerprints = {
7+
{mfr = 0x0086, prodId = 0x0060},
8+
{mfr = 0x0371, prodId = 0x00AF}, -- Smart Switch 7 EU
9+
{mfr = 0x0371, prodId = 0x0017} -- Smart Switch 7 US
10+
}
11+
12+
for _, fingerprint in ipairs(fingerprints) do
13+
if device:id_match(fingerprint.mfr, nil, fingerprint.prodId) then
14+
local subdriver = require("aeotec-smart-switch")
15+
return true, subdriver
16+
end
17+
end
18+
return false
19+
end
20+
21+
return can_handle

drivers/SmartThings/zwave-switch/src/aeotec-smart-switch/init.lua

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

154
local capabilities = require "st.capabilities"
165
local Basic = (require "st.zwave.CommandClass.Basic")({ version=1 })
@@ -28,22 +17,6 @@ local LAST_REPORT_TIME = "LAST_REPORT_TIME"
2817
local POWER_UNIT_WATT = "W"
2918
local ENERGY_UNIT_KWH = "kWh"
3019

31-
local FINGERPRINTS = {
32-
{mfr = 0x0086, prodId = 0x0060},
33-
{mfr = 0x0371, prodId = 0x00AF}, -- Smart Switch 7 EU
34-
{mfr = 0x0371, prodId = 0x0017} -- Smart Switch 7 US
35-
}
36-
37-
local function can_handle(opts, driver, device, ...)
38-
for _, fingerprint in ipairs(FINGERPRINTS) do
39-
if device:id_match(fingerprint.mfr, nil, fingerprint.prodId) then
40-
local subdriver = require("aeotec-smart-switch")
41-
return true, subdriver
42-
end
43-
end
44-
return false
45-
end
46-
4720
local function emit_power_consumption_report_event(device, value, channel)
4821
-- powerConsumptionReport report interval
4922
local current_time = os.time()
@@ -144,7 +117,7 @@ local aeotec_smart_switch = {
144117
[Meter.REPORT] = meter_report_handler
145118
}
146119
},
147-
can_handle = can_handle
120+
can_handle = require("aeotec-smart-switch.can_handle")
148121
}
149122

150123
return aeotec_smart_switch

drivers/SmartThings/zwave-switch/src/configurations.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 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
143

154
local devices = {
165
AEOTEC_METERING_SWITCH = {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
5+
--- Determine whether the passed device is Dawon smart plug
6+
---
7+
--- @param driver Driver driver instance
8+
--- @param device Device device isntance
9+
--- @return boolean true if the device proper, else false
10+
local function can_handle_dawon_smart_plug(opts, driver, device, ...)
11+
local fingerprints = {
12+
{mfr = 0x018C, prod = 0x0042, model = 0x0005}, -- Dawon Smart Plug
13+
{mfr = 0x018C, prod = 0x0042, model = 0x0008} -- Dawon Smart Multitab
14+
}
15+
for _, fingerprint in ipairs(fingerprints) do
16+
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
17+
local subdriver = require("dawon-smart-plug")
18+
return true, subdriver
19+
end
20+
end
21+
return false
22+
end
23+
24+
return can_handle_dawon_smart_plug
Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,13 @@
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 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
143

154
local capabilities = require "st.capabilities"
165
--- @type st.zwave.CommandClass
176
local cc = require "st.zwave.CommandClass"
187
--- @type st.zwave.CommandClass.Notification
198
local Notification = (require "st.zwave.CommandClass.Notification")({ version = 3 })
209

21-
local DAWON_SMART_PLUG_FINGERPRINTS = {
22-
{mfr = 0x018C, prod = 0x0042, model = 0x0005}, -- Dawon Smart Plug
23-
{mfr = 0x018C, prod = 0x0042, model = 0x0008} -- Dawon Smart Multitab
24-
}
2510

26-
--- Determine whether the passed device is Dawon smart plug
27-
---
28-
--- @param driver Driver driver instance
29-
--- @param device Device device isntance
30-
--- @return boolean true if the device proper, else false
31-
local function can_handle_dawon_smart_plug(opts, driver, device, ...)
32-
for _, fingerprint in ipairs(DAWON_SMART_PLUG_FINGERPRINTS) do
33-
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
34-
local subdriver = require("dawon-smart-plug")
35-
return true, subdriver
36-
end
37-
end
38-
return false
39-
end
4011

4112
--- Default handler for notification reports
4213
---
@@ -60,7 +31,7 @@ local dawon_smart_plug = {
6031
[Notification.REPORT] = notification_report_handler
6132
}
6233
},
63-
can_handle = can_handle_dawon_smart_plug
34+
can_handle = require("dawon-smart-plug.can_handle")
6435
}
6536

6637
return dawon_smart_plug
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
5+
--- Determine whether the passed device is Dawon wall smart switch
6+
---
7+
--- @param driver Driver driver instance
8+
--- @param device Device device isntance
9+
--- @return boolean true if the device proper, else false
10+
local function can_handle_dawon_wall_smart_switch(opts, driver, device, ...)
11+
local fingerprints = require("dawon-wall-smart-switch.fingerprints")
12+
for _, fingerprint in ipairs(fingerprints) do
13+
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
14+
local subdriver = require("dawon-wall-smart-switch")
15+
return true, subdriver
16+
end
17+
end
18+
return false
19+
end
20+
21+
return can_handle_dawon_wall_smart_switch

0 commit comments

Comments
 (0)