Skip to content

Commit 7c0c6e2

Browse files
committed
CHAD-17094: zwave-smoke-alarm lazy loading of sub-drivers
1 parent 2c7d3f5 commit 7c0c6e2

File tree

23 files changed

+175
-212
lines changed

23 files changed

+175
-212
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local function can_handle(opts, driver, device, cmd, ...)
5+
local version = require "version"
6+
return version.api == 6 and
7+
cmd.cmd_class == cc.WAKE_UP and
8+
cmd.cmd_id == WakeUp.NOTIFICATION
9+
end
10+
11+
return can_handle
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
14
local cc = require "st.zwave.CommandClass"
25
local WakeUp = (require "st.zwave.CommandClass.WakeUp")({ version = 1 })
36

47

5-
local function can_handle(opts, driver, device, cmd, ...)
6-
local version = require "version"
7-
return version.api == 6 and
8-
cmd.cmd_class == cc.WAKE_UP and
9-
cmd.cmd_id == WakeUp.NOTIFICATION
10-
end
118

129
local function wakeup_notification(driver, device, cmd)
1310
device:refresh()
@@ -20,7 +17,7 @@ local apiv6_bugfix = {
2017
}
2118
},
2219
NAME = "apiv6_bugfix",
23-
can_handle = can_handle
20+
can_handle = require("apiv6_bugfix.can_handle"),
2421
}
2522

2623
return apiv6_bugfix
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_fibaro_smoke_sensor(opts, driver, device, cmd, ...)
5+
local FINGERPRINTS = require("fibaro-smoke-sensor.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:id_match( fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
8+
return true, require("fibaro-smoke-sensor")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return can_handle_fibaro_smoke_sensor
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local FIBARO_SMOKE_SENSOR_FINGERPRINTS = {
5+
{ manufacturerId = 0x010F, productType = 0x0C02, productId = 0x1002 }, -- Fibaro Smoke Sensor
6+
{ manufacturerId = 0x010F, productType = 0x0C02, productId = 0x1003 }, -- Fibaro Smoke Sensor
7+
{ manufacturerId = 0x010F, productType = 0x0C02, productId = 0x3002 }, -- Fibaro Smoke Sensor
8+
{ manufacturerId = 0x010F, productType = 0x0C02, productId = 0x4002 } -- Fibaro Smoke Sensor
9+
}
10+
11+
return FIBARO_SMOKE_SENSOR_FINGERPRINTS

drivers/SmartThings/zwave-smoke-alarm/src/fibaro-smoke-sensor/init.lua

Lines changed: 4 additions & 28 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
--- @type st.zwave.CommandClass
@@ -24,26 +14,12 @@ local WakeUp = (require "st.zwave.CommandClass.WakeUp")({version=1})
2414

2515
local FIBARO_SMOKE_SENSOR_WAKEUP_INTERVAL = 21600 --seconds
2616

27-
local FIBARO_SMOKE_SENSOR_FINGERPRINTS = {
28-
{ manufacturerId = 0x010F, productType = 0x0C02, productId = 0x1002 }, -- Fibaro Smoke Sensor
29-
{ manufacturerId = 0x010F, productType = 0x0C02, productId = 0x1003 }, -- Fibaro Smoke Sensor
30-
{ manufacturerId = 0x010F, productType = 0x0C02, productId = 0x3002 }, -- Fibaro Smoke Sensor
31-
{ manufacturerId = 0x010F, productType = 0x0C02, productId = 0x4002 } -- Fibaro Smoke Sensor
32-
}
3317

3418
--- Determine whether the passed device is fibaro smoke sensro
3519
---
3620
--- @param driver st.zwave.Driver
3721
--- @param device st.zwave.Device
3822
--- @return boolean true if the device is fibaro smoke sensor
39-
local function can_handle_fibaro_smoke_sensor(opts, driver, device, cmd, ...)
40-
for _, fingerprint in ipairs(FIBARO_SMOKE_SENSOR_FINGERPRINTS) do
41-
if device:id_match( fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
42-
return true
43-
end
44-
end
45-
return false
46-
end
4723

4824
local function device_added(self, device)
4925
device:send(WakeUp:IntervalSet({node_id = self.environment_info.hub_zwave_id, seconds = FIBARO_SMOKE_SENSOR_WAKEUP_INTERVAL}))
@@ -76,7 +52,7 @@ local fibaro_smoke_sensor = {
7652
added = device_added
7753
},
7854
NAME = "fibaro smoke sensor",
79-
can_handle = can_handle_fibaro_smoke_sensor,
55+
can_handle = require("fibaro-smoke-sensor.can_handle"),
8056
health_check = false,
8157
}
8258

drivers/SmartThings/zwave-smoke-alarm/src/init.lua

Lines changed: 4 additions & 19 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
--- @type st.zwave.CommandClass
@@ -83,12 +73,7 @@ local driver_template = {
8373
capabilities.temperatureAlarm,
8474
capabilities.temperatureMeasurement
8575
},
86-
sub_drivers = {
87-
require("zwave-smoke-co-alarm-v1"),
88-
require("zwave-smoke-co-alarm-v2"),
89-
require("fibaro-smoke-sensor"),
90-
require("apiv6_bugfix"),
91-
},
76+
sub_drivers = require("sub_drivers"),
9277
lifecycle_handlers = {
9378
init = device_init,
9479
infoChanged = info_changed,
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+
5+
return function(sub_driver_name)
6+
-- gets the current lua libs api version
7+
local ZwaveDriver = require "st.zwave.driver"
8+
local version = require "version"
9+
10+
if version.api >= 16 then
11+
return ZwaveDriver.lazy_load_sub_driver_v2(sub_driver_name)
12+
elseif version.api >= 9 then
13+
return ZwaveDriver.lazy_load_sub_driver(require(sub_driver_name))
14+
else
15+
return require(sub_driver_name)
16+
end
17+
18+
end

drivers/SmartThings/zwave-smoke-alarm/src/preferences.lua

Lines changed: 3 additions & 13 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 devices = {
166
FIBARO = {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local lazy_load_if_possible = require "lazy_load_subdriver"
5+
local sub_drivers = {
6+
lazy_load_if_possible("zwave-smoke-co-alarm-v1"),
7+
lazy_load_if_possible("zwave-smoke-co-alarm-v2"),
8+
lazy_load_if_possible("fibaro-smoke-sensor"),
9+
lazy_load_if_possible("apiv6_bugfix"),
10+
}
11+
return sub_drivers

drivers/SmartThings/zwave-smoke-alarm/src/test/test_fibaro_co_sensor_zw5.lua

Lines changed: 3 additions & 13 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 test = require "integration_test"
166
local capabilities = require "st.capabilities"

0 commit comments

Comments
 (0)