Skip to content

Commit 0ca3a93

Browse files
committed
CHAD-17077: zigbee-thermostat lazy load subdrivers
1 parent 246a4c3 commit 0ca3a93

Some content is hidden

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

55 files changed

+394
-512
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 is_aqara_products(opts, driver, device)
5+
local FINGERPRINTS = require("aqara.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("aqara")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return is_aqara_products
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 FINGERPRINTS = {
5+
{ mfr = "LUMI", model = "lumi.airrtc.agl001" }
6+
}
7+
8+
return FINGERPRINTS

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

Lines changed: 5 additions & 26 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
local data_types = require "st.zigbee.data_types"
155
local clusters = require "st.zigbee.zcl.clusters"
166
local cluster_base = require "st.zigbee.cluster_base"
@@ -34,9 +24,6 @@ local PRIVATE_ANTIFREEZE_MODE_TEMPERATURE_SETTING_ID = 0x0279
3424
local PRIVATE_VALVE_RESULT_CALIBRATION_ID = 0x027B
3525
local PRIVATE_BATTERY_ENERGY_ID = 0x040A
3626

37-
local FINGERPRINTS = {
38-
{ mfr = "LUMI", model = "lumi.airrtc.agl001" }
39-
}
4027

4128
local preference_map = {
4229
["stse.notificationOfValveTest"] = {
@@ -82,14 +69,6 @@ local function device_info_changed(driver, device, event, args)
8269
end
8370
end
8471

85-
local function is_aqara_products(opts, driver, device)
86-
for _, fingerprint in ipairs(FINGERPRINTS) do
87-
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
88-
return true
89-
end
90-
end
91-
return false
92-
end
9372

9473
local function supported_thermostat_modes_handler(driver, device, value)
9574
device:emit_event(capabilities.thermostatMode.supportedThermostatModes({
@@ -277,7 +256,7 @@ local aqara_radiator_thermostat_e1_handler = {
277256
[capabilities.refresh.commands.refresh.NAME] = do_refresh,
278257
}
279258
},
280-
can_handle = is_aqara_products
259+
can_handle = require("aqara.can_handle"),
281260
}
282261

283-
return aqara_radiator_thermostat_e1_handler
262+
return aqara_radiator_thermostat_e1_handler
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 is_danfoss_thermostat = function(opts, driver, device)
5+
local FINGERPRINTS = require("danfoss.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("danfoss")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return is_danfoss_thermostat
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 DANFOSS_THERMOSTAT_FINGERPRINTS = {
5+
{ mfr = "Danfoss", model = "eTRV0100" }
6+
}
7+
8+
return DANFOSS_THERMOSTAT_FINGERPRINTS
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
14
local clusters = require "st.zigbee.zcl.clusters"
25
local battery_defaults = require "st.zigbee.defaults.battery_defaults"
36
local PowerConfiguration = clusters.PowerConfiguration
47

5-
local DANFOSS_THERMOSTAT_FINGERPRINTS = {
6-
{ mfr = "Danfoss", model = "eTRV0100" }
7-
}
88

9-
local is_danfoss_thermostat = function(opts, driver, device)
10-
for _, fingerprint in ipairs(DANFOSS_THERMOSTAT_FINGERPRINTS) do
11-
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
12-
return true
13-
end
14-
end
15-
return false
16-
end
179

1810
local danfoss_thermostat = {
1911
NAME = "Danfoss Thermostat Handler",
@@ -27,7 +19,7 @@ local danfoss_thermostat = {
2719
lifecycle_handlers = {
2820
init = battery_defaults.build_linear_voltage_init(2.4, 3.2)
2921
},
30-
can_handle = is_danfoss_thermostat
22+
can_handle = require("danfoss.can_handle"),
3123
}
3224

33-
return danfoss_thermostat
25+
return danfoss_thermostat
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 fidure_can_handle(opts, driver, device, ...)
5+
if device:get_manufacturer() == "Fidure" and device:get_model() == "A1732R3" then
6+
return true, require("fidure")
7+
end
8+
return false
9+
end
10+
11+
return fidure_can_handle

drivers/SmartThings/zigbee-thermostat/src/fidure/init.lua

Lines changed: 4 additions & 16 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 device_management = require "st.zigbee.device_management"
166

@@ -38,9 +28,7 @@ local fidure_thermostat = {
3828
}
3929
}
4030
},
41-
can_handle = function(opts, driver, device, ...)
42-
return device:get_manufacturer() == "Fidure" and device:get_model() == "A1732R3"
43-
end
31+
can_handle = require("fidure.can_handle"),
4432
}
4533

4634
return fidure_thermostat

drivers/SmartThings/zigbee-thermostat/src/init.lua

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

155
-- Zigbee Driver utilities
166
local ZigbeeDriver = require "st.zigbee"
@@ -362,20 +352,7 @@ local zigbee_thermostat_driver = {
362352
doConfigure = do_configure,
363353
added = device_added
364354
},
365-
sub_drivers = {
366-
require("zenwithin"),
367-
require("fidure"),
368-
require("sinope"),
369-
require("stelpro-ki-zigbee-thermostat"),
370-
require("stelpro"),
371-
require("lux-konoz"),
372-
require("leviton"),
373-
require("danfoss"),
374-
require("popp"),
375-
require("vimar"),
376-
require("resideo_korea"),
377-
require("aqara")
378-
},
355+
sub_drivers = require("sub_drivers"),
379356
health_check = false,
380357
}
381358

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

0 commit comments

Comments
 (0)