Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy load zwave switch sub drivers #921

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ local POWER_UNIT_WATT = "W"
local function can_handle_aeon_smart_strip(opts, driver, device, ...)
for _, fingerprint in ipairs(AEON_SMART_STRIP_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("aeon-smart-strip")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ local FINGERPRINTS = {

local function can_handle(opts, driver, device, ...)
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:id_match(fingerprint.mfr, nil, fingerprint.prodId) then return true end
if device:id_match(fingerprint.mfr, nil, fingerprint.prodId) then
local subdriver = require("aeotec-smart-switch")
return true, subdriver
end
end
return false
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ local DAWON_SMART_PLUG_FINGERPRINTS = {
local function can_handle_dawon_smart_plug(opts, driver, device, ...)
for _, fingerprint in ipairs(DAWON_SMART_PLUG_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("dawon-smart-plug")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ local DAWON_WALL_SMART_SWITCH_FINGERPRINTS = {
local function can_handle_dawon_wall_smart_switch(opts, driver, device, ...)
for _, fingerprint in ipairs(DAWON_WALL_SMART_SWITCH_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("dawon-wall-smart-switch")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ end
local function can_handle_eaton_5_scene_keypad(opts, driver, device, ...)
for _, fingerprint in ipairs(EATON_5_SCENE_KEYPAD_FINGERPRINT) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("eaton-5-scene-keypad")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ local EATON_ACCESSORY_DIMMER_FINGERPRINTS = {
local function can_handle_eaton_accessory_dimmer(opts, driver, device, ...)
for _, fingerprint in ipairs(EATON_ACCESSORY_DIMMER_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("eaton-accessory-dimmer")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ local EATON_ANYPLACE_SWITCH_FINGERPRINTS = {
local function can_handle_eaton_anyplace_switch(opts, driver, device, ...)
for _, fingerprint in ipairs(EATON_ANYPLACE_SWITCH_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
return true
local subdriver = require("eaton-anyplace-switch")
return true, subdriver
end
end
return false
Expand Down
3 changes: 2 additions & 1 deletion drivers/SmartThings/zwave-switch/src/ecolink-switch/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ local ECOLINK_FINGERPRINTS = {
local function can_handle_ecolink(opts, driver, device, ...)
for _, fingerprint in ipairs(ECOLINK_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("ecolink-switch")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ local FIBARO_DOUBLE_SWITCH_FINGERPRINTS = {
local function can_handle_fibaro_double_switch(opts, driver, device, ...)
for _, fingerprint in ipairs(FIBARO_DOUBLE_SWITCH_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("fibaro-double-switch")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ local FIBARO_SINGLE_SWITCH_FINGERPRINTS = {
local function can_handle_fibaro_single_switch(opts, driver, device, ...)
for _, fingerprint in ipairs(FIBARO_SINGLE_SWITCH_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("fibaro-single-switch")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ local FIBARO_WALL_PLUG_FINGERPRINTS = {
local function can_handle_fibaro_wall_plug(opts, driver, device, ...)
for _, fingerprint in ipairs(FIBARO_WALL_PLUG_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("fibaro-wall-plug-us")
return true, subdriver
end
end
return false
Expand Down
39 changes: 20 additions & 19 deletions drivers/SmartThings/zwave-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local defaults = require "st.zwave.defaults"
local st_device = require "st.device"
--- @type st.zwave.Driver
local ZwaveDriver = require "st.zwave.driver"
local Driver = require "st.driver"
--- @type st.zwave.CommandClass
local cc = require "st.zwave.CommandClass"
--- @type st.zwave.CommandClass.Configuration
Expand Down Expand Up @@ -130,25 +131,25 @@ local driver_template = {
}
},
sub_drivers = {
require("eaton-accessory-dimmer"),
require("inovelli-LED"),
require("dawon-smart-plug"),
require("inovelli-2-channel-smart-plug"),
require("zwave-dual-switch"),
require("eaton-anyplace-switch"),
require("fibaro-wall-plug-us"),
require("dawon-wall-smart-switch"),
require("zooz-power-strip"),
require("aeon-smart-strip"),
require("qubino-switches"),
require("fibaro-double-switch"),
require("fibaro-single-switch"),
require("eaton-5-scene-keypad"),
require("ecolink-switch"),
require("multi-metering-switch"),
require("zooz-zen-30-dimmer-relay"),
require("multichannel-device"),
require("aeotec-smart-switch")
ZwaveDriver.lazy_load_sub_driver(require("eaton-accessory-dimmer")),
ZwaveDriver.lazy_load_sub_driver(require("inovelli-LED")),
ZwaveDriver.lazy_load_sub_driver(require("dawon-smart-plug")),
ZwaveDriver.lazy_load_sub_driver(require("inovelli-2-channel-smart-plug")),
ZwaveDriver.lazy_load_sub_driver(require("zwave-dual-switch")),
ZwaveDriver.lazy_load_sub_driver(require("eaton-anyplace-switch")),
ZwaveDriver.lazy_load_sub_driver(require("fibaro-wall-plug-us")),
ZwaveDriver.lazy_load_sub_driver(require("dawon-wall-smart-switch")),
ZwaveDriver.lazy_load_sub_driver(require("zooz-power-strip")),
ZwaveDriver.lazy_load_sub_driver(require("aeon-smart-strip")),
ZwaveDriver.lazy_load_sub_driver(require("qubino-switches")),
ZwaveDriver.lazy_load_sub_driver(require("fibaro-double-switch")),
ZwaveDriver.lazy_load_sub_driver(require("fibaro-single-switch")),
ZwaveDriver.lazy_load_sub_driver(require("eaton-5-scene-keypad")),
ZwaveDriver.lazy_load_sub_driver(require("ecolink-switch")),
ZwaveDriver.lazy_load_sub_driver(require("multi-metering-switch")),
ZwaveDriver.lazy_load_sub_driver(require("zooz-zen-30-dimmer-relay")),
ZwaveDriver.lazy_load_sub_driver(require("multichannel-device")),
ZwaveDriver.lazy_load_sub_driver(require("aeotec-smart-switch"))
},
lifecycle_handlers = {
init = device_init,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ local INOVELLI_2_CHANNEL_SMART_PLUG_FINGERPRINTS = {
local function can_handle_inovelli_2_channel_smart_plug(opts, driver, device, ...)
for _, fingerprint in ipairs(INOVELLI_2_CHANNEL_SMART_PLUG_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("inovelli-2-channel-smart-plug")
return true, subdriver
end
end
return false
Expand Down
3 changes: 2 additions & 1 deletion drivers/SmartThings/zwave-switch/src/inovelli-LED/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ local function can_handle_inovelli_led(opts, driver, device, ...)
{INOVELLI_LZW31SN_PRODUCT_TYPE, INOVELLI_LZW31_PRODUCT_TYPE},
INOVELLI_DIMMER_PRODUCT_ID
) then
return true
local subdriver = require("inovelli-LED")
return true, subdriver
end
return false
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ local MULTI_METERING_SWITCH_FINGERPRINTS = {
local function can_handle_multi_metering_switch(opts, driver, device, ...)
for _, fingerprint in ipairs(MULTI_METERING_SWITCH_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("multi-metering-switch")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ local map_device_class_to_profile = {
}

local function can_handle_multichannel_device(opts, driver, device, ...)
return device:supports_capability(capabilities.zwMultichannel)
if device:supports_capability(capabilities.zwMultichannel) then
local subdriver = require("multichannel-device")
return true, subdriver
end
return false
end

local function find_child(device, src_channel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ local function getDeviceProfile(device, isTemperatureSensorOnboard)
end

local function can_handle_qubino_flush_relay(opts, driver, device, cmd, ...)
return device:id_match(constants.QUBINO_MFR)
if device:id_match(constants.QUBINO_MFR) then
local subdriver = require("qubino-switches")
return true, subdriver
end
return false
end

local function add_temperature_sensor_if_needed(device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ local ZOOZ_POWER_STRIP_FINGERPRINTS = {
local function can_handle_zooz_power_strip(opts, driver, device, ...)
for _, fingerprint in ipairs(ZOOZ_POWER_STRIP_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("zooz-power-strip")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ local ZOOZ_ZEN_30_DIMMER_RELAY_FINGERPRINTS = {
local function can_handle_zooz_zen_30_dimmer_relay_double_switch(opts, driver, device, ...)
for _, fingerprint in ipairs(ZOOZ_ZEN_30_DIMMER_RELAY_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("zooz-zen-30-dimmer-relay")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ local ZWAVE_DUAL_SWITCH_FINGERPRINTS = {
local function can_handle_zwave_dual_switch(opts, driver, device, ...)
for _, fingerprint in ipairs(ZWAVE_DUAL_SWITCH_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("zwave-dual-switch")
return true, subdriver
end
end
return false
Expand Down
Loading