Skip to content

Commit 282e600

Browse files
committed
zb-motion: Lazy loading of can handle. Developed heavily assisted by scripting.
1 parent f1557c4 commit 282e600

Some content is hidden

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

46 files changed

+369
-183
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 is_aqara_products = function(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: 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 FINGERPRINTS = {
5+
{ mfr = "LUMI", model = "lumi.motion.ac02" },
6+
{ mfr = "LUMI", model = "lumi.motion.agl02" },
7+
{ mfr = "LUMI", model = "lumi.motion.agl04" }
8+
}
9+
10+
return FINGERPRINTS

drivers/SmartThings/zigbee-motion-sensor/src/aqara/init.lua

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ local FREQUENCY_ATTRIBUTE_ID = 0x0102
1616

1717
local MOTION_DETECTED_UINT32 = 65536
1818

19-
local FINGERPRINTS = {
20-
{ mfr = "LUMI", model = "lumi.motion.ac02" },
21-
{ mfr = "LUMI", model = "lumi.motion.agl02" },
22-
{ mfr = "LUMI", model = "lumi.motion.agl04" }
23-
}
2419

2520
local CONFIGURATIONS = {
2621
{
@@ -33,14 +28,6 @@ local CONFIGURATIONS = {
3328
}
3429
}
3530

36-
local is_aqara_products = function(opts, driver, device)
37-
for _, fingerprint in ipairs(FINGERPRINTS) do
38-
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
39-
return true
40-
end
41-
end
42-
return false
43-
end
4431

4532
local function motion_illuminance_attr_handler(driver, device, value, zb_rx)
4633
-- The low 16 bits for Illuminance
@@ -126,7 +113,7 @@ local aqara_motion_handler = {
126113
sub_drivers = {
127114
require("aqara.high-precision-motion")
128115
},
129-
can_handle = is_aqara_products
116+
can_handle = require("aqara.can_handle"),
130117
}
131118

132119
return aqara_motion_handler
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 aurora_can_handle(opts, driver, device, ...)
5+
if device:get_manufacturer() == "Aurora" and device:get_model() == "MotionSensor51AU" then
6+
return true, require("aurora")
7+
end
8+
return false
9+
end
10+
11+
return aurora_can_handle

drivers/SmartThings/zigbee-motion-sensor/src/aurora/init.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ local aurora_motion_driver = {
2424
lifecycle_handlers = {
2525
added = added_handler,
2626
},
27-
can_handle = function(opts, driver, device, ...)
28-
return device:get_manufacturer() == "Aurora" and device:get_model() == "MotionSensor51AU"
29-
end
27+
can_handle = require("aurora.can_handle"),
3028
}
3129

3230
return aurora_motion_driver
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 can_handle_battery_voltage = function(opts, driver, device, ...)
5+
local FINGERPRINTS = require("battery-voltage.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("battery-voltage")
9+
end
10+
end
11+
return false
12+
end
13+
14+
return can_handle_battery_voltage
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 DEVICES_REPORTING_BATTERY_VOLTAGE = {
5+
{ mfr = "Bosch", model = "RFPR-ZB" },
6+
{ mfr = "Bosch", model = "RFDL-ZB-MS" },
7+
{ mfr = "Ecolink", model = "PIRZB1-ECO" },
8+
{ mfr = "ADUROLIGHT", model = "VMS_ADUROLIGHT" },
9+
{ mfr = "AduroSmart Eria", model = "VMS_ADUROLIGHT" }
10+
}
11+
12+
return DEVICES_REPORTING_BATTERY_VOLTAGE

drivers/SmartThings/zigbee-motion-sensor/src/battery-voltage/init.lua

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,13 @@
1414

1515
local battery_defaults = require "st.zigbee.defaults.battery_defaults"
1616

17-
local DEVICES_REPORTING_BATTERY_VOLTAGE = {
18-
{ mfr = "Bosch", model = "RFPR-ZB" },
19-
{ mfr = "Bosch", model = "RFDL-ZB-MS" },
20-
{ mfr = "Ecolink", model = "PIRZB1-ECO" },
21-
{ mfr = "ADUROLIGHT", model = "VMS_ADUROLIGHT" },
22-
{ mfr = "AduroSmart Eria", model = "VMS_ADUROLIGHT" }
23-
}
24-
25-
local can_handle_battery_voltage = function(opts, driver, device, ...)
26-
for _, fingerprint in ipairs(DEVICES_REPORTING_BATTERY_VOLTAGE) do
27-
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
28-
return true
29-
end
30-
end
31-
return false
32-
end
33-
3417

3518
local battery_voltage_motion = {
3619
NAME = "Battery Voltage Motion Sensor",
3720
lifecycle_handlers = {
3821
init = battery_defaults.build_linear_voltage_init(2.1, 3.0)
3922
},
40-
can_handle = can_handle_battery_voltage
23+
can_handle = require("battery-voltage.can_handle"),
4124
}
4225

4326
return battery_voltage_motion
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 centralite_can_handle(opts, driver, device, ...)
5+
if device:get_manufacturer() == "CentraLite" then
6+
return true, require("centralite")
7+
end
8+
return false
9+
end
10+
11+
return centralite_can_handle

drivers/SmartThings/zigbee-motion-sensor/src/centralite/init.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ local centralite_handler = {
4646
lifecycle_handlers = {
4747
init = init_handler
4848
},
49-
can_handle = function(opts, driver, device, ...)
50-
return device:get_manufacturer() == "CentraLite"
51-
end
49+
can_handle = require("centralite.can_handle"),
5250
}
5351

5452
return centralite_handler

0 commit comments

Comments
 (0)