Skip to content

CHAD-12900 Lazy load for z-wave sensor #2215

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -26,7 +26,8 @@ local AEOTEC_MULTISENSOR_FINGERPRINTS = {
local function can_handle_aeotec_multisensor(opts, self, device, ...)
for _, fingerprint in ipairs(AEOTEC_MULTISENSOR_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
return true
local subdriver = require("aeotec-multisensor")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ local ZWAVE_WATER_TEMP_HUMIDITY_FINGERPRINTS = {
}

--- Determine whether the passed device is zwave water temperature humidiry sensor
---
--- @param driver Driver driver instance
--- @param device Device device isntance
--- @return boolean true if the device proper, else false
local function can_handle_zwave_water_temp_humidity_sensor(opts, driver, device, ...)
for _, fingerprint in ipairs(ZWAVE_WATER_TEMP_HUMIDITY_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
return true
local subdriver = require("aeotec-water-sensor")
return true, subdriver
end
end
return false
Expand Down
3 changes: 2 additions & 1 deletion drivers/SmartThings/zwave-sensor/src/apiv6_bugfix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ local function can_handle(opts, driver, device, cmd, ...)
for _, fp in ipairs(FPS) do
if device:id_match(fp.mfr, fp.prod, fp.model) then return false end
end
return true
local subdriver = require("apiv6_bugfix")
return true, subdriver
else
return false
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ local WakeUp = (require "st.zwave.CommandClass.WakeUp")({version=1})
local ENERWAVE_MFR = 0x011A

local function can_handle_enerwave_motion_sensor(opts, driver, device, cmd, ...)
return device.zwave_manufacturer_id == ENERWAVE_MFR
if device.zwave_manufacturer_id == ENERWAVE_MFR then
local subdriver = require("enerwave-motion-sensor")
return true, subdriver
else return false end
end

local function wakeup_notification(driver, device, cmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ local SensorBinary = (require "st.zwave.CommandClass.SensorBinary")({version=2})
local EVERSPRING_MOTION_LIGHT_FINGERPRINT = { mfr = 0x0060, prod = 0x0012, model = 0x0001 }

local function can_handle_everspring_motion_light(opts, driver, device, ...)
return device:id_match(
if device:id_match(
EVERSPRING_MOTION_LIGHT_FINGERPRINT.mfr,
EVERSPRING_MOTION_LIGHT_FINGERPRINT.prod,
EVERSPRING_MOTION_LIGHT_FINGERPRINT.model
)
) then
local subdriver = require("everspring-motion-light-sensor")
return true, subdriver
else return false end
end

local function device_added(driver, device)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ local SwitchBinary = (require "st.zwave.CommandClass.SwitchBinary")({version=2})

local CAP_CACHE_KEY = "st.capabilities." .. capabilities.colorControl.ID

local EZMULTIPLI_MULTIPURPOSE_SENSOR_FINGERPRINTS = {
{ manufacturerId = 0x001E, productType = 0x0004, productId = 0x0001 }
}
local EZMULTIPLI_MULTIPURPOSE_SENSOR_FINGERPRINTS = { manufacturerId = 0x001E, productType = 0x0004, productId = 0x0001 }

local function can_handle_ezmultipli_multipurpose_sensor(opts, driver, device, ...)
for _, fingerprint in ipairs(EZMULTIPLI_MULTIPURPOSE_SENSOR_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
return true
end
end
return false
if device:id_match(EZMULTIPLI_MULTIPURPOSE_SENSOR_FINGERPRINTS.manufacturerId,
EZMULTIPLI_MULTIPURPOSE_SENSOR_FINGERPRINTS.productType,
EZMULTIPLI_MULTIPURPOSE_SENSOR_FINGERPRINTS.productId) then
local subdriver = require("ezmultipli-multipurpose-sensor")
return true, subdriver
else return false end
end

local function basic_report_handler(driver, device, cmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ local FIBARO_DOOR_WINDOW_SENSOR_FINGERPRINTS = {
local function can_handle_fibaro_door_window_sensor(opts, driver, device, ...)
for _, fingerprint in ipairs(FIBARO_DOOR_WINDOW_SENSOR_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.prod, fingerprint.productId) then
return true
local subdriver = require("fibaro-door-window-sensor")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ local FIBARO_MFR_ID = 0x010F
local FIBARO_FLOOD_PROD_TYPES = { 0x0000, 0x0B00 }

local function can_handle_fibaro_flood_sensor(opts, driver, device, ...)
return device:id_match(FIBARO_MFR_ID, FIBARO_FLOOD_PROD_TYPES, nil)
if device:id_match(FIBARO_MFR_ID, FIBARO_FLOOD_PROD_TYPES, nil) then
local subdriver = require("fibaro-flood-sensor")
return true, subdriver
else return false end
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ local FIBARO_MOTION_MFR = 0x010F
local FIBARO_MOTION_PROD = 0x0800

local function can_handle_fibaro_motion_sensor(opts, driver, device, ...)
return device:id_match(FIBARO_MOTION_MFR, FIBARO_MOTION_PROD)
if device:id_match(FIBARO_MOTION_MFR, FIBARO_MOTION_PROD) then
local subdriver = require("fibaro-motion-sensor")
return true, subdriver
else return false end
end

local function sensor_alarm_report(driver, device, cmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ local cc = require "st.zwave.CommandClass"
--- @type st.zwave.CommandClass.Notification
local Notification = (require "st.zwave.CommandClass.Notification")({ version = 3 })

local GLENTRONICS_WATER_LEAK_SENSOR_FINGERPRINTS = {
{ manufacturerId = 0x0084, productType = 0x0093, productId = 0x0114 } -- glentronics water leak sensor
}
local GLENTRONICS_WATER_LEAK_SENSOR_FINGERPRINTS = { manufacturerId = 0x0084, productType = 0x0093, productId = 0x0114 } -- glentronics water leak sensor

--- Determine whether the passed device is glentronics water leak sensor
---
--- @param driver Driver driver instance
--- @param device Device device isntance
--- @return boolean true if the device proper, else false
local function can_handle_glentronics_water_leak_sensor(opts, driver, device, ...)
for _, fingerprint in ipairs(GLENTRONICS_WATER_LEAK_SENSOR_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
return true
end
end
return false
if device:id_match(
GLENTRONICS_WATER_LEAK_SENSOR_FINGERPRINTS.manufacturerId,
GLENTRONICS_WATER_LEAK_SENSOR_FINGERPRINTS.productType,
GLENTRONICS_WATER_LEAK_SENSOR_FINGERPRINTS.productId) then
local subdriver = require("glentronics-water-leak-sensor")
return true, subdriver
else return false end
end

local function notification_report_handler(self, device, cmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@ local WakeUp = (require "st.zwave.CommandClass.WakeUp")({ version = 1 })
local SensorMultilevel = (require "st.zwave.CommandClass.SensorMultilevel")({version = 5})
local Battery = (require "st.zwave.CommandClass.Battery")({ version = 1})

local HOMESEER_MULTI_SENSOR_FINGERPRINTS = {
{ manufacturerId = 0x001E, productType = 0x0002, productId = 0x0001 }, -- Homeseer multi sensor HSM100
}
local HOMESEER_MULTI_SENSOR_FINGERPRINTS = { manufacturerId = 0x001E, productType = 0x0002, productId = 0x0001 } -- Homeseer multi sensor HSM100

--- Determine whether the passed device is homeseer multi sensor
---
--- @param driver Driver driver instance
--- @param device Device device instance
--- @return boolean true if the device proper, else false
local function can_handle_homeseer_multi_sensor(opts, driver, device, ...)
for _, fingerprint in ipairs(HOMESEER_MULTI_SENSOR_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
return true
end
end
return false
if device:id_match(
HOMESEER_MULTI_SENSOR_FINGERPRINTS.manufacturerId,
HOMESEER_MULTI_SENSOR_FINGERPRINTS.productType,
HOMESEER_MULTI_SENSOR_FINGERPRINTS.productId) then
local subdriver = require("homeseer-multi-sensor")
return true, subdriver
else return false end
end

local function basic_set_handler(self, device, cmd)
Expand Down
49 changes: 31 additions & 18 deletions drivers/SmartThings/zwave-sensor/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ local WakeUp = (require "st.zwave.CommandClass.WakeUp")({ version = 1 })
local preferences = require "preferences"
local configurations = require "configurations"

local function lazy_load_if_possible(sub_driver_name)
-- gets the current lua libs api version
local version = require "version"

-- version 9 will include the lazy loading functions
if version.api >= 9 then
return ZwaveDriver.lazy_load_sub_driver(require(sub_driver_name))
else
return require(sub_driver_name)
end

end

--- Handle preference changes
---
--- @param driver st.zwave.Driver
Expand Down Expand Up @@ -122,24 +135,24 @@ local driver_template = {
capabilities.smokeDetector
},
sub_drivers = {
require("zooz-4-in-1-sensor"),
require("vision-motion-detector"),
require("fibaro-flood-sensor"),
require("aeotec-water-sensor"),
require("glentronics-water-leak-sensor"),
require("homeseer-multi-sensor"),
require("fibaro-door-window-sensor"),
require("sensative-strip"),
require("enerwave-motion-sensor"),
require("aeotec-multisensor"),
require("zwave-water-leak-sensor"),
require("everspring-motion-light-sensor"),
require("ezmultipli-multipurpose-sensor"),
require("fibaro-motion-sensor"),
require("v1-contact-event"),
require("timed-tamper-clear"),
require("wakeup-no-poll"),
require("apiv6_bugfix")
lazy_load_if_possible("zooz-4-in-1-sensor"),
lazy_load_if_possible("vision-motion-detector"),
lazy_load_if_possible("fibaro-flood-sensor"),
lazy_load_if_possible("aeotec-water-sensor"),
lazy_load_if_possible("glentronics-water-leak-sensor"),
lazy_load_if_possible("homeseer-multi-sensor"),
lazy_load_if_possible("fibaro-door-window-sensor"),
lazy_load_if_possible("sensative-strip"),
lazy_load_if_possible("enerwave-motion-sensor"),
lazy_load_if_possible("aeotec-multisensor"),
lazy_load_if_possible("zwave-water-leak-sensor"),
lazy_load_if_possible("everspring-motion-light-sensor"),
lazy_load_if_possible("ezmultipli-multipurpose-sensor"),
lazy_load_if_possible("fibaro-motion-sensor"),
lazy_load_if_possible("v1-contact-event"),
lazy_load_if_possible("timed-tamper-clear"),
lazy_load_if_possible("wakeup-no-poll"),
lazy_load_if_possible("apiv6_bugfix")
},
lifecycle_handlers = {
added = added_handler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ local SENSATIVE_COMFORT_PROFILE = "illuminance-temperature"
local CONFIG_REPORT_RECEIVED = "configReportReceived"

local function can_handle_sensative_strip(opts, driver, device, cmd, ...)
return device:id_match(SENSATIVE_MFR, nil, SENSATIVE_MODEL)
if device:id_match(SENSATIVE_MFR, nil, SENSATIVE_MODEL) then
local subdriver = require("sensative-strip")
return true, subdriver
else return false end
end

local function configuration_report(driver, device, cmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ local TAMPER_CLEAR = 10
local FIBARO_DOOR_WINDOW_MFR_ID = 0x010F

local function can_handle_tamper_event(opts, driver, device, cmd, ...)
return device.zwave_manufacturer_id ~= FIBARO_DOOR_WINDOW_MFR_ID and
if device.zwave_manufacturer_id ~= FIBARO_DOOR_WINDOW_MFR_ID and
opts.dispatcher_class == "ZwaveDispatcher" and
cmd ~= nil and
cmd.cmd_class ~= nil and
cmd.cmd_class == cc.NOTIFICATION and
cmd.cmd_id == Notification.REPORT and
cmd.args.notification_type == Notification.notification_type.HOME_SECURITY and
(cmd.args.event == Notification.event.home_security.TAMPERING_PRODUCT_COVER_REMOVED or
cmd.args.event == Notification.event.home_security.TAMPERING_PRODUCT_MOVED)
cmd.args.event == Notification.event.home_security.TAMPERING_PRODUCT_MOVED) then
local subdriver = require("timed-tamper-clear")
return true, subdriver
else return false
end
end

-- This behavior is from zwave-door-window-sensor.groovy. We've seen this behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ local Notification = (require "st.zwave.CommandClass.Notification")({ version =
local capabilities = require "st.capabilities"

local function can_handle_v1_contact_event(opts, driver, device, cmd, ...)
return opts.dispatcher_class == "ZwaveDispatcher" and
if opts.dispatcher_class == "ZwaveDispatcher" and
cmd ~= nil and
cmd.cmd_class ~= nil and
cmd.cmd_class == cc.NOTIFICATION and
cmd.cmd_id == Notification.REPORT and
cmd.args.notification_type == Notification.notification_type.HOME_SECURITY and
cmd.args.v1_alarm_type == 0x07
cmd.args.v1_alarm_type == 0x07 then
local subdriver = require("v1-contact-event")
return true, subdriver
else
return false
end
end

-- This behavior is from zwave-door-window-sensor.groovy, where it is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,18 @@ local Configuration = (require "st.zwave.CommandClass.Configuration")({ version
--- @type st.zwave.CommandClass.Notification
local Notification = (require "st.zwave.CommandClass.Notification")({ version = 3 })

local VISION_MOTION_DETECTOR_FINGERPRINTS = {
{ manufacturerId = 0x0109, productType = 0x2002, productId = 0x0205 } -- Vision Motion Detector ZP3102
}
local VISION_MOTION_DETECTOR_FINGERPRINTS = { manufacturerId = 0x0109, productType = 0x2002, productId = 0x0205 } -- Vision Motion Detector ZP3102

--- Determine whether the passed device is zwave-plus-motion-temp-sensor
---
--- @param driver Driver driver instance
--- @param device Device device isntance
--- @return boolean true if the device proper, else false
local function can_handle_vision_motion_detector(opts, driver, device, ...)
for _, fingerprint in ipairs(VISION_MOTION_DETECTOR_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
return true
end
end
return false
if device:id_match(
VISION_MOTION_DETECTOR_FINGERPRINTS.manufacturerId,
VISION_MOTION_DETECTOR_FINGERPRINTS.productType,
VISION_MOTION_DETECTOR_FINGERPRINTS.productId
) then
local subdriver = require("vision-motion-detector")
return true, subdriver
else return false end
end

--- Handler for notification report command class from sensor
Expand Down
7 changes: 6 additions & 1 deletion drivers/SmartThings/zwave-sensor/src/wakeup-no-poll/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ local Battery = (require "st.zwave.CommandClass.Battery")({ version = 1 })
local fingerprint = {manufacturerId = 0x014F, productType = 0x2001, productId = 0x0102} -- NorTek open/close sensor

local function can_handle(opts, driver, device, ...)
return device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId)
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
local subdriver = require("wakeup-no-poll")
return true, subdriver
else
return false
end
end

-- Nortek open/closed sensors _always_ respond with "open" when polled, and they are polled after wakeup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ local ZOOZ_4_IN_1_FINGERPRINTS = {
}

--- Determine whether the passed device is zooz_4_in_1_sensor
---
--- @param driver Driver driver instance
--- @param device Device device isntance
--- @return boolean true if the device proper, else false
local function can_handle_zooz_4_in_1_sensor(opts, driver, device, ...)
for _, fingerprint in ipairs(ZOOZ_4_IN_1_FINGERPRINTS) do
if device:id_match(fingerprint.manufacturerId, fingerprint.productType, fingerprint.productId) then
return true
local subdriver = require("zooz-4-in-1-sensor")
return true, subdriver
end
end
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ local WATER_LEAK_SENSOR_FINGERPRINTS = {
local function can_handle_water_leak_sensor(opts, driver, device, ...)
for _, fingerprint in ipairs(WATER_LEAK_SENSOR_FINGERPRINTS) do
if device:id_match(fingerprint.mfr, fingerprint.prod, fingerprint.model) then
return true
local subdriver = require("zwave-water-leak-sensor")
return true, subdriver
end
end
return false
Expand Down
Loading