Skip to content

Commit 928d2bf

Browse files
authored
Merge pull request #2642 from SmartThingsCommunity/zwave-fan-lazy-load-subdrivers
CHAD-17087: zwave-fan lazy lading of sub-drivers
2 parents e80a937 + e8abbc0 commit 928d2bf

12 files changed

Lines changed: 99 additions & 110 deletions

File tree

drivers/SmartThings/zwave-fan/src/init.lua

Lines changed: 5 additions & 17 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
@@ -27,10 +17,8 @@ local driver_template = {
2717
capabilities.switch,
2818
capabilities.fanSpeed,
2919
},
30-
sub_drivers = {
31-
require("zwave-fan-3-speed"),
32-
require("zwave-fan-4-speed")
33-
},
20+
sub_drivers = require("sub_drivers"),
21+
shared_device_thread_enabled = true,
3422
}
3523

3624
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: 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 lazy_load_if_possible = require "lazy_load_subdriver"
5+
local sub_drivers = {
6+
lazy_load_if_possible("zwave-fan-3-speed"),
7+
lazy_load_if_possible("zwave-fan-4-speed"),
8+
}
9+
return sub_drivers

drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_3_speed.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"

drivers/SmartThings/zwave-fan/src/test/test_zwave_fan_4_speed.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"
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_fan_3_speed(opts, driver, device, ...)
5+
local FINGERPRINTS = require("zwave-fan-3-speed.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
8+
return true, require("zwave-fan-3-speed")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return is_fan_3_speed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Copyright 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
local FAN_3_SPEED_FINGERPRINTS = {
5+
{mfr = 0x001D, prod = 0x1001, model = 0x0334}, -- Leviton 3-Speed Fan Controller
6+
{mfr = 0x0063, prod = 0x4944, model = 0x3034}, -- GE In-Wall Smart Fan Control
7+
{mfr = 0x0063, prod = 0x4944, model = 0x3131}, -- GE In-Wall Smart Fan Control
8+
{mfr = 0x0039, prod = 0x4944, model = 0x3131}, -- Honeywell Z-Wave Plus In-Wall Fan Speed Control
9+
{mfr = 0x0063, prod = 0x4944, model = 0x3337}, -- GE In-Wall Smart Fan Control
10+
}
11+
12+
return FAN_3_SPEED_FINGERPRINTS

drivers/SmartThings/zwave-fan/src/zwave-fan-3-speed/init.lua

Lines changed: 5 additions & 29 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 log = require "log"
166
local capabilities = require "st.capabilities"
@@ -22,13 +12,6 @@ local Basic = (require "st.zwave.CommandClass.Basic")({ version=1 })
2212
local SwitchMultilevel = (require "st.zwave.CommandClass.SwitchMultilevel")({ version=4 })
2313
local fan_speed_helper = (require "zwave_fan_helpers")
2414

25-
local FAN_3_SPEED_FINGERPRINTS = {
26-
{mfr = 0x001D, prod = 0x1001, model = 0x0334}, -- Leviton 3-Speed Fan Controller
27-
{mfr = 0x0063, prod = 0x4944, model = 0x3034}, -- GE In-Wall Smart Fan Control
28-
{mfr = 0x0063, prod = 0x4944, model = 0x3131}, -- GE In-Wall Smart Fan Control
29-
{mfr = 0x0039, prod = 0x4944, model = 0x3131}, -- Honeywell Z-Wave Plus In-Wall Fan Speed Control
30-
{mfr = 0x0063, prod = 0x4944, model = 0x3337}, -- GE In-Wall Smart Fan Control
31-
}
3215

3316
local function map_fan_3_speed_to_switch_level (speed)
3417
if speed == fan_speed_helper.fan_speed.OFF then
@@ -63,14 +46,6 @@ end
6346
--- @param driver st.zwave.Driver
6447
--- @param device st.zwave.Device
6548
--- @return boolean true if the device is an 3-speed fan, else false
66-
local function is_fan_3_speed(opts, driver, device, ...)
67-
for _, fingerprint in ipairs(FAN_3_SPEED_FINGERPRINTS) do
68-
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
69-
return true
70-
end
71-
end
72-
return false
73-
end
7449

7550
local capability_handlers = {}
7651

@@ -110,7 +85,8 @@ local zwave_fan_3_speed = {
11085
}
11186
},
11287
NAME = "Z-Wave fan 3 speed",
113-
can_handle = is_fan_3_speed,
88+
can_handle = require("zwave-fan-3-speed.can_handle"),
89+
shared_device_thread_enabled = true,
11490
}
11591

11692
return zwave_fan_3_speed
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_fan_4_speed(opts, driver, device, ...)
5+
local FINGERPRINTS = require("zwave-fan-4-speed.fingerprints")
6+
for _, fingerprint in ipairs(FINGERPRINTS) do
7+
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
8+
return true, require("zwave-fan-4-speed")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return can_handle_fan_4_speed
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 FAN_4_SPEED_FINGERPRINTS = {
5+
{mfr = 0x001D, prod = 0x0038, model = 0x0002}, -- Leviton 4-Speed Fan Controller
6+
}
7+
8+
return FAN_4_SPEED_FINGERPRINTS

0 commit comments

Comments
 (0)