Skip to content

Commit 66f0b0a

Browse files
Lazy load camera subdriver
1 parent 6dec746 commit 66f0b0a

File tree

4 files changed

+41
-35
lines changed

4 files changed

+41
-35
lines changed

drivers/SmartThings/matter-switch/src/init.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ function SwitchLifecycleHandlers.device_init(driver, device)
127127
end
128128
end
129129

130+
local lazy_load_if_possible = require "utils.lazy_load_subdriver"
131+
130132
local matter_driver_template = {
131133
lifecycle_handlers = {
132134
added = SwitchLifecycleHandlers.device_added,
@@ -309,7 +311,7 @@ local matter_driver_template = {
309311
supported_capabilities = fields.supported_capabilities,
310312
sub_drivers = {
311313
require("sub_drivers.aqara_cube"),
312-
require("sub_drivers.camera"),
314+
lazy_load_if_possible("sub_drivers.camera"),
313315
require("sub_drivers.eve_energy"),
314316
require("sub_drivers.third_reality_mk1")
315317
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Copyright © 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
3+
4+
return function(opts, driver, device, ...)
5+
local device_lib = require "st.device"
6+
if device.network_type == device_lib.NETWORK_TYPE_MATTER then
7+
local version = require "version"
8+
if version.rpc < 10 or version.api < 16 then
9+
return false
10+
end
11+
for _, ep in ipairs(device.endpoints) do
12+
for _, dt in ipairs(ep.device_types) do
13+
if dt.device_type_id == 0x0142 then
14+
return true, require("sub_drivers.camera")
15+
end
16+
end
17+
end
18+
end
19+
return false
20+
end

drivers/SmartThings/matter-switch/src/sub_drivers/camera/init.lua

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
-- Copyright 2025 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 © 2025 SmartThings, Inc.
2+
-- Licensed under the Apache License, Version 2.0
143

154
-------------------------------------------------------------------------------------
165
-- Matter Camera Sub Driver
@@ -160,25 +149,6 @@ local ABS_VOL_MAX, ABS_VOL_MIN = 254.0, 0.0
160149

161150
-- Helper Functions
162151

163-
local function is_camera(opts, driver, device)
164-
local device_lib = require "st.device"
165-
if device.network_type == device_lib.NETWORK_TYPE_MATTER then
166-
local version = require "version"
167-
if version.rpc < 10 or version.api < 16 then
168-
device.log.warn(string.format("Matter Camera not supported on current firmware version"))
169-
return false
170-
end
171-
for _, ep in ipairs(device.endpoints) do
172-
for _, dt in ipairs(ep.device_types) do
173-
if dt.device_type_id == 0x0142 then -- 0x0142 is the Camera device type ID
174-
return true
175-
end
176-
end
177-
end
178-
end
179-
return false
180-
end
181-
182152
local function component_to_endpoint(device, component)
183153
local camera_eps = device:get_endpoints(clusters.CameraAvStreamManagement.ID)
184154
table.sort(camera_eps)
@@ -621,7 +591,7 @@ local function device_init(driver, device)
621591
local parent_child_device = false
622592
for _, ep in ipairs(device.endpoints) do
623593
if device:supports_server_cluster(clusters.OnOff.ID, ep.endpoint_id) then
624-
local child_profile = cfg.SwitchCfg.assign_child_profile(device, ep.endpoint_id)
594+
local child_profile = cfg.SwitchCfg.assign_profile_for_onoff_ep(device, ep.endpoint_id)
625595
if child_profile then
626596
num_floodlight_eps = num_floodlight_eps + 1
627597
local name = string.format("%s %d", "Floodlight", num_floodlight_eps)
@@ -1582,7 +1552,7 @@ local camera_handler = {
15821552
[capabilities.localMediaStorage.commands.setLocalVideoRecording.NAME] = set_enabled_factory(clusters.CameraAvStreamManagement.attributes.LocalVideoRecordingEnabled)
15831553
}
15841554
},
1585-
can_handle = is_camera
1555+
can_handle = require("sub_drivers.camera.can_handle")
15861556
}
15871557

15881558
return camera_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+
return function(sub_driver_name)
5+
local version = require "version"
6+
local MatterDriver = require "st.matter.driver"
7+
if version.api >= 16 then
8+
return MatterDriver.lazy_load_sub_driver_v2(sub_driver_name)
9+
elseif version.api >= 9 then
10+
return MatterDriver.lazy_load_sub_driver(require(sub_driver_name))
11+
else
12+
return require(sub_driver_name)
13+
end
14+
end

0 commit comments

Comments
 (0)