Skip to content

Commit 6a4aab5

Browse files
authored
Merge pull request #2577 from SmartThingsCommunity/zigbee-power-meter-lazy-load-subdrivers
CHAD-17041: zigbee-power-meter: lazy loading sub-drivers v2 changes
2 parents afbb8b3 + ea8cbe0 commit 6a4aab5

File tree

12 files changed

+113
-99
lines changed

12 files changed

+113
-99
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local is_ezex_power_meter = function(opts, driver, device)
5+
local FINGERPRINTS = require("ezex.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:get_model() == fingerprint.model then
8+
return true, require("ezex")
9+
end
10+
end
11+
12+
return false
13+
end
14+
15+
return is_ezex_power_meter
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local ZIGBEE_POWER_METER_FINGERPRINTS = {
5+
{ model = "E240-KR080Z0-HA" }
6+
}
7+
8+
return ZIGBEE_POWER_METER_FINGERPRINTS

drivers/SmartThings/zigbee-power-meter/src/ezex/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 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
144

155
local capabilities = require "st.capabilities"
166
local constants = require "st.zigbee.constants"
@@ -20,19 +10,7 @@ local ElectricalMeasurement = clusters.ElectricalMeasurement
2010
local energy_meter_defaults = require "st.zigbee.defaults.energyMeter_defaults"
2111
local configurations = require "configurations"
2212

23-
local ZIGBEE_POWER_METER_FINGERPRINTS = {
24-
{ model = "E240-KR080Z0-HA" }
25-
}
2613

27-
local is_ezex_power_meter = function(opts, driver, device)
28-
for _, fingerprint in ipairs(ZIGBEE_POWER_METER_FINGERPRINTS) do
29-
if device:get_model() == fingerprint.model then
30-
return true
31-
end
32-
end
33-
34-
return false
35-
end
3614

3715
local instantaneous_demand_configuration = {
3816
cluster = SimpleMetering.ID,
@@ -88,7 +66,7 @@ local ezex_power_meter_handler = {
8866
init = configurations.power_reconfig_wrapper(device_init),
8967
doConfigure = do_configure,
9068
},
91-
can_handle = is_ezex_power_meter
69+
can_handle = require("ezex.can_handle"),
9270
}
9371

9472
return ezex_power_meter_handler
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local is_frient_power_meter = function(opts, driver, device)
5+
local FINGERPRINTS = require("frient.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:get_model() == fingerprint.model then
8+
return true, require("frient")
9+
end
10+
end
11+
12+
return false
13+
end
14+
15+
return is_frient_power_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 ZIGBEE_POWER_METER_FINGERPRINTS = {
5+
{ model = "ZHEMI101" },
6+
{ model = "EMIZB-132" },
7+
}
8+
9+
return ZIGBEE_POWER_METER_FINGERPRINTS
Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,11 @@
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
3+
144

155
local constants = require "st.zigbee.constants"
166
local configurations = require "configurations"
177

18-
local ZIGBEE_POWER_METER_FINGERPRINTS = {
19-
{ model = "ZHEMI101" },
20-
{ model = "EMIZB-132" },
21-
}
22-
23-
local is_frient_power_meter = function(opts, driver, device)
24-
for _, fingerprint in ipairs(ZIGBEE_POWER_METER_FINGERPRINTS) do
25-
if device:get_model() == fingerprint.model then
26-
return true
27-
end
28-
end
298

30-
return false
31-
end
329

3310
local do_configure = function(self, device)
3411
device:refresh()
@@ -46,7 +23,7 @@ local frient_power_meter_handler = {
4623
init = configurations.power_reconfig_wrapper(device_init),
4724
doConfigure = do_configure,
4825
},
49-
can_handle = is_frient_power_meter
26+
can_handle = require("frient.can_handle"),
5027
}
5128

5229
return frient_power_meter_handler

drivers/SmartThings/zigbee-power-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 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
144

155
local capabilities = require "st.capabilities"
166
local ZigbeeDriver = require "st.zigbee"
@@ -63,11 +53,7 @@ local zigbee_power_meter_driver_template = {
6353
}
6454
},
6555
current_config_version = 1,
66-
sub_drivers = {
67-
require("ezex"),
68-
require("frient"),
69-
require("shinasystems"),
70-
},
56+
sub_drivers = require("sub_drivers"),
7157
lifecycle_handlers = {
7258
init = configurations.power_reconfig_wrapper(device_init),
7359
doConfigure = do_configure,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
return function(sub_driver_name)
5+
-- gets the current lua libs api version
6+
local version = require "version"
7+
local ZigbeeDriver = require "st.zigbee"
8+
if version.api >= 16 then
9+
return ZigbeeDriver.lazy_load_sub_driver_v2(sub_driver_name)
10+
elseif version.api >= 9 then
11+
return ZigbeeDriver.lazy_load_sub_driver(require(sub_driver_name))
12+
else
13+
return require(sub_driver_name)
14+
end
15+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local is_shinasystems_power_meter = function(opts, driver, device)
5+
local FINGERPRINTS = require("shinasystems.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:get_model() == fingerprint.model then
8+
return true, require("shinasystems")
9+
end
10+
end
11+
12+
return false
13+
end
14+
15+
return is_shinasystems_power_meter
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local ZIGBEE_POWER_METER_FINGERPRINTS = {
5+
{ model = "PMM-300Z1" },
6+
{ model = "PMM-300Z2" },
7+
{ model = "PMM-300Z3" }
8+
}
9+
10+
return ZIGBEE_POWER_METER_FINGERPRINTS

0 commit comments

Comments
 (0)