Skip to content

Commit 440180b

Browse files
committed
CHAD-17086: zwave-electric-meter lazy loading of sub-drivers
1 parent 2c7d3f5 commit 440180b

File tree

17 files changed

+126
-165
lines changed

17 files changed

+126
-165
lines changed
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_aeon_meter(opts, driver, device, ...)
5+
local FINGERPRINTS = require("aeon-meter.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
8+
return true, require("aeon-meter")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return can_handle_aeon_meter
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 AEON_FINGERPRINTS = {
5+
{mfr = 0x0086, prod = 0x0002, model = 0x0009}, -- DSB09xxx-ZWUS
6+
{mfr = 0x0086, prod = 0x0002, model = 0x0001}, -- DSB28-ZWEU
7+
}
8+
9+
return AEON_FINGERPRINTS
Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
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
--- @type st.zwave.CommandClass.Configuration
165
local Configuration = (require "st.zwave.CommandClass.Configuration")({ version=1 })
176

18-
local AEON_FINGERPRINTS = {
19-
{mfr = 0x0086, prod = 0x0002, model = 0x0009}, -- DSB09xxx-ZWUS
20-
{mfr = 0x0086, prod = 0x0002, model = 0x0001}, -- DSB28-ZWEU
21-
}
22-
23-
local function can_handle_aeon_meter(opts, driver, device, ...)
24-
for _, fingerprint in ipairs(AEON_FINGERPRINTS) do
25-
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
26-
return true
27-
end
28-
end
29-
return false
30-
end
31-
327
local do_configure = function (self, device)
338
device:send(Configuration:Set({parameter_number = 101, size = 4, configuration_value = 4})) -- combined power in watts...
349
device:send(Configuration:Set({parameter_number = 111, size = 4, configuration_value = 300})) -- ...every 5 min
@@ -42,7 +17,7 @@ local aeon_meter = {
4217
doConfigure = do_configure
4318
},
4419
NAME = "aeon meter",
45-
can_handle = can_handle_aeon_meter
20+
can_handle = require("aeon-meter.can_handle"),
4621
}
4722

4823
return aeon_meter
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_aeotec_gen5_meter(opts, driver, device, ...)
5+
local FINGERPRINTS = require("aeotec-gen5-meter.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
8+
return true, require("aeotec-gen5-meter")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return can_handle_aeotec_gen5_meter
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 AEOTEC_GEN5_FINGERPRINTS = {
5+
{mfr = 0x0086, prod = 0x0102, model = 0x005F}, -- Aeotec Home Energy Meter (Gen5) US
6+
{mfr = 0x0086, prod = 0x0002, model = 0x005F}, -- Aeotec Home Energy Meter (Gen5) EU
7+
}
8+
9+
return AEOTEC_GEN5_FINGERPRINTS
Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
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
--- @type st.zwave.CommandClass.Configuration
165
local Configuration = (require "st.zwave.CommandClass.Configuration")({ version=1 })
176

18-
local AEOTEC_GEN5_FINGERPRINTS = {
19-
{mfr = 0x0086, prod = 0x0102, model = 0x005F}, -- Aeotec Home Energy Meter (Gen5) US
20-
{mfr = 0x0086, prod = 0x0002, model = 0x005F}, -- Aeotec Home Energy Meter (Gen5) EU
21-
}
22-
23-
local function can_handle_aeotec_gen5_meter(opts, driver, device, ...)
24-
for _, fingerprint in ipairs(AEOTEC_GEN5_FINGERPRINTS) do
25-
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
26-
return true
27-
end
28-
end
29-
return false
30-
end
31-
327
local do_configure = function (self, device)
338
device:send(Configuration:Set({parameter_number = 101, size = 4, configuration_value = 3})) -- report total power in Watts and total energy in kWh...
349
device:send(Configuration:Set({parameter_number = 102, size = 4, configuration_value = 0})) -- disable group 2...
@@ -43,7 +18,7 @@ local aeotec_gen5_meter = {
4318
doConfigure = do_configure
4419
},
4520
NAME = "aeotec gen5 meter",
46-
can_handle = can_handle_aeotec_gen5_meter
21+
can_handle = require("aeotec-gen5-meter.can_handle"),
4722
}
4823

4924
return aeotec_gen5_meter

drivers/SmartThings/zwave-electric-meter/src/init.lua

Lines changed: 4 additions & 18 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.defaults
@@ -31,11 +21,7 @@ local driver_template = {
3121
lifecycle_handlers = {
3222
added = device_added
3323
},
34-
sub_drivers = {
35-
require("qubino-meter"),
36-
require("aeotec-gen5-meter"),
37-
require("aeon-meter")
38-
}
24+
sub_drivers = require("sub_drivers"),
3925
}
4026

4127
defaults.register_for_default_handlers(driver_template, driver_template.supported_capabilities)
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
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_qubino_meter(opts, driver, device, ...)
5+
local FINGERPRINTS = require("qubino-meter.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
8+
return true, require("qubino-meter")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return can_handle_qubino_meter
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 QUBINO_FINGERPRINTS = {
5+
{mfr = 0x0159, prod = 0x0007, model = 0x0054}, -- Qubino 3 Phase Meter
6+
{mfr = 0x0159, prod = 0x0007, model = 0x0052} -- Qubino Smart Meter
7+
}
8+
9+
return QUBINO_FINGERPRINTS

0 commit comments

Comments
 (0)