Skip to content
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
15 changes: 14 additions & 1 deletion drivers/SmartThings/matter-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local switch_utils = require "switch_utils.utils"
local attribute_handlers = require "switch_handlers.attribute_handlers"
local event_handlers = require "switch_handlers.event_handlers"
local capability_handlers = require "switch_handlers.capability_handlers"
local utils = require "st.utils"

-- Include driver-side definitions when lua libs api version is < 11
if version.api < 11 then
Expand All @@ -32,6 +33,8 @@ end
local SwitchLifecycleHandlers = {}

function SwitchLifecycleHandlers.device_added(driver, device)
device.log.info_with({ hub_logs = true }, string.format("parent driver - added handler"))

-- refresh child devices to get an initial attribute state for OnOff in case child device
-- was created after the initial subscription report
if device.network_type == device_lib.NETWORK_TYPE_CHILD then
Expand All @@ -43,6 +46,8 @@ function SwitchLifecycleHandlers.device_added(driver, device)
end

function SwitchLifecycleHandlers.do_configure(driver, device)
device.log.info_with({ hub_logs = true }, string.format("parent driver - do_configure handler"))

if device.network_type == device_lib.NETWORK_TYPE_MATTER and not switch_utils.detect_bridge(device) then
switch_cfg.set_device_control_options(device)
device_cfg.match_profile(driver, device)
Expand All @@ -60,6 +65,8 @@ function SwitchLifecycleHandlers.driver_switched(driver, device)
end

function SwitchLifecycleHandlers.info_changed(driver, device, event, args)
device.log.info_with({ hub_logs = true }, string.format("parent driver - info_changed handler"))

if not switch_utils.deep_equals(device.profile, args.old_st_store.profile, { ignore_functions = true }) then
if device.network_type == device_lib.NETWORK_TYPE_MATTER then
device:subscribe()
Expand Down Expand Up @@ -91,6 +98,12 @@ function SwitchLifecycleHandlers.info_changed(driver, device, event, args)
end

function SwitchLifecycleHandlers.device_init(driver, device)
device.log.info_with({ hub_logs = true }, string.format("parent driver - device_init handler"))
local version = require "version"
device.log.info_with({ hub_logs = true }, string.format("parent driver - device_init: rpc: %d, api version: %d, # camera endpoints: %d", version.rpc, version.api, #switch_utils.get_endpoints_by_device_type(device, fields.DEVICE_TYPE_ID.CAMERA)))
device.log.info_with({ hub_logs = true }, string.format("parent driver - device: %s", utils.stringify_table(device)))


if device.network_type == device_lib.NETWORK_TYPE_MATTER then
switch_utils.check_field_name_updates(device)
device:set_component_to_endpoint_fn(switch_utils.component_to_endpoint)
Expand Down Expand Up @@ -341,7 +354,7 @@ local matter_driver_template = {
},
sub_drivers = {
switch_utils.lazy_load_if_possible("sub_drivers.aqara_cube"),
switch_utils.lazy_load("sub_drivers.camera"),
require("sub_drivers.camera"),
switch_utils.lazy_load_if_possible("sub_drivers.eve_energy"),
switch_utils.lazy_load_if_possible("sub_drivers.ikea_scroll"),
switch_utils.lazy_load_if_possible("sub_drivers.third_reality_mk1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function CameraAttributeHandlers.min_viewport_handler(driver, device, ib, respon
end

function CameraAttributeHandlers.allocated_video_streams_handler(driver, device, ib, response)
device.log.info_with({ hub_logs = true }, string.format("camera driver - allocated video streams handler"))
if not ib.data.elements then return end

local dptz_viewports = device:get_field(camera_fields.DPTZ_VIEWPORTS) or {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
-- Licensed under the Apache License, Version 2.0

return function(opts, driver, device, ...)
device.log.info_with({ hub_logs = true }, string.format("camera driver - calling can_handle, network type: %s", device.network_type))
local device_lib = require "st.device"
local fields = require "switch_utils.fields"
local switch_utils = require "switch_utils.utils"
if device.network_type == device_lib.NETWORK_TYPE_MATTER then
local version = require "version"
if version.rpc >= 10 and version.api >= 16 and
#switch_utils.get_endpoints_by_device_type(device, fields.DEVICE_TYPE_ID.CAMERA) > 0 then
return true, require("sub_drivers.camera")
end
end
return false
return true, require("sub_drivers.camera")
end

21 changes: 19 additions & 2 deletions drivers/SmartThings/matter-switch/src/sub_drivers/camera/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ local clusters = require "st.matter.clusters"
local event_handlers = require "sub_drivers.camera.camera_handlers.event_handlers"
local fields = require "switch_utils.fields"
local switch_utils = require "switch_utils.utils"
local utils = require "st.utils"

local CameraLifecycleHandlers = {}

function CameraLifecycleHandlers.device_init(driver, device)
device.log.info_with({ hub_logs = true }, string.format("camera driver - camera device_init handler"))
local version = require "version"
device.log.info_with({ hub_logs = true }, string.format("camera driver - device_init: rpc: %d, api version: %d, # camera endpoints: %d", version.rpc, version.api, #switch_utils.get_endpoints_by_device_type(device, fields.DEVICE_TYPE_ID.CAMERA)))
device.log.info_with({ hub_logs = true }, string.format("camera driver - device: %s", utils.stringify_table(device)))


device:set_component_to_endpoint_fn(camera_utils.component_to_endpoint)
device:set_endpoint_to_component_fn(switch_utils.endpoint_to_component)
device:extend_device("emit_event_for_endpoint", switch_utils.emit_event_for_endpoint)
Expand All @@ -31,6 +38,7 @@ function CameraLifecycleHandlers.device_init(driver, device)
end

function CameraLifecycleHandlers.do_configure(driver, device)
device.log.info_with({ hub_logs = true }, string.format("camera driver - camera do_configure handler"))
camera_utils.update_camera_component_map(device)
if #device:get_endpoints(clusters.CameraAvStreamManagement.ID) == 0 then
camera_cfg.match_profile(device, false, false)
Expand All @@ -47,6 +55,8 @@ function CameraLifecycleHandlers.driver_switched(driver, device)
end

function CameraLifecycleHandlers.info_changed(driver, device, event, args)
device.log.info_with({ hub_logs = true }, string.format("camera driver - camera info_changed handler"))

if not switch_utils.deep_equals(device.profile, args.old_st_store.profile, { ignore_functions = true }) then
camera_cfg.initialize_camera_capabilities(device)
device:subscribe()
Expand All @@ -56,7 +66,14 @@ function CameraLifecycleHandlers.info_changed(driver, device, event, args)
end
end

function CameraLifecycleHandlers.added() end
function CameraLifecycleHandlers.added(driver, device)
device.log.info_with({ hub_logs = true }, string.format("camera driver - camera added handler"))
end

function can_handle_matter_camera(opts, driver, device, ...)
device.log.info_with({ hub_logs = true }, string.format("camera driver - calling can_handle, network type: %s", device.network_type))
return true
end

local camera_handler = {
NAME = "Camera Handler",
Expand Down Expand Up @@ -202,7 +219,7 @@ local camera_handler = {
[capabilities.localMediaStorage.commands.setLocalVideoRecording.NAME] = capability_handlers.set_enabled_factory(clusters.CameraAvStreamManagement.attributes.LocalVideoRecordingEnabled)
}
},
can_handle = require("sub_drivers.camera.can_handle")
can_handle = can_handle_matter_camera,
}

return camera_handler