diff --git a/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/attribute_handlers.lua b/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/attribute_handlers.lua index 0e3fe5f843..484e4c7a15 100644 --- a/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/attribute_handlers.lua +++ b/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/attribute_handlers.lua @@ -396,15 +396,13 @@ end function CameraAttributeHandlers.camera_av_stream_management_attribute_list_handler(driver, device, ib, response) if not ib.data.elements then return end local status_light_enabled_present, status_light_brightness_present = false, false - local attribute_ids, capability_ids = {}, {} + local attribute_ids = {} for _, attr in ipairs(ib.data.elements) do if attr.value == clusters.CameraAvStreamManagement.attributes.StatusLightEnabled.ID then status_light_enabled_present = true - table.insert(capability_ids, capabilities.switch.ID) table.insert(attribute_ids, clusters.CameraAvStreamManagement.attributes.StatusLightEnabled.ID) elseif attr.value == clusters.CameraAvStreamManagement.attributes.StatusLightBrightness.ID then status_light_brightness_present = true - table.insert(capability_ids, capabilities.mode.ID) table.insert(attribute_ids, clusters.CameraAvStreamManagement.attributes.StatusLightBrightness.ID) end end @@ -413,7 +411,6 @@ function CameraAttributeHandlers.camera_av_stream_management_attribute_list_hand endpoint_id = ib.endpoint_id, cluster_id = ib.cluster_id, attribute_ids = attribute_ids, - capability_ids = capability_ids } device:set_field(fields.COMPONENT_TO_ENDPOINT_MAP, component_map, {persist=true}) camera_cfg.match_profile(device, status_light_enabled_present, status_light_brightness_present) diff --git a/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/utils.lua b/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/utils.lua index 4334d2a304..dcdd936950 100644 --- a/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/utils.lua +++ b/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/utils.lua @@ -35,10 +35,6 @@ function CameraUtils.update_camera_component_map(device) clusters.CameraAvStreamManagement.attributes.MicrophoneMaxLevel.ID, clusters.CameraAvStreamManagement.attributes.MicrophoneMinLevel.ID, }, - capability_ids = { - capabilities.audioMute.ID, - capabilities.audioVolume.ID, - } } end if CameraUtils.feature_supported(device, clusters.CameraAvStreamManagement.ID, clusters.CameraAvStreamManagement.types.Feature.VIDEO) then @@ -51,10 +47,6 @@ function CameraUtils.update_camera_component_map(device) clusters.CameraAvStreamManagement.attributes.SpeakerMaxLevel.ID, clusters.CameraAvStreamManagement.attributes.SpeakerMinLevel.ID, }, - capability_ids = { - capabilities.audioMute.ID, - capabilities.audioVolume.ID, - } } end device:set_field(fields.COMPONENT_TO_ENDPOINT_MAP, component_map, {persist = true}) diff --git a/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua b/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua index 718e186dcf..51534ed02e 100644 --- a/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua +++ b/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua @@ -168,60 +168,40 @@ function utils.component_to_endpoint(device, component) return utils.find_default_endpoint(device) end ---- An extension of the library function endpoint_to_component, to support a mapping scheme ---- that includes cluster and attribute id's so that we can use multiple components for a ---- single endpoint. +--- An extension of the library function endpoint_to_component, used to support a mapping scheme +--- that optionally includes cluster and attribute ids so that multiple components can be mapped +--- to a single endpoint. --- --- @param device any a Matter device object ---- @param opts number|table either is an ep_id or a table { endpoint_id, capability_id } +--- @param ep_info number|table either an ep_id or a table { endpoint_id, optional(cluster_id), optional(attribute_id) } +--- where cluster_id is required for an attribute_id to be handled. --- @return string component -function utils.endpoint_to_component(device, opts) - local ep_info = {} - if type(opts) == "number" then - ep_info.endpoint_id = opts - elseif type(opts) == "table" then - if opts.endpoint_info then - ep_info = opts.endpoint_info - else - ep_info = { - endpoint_id = opts.endpoint_id, - cluster_id = opts.cluster_id, - attribute_id = opts.attribute_id - } - end +function utils.endpoint_to_component(device, ep_info) + if type(ep_info) == "number" then + ep_info = { endpoint_id = ep_info } end for component, map_info in pairs(device:get_field(fields.COMPONENT_TO_ENDPOINT_MAP) or {}) do if type(map_info) == "number" and map_info == ep_info.endpoint_id then return component - elseif type(map_info) == "table" and map_info.endpoint_id == ep_info.endpoint_id then - if (not map_info.cluster_id or (map_info.cluster_id == ep_info.cluster_id - and utils.tbl_contains(map_info.attribute_ids, ep_info.attribute_id))) - and (not opts.capability_id or utils.tbl_contains(map_info.capability_ids, opts.capability_id)) then + elseif type(map_info) == "table" and map_info.endpoint_id == ep_info.endpoint_id + and (not map_info.cluster_id or (map_info.cluster_id == ep_info.cluster_id + and (not map_info.attribute_ids or utils.tbl_contains(map_info.attribute_ids, ep_info.attribute_id)))) then return component - end end end return "main" end ---- An extension of the library function emit_event_for_endpoint, to support devices with ---- multiple components defined for the same endpoint, since they can't be easily ---- differentiated based on a simple endpoint id to component mapping, but we can extend ---- this mapping to include the cluster and attribute id's so that we know which component ---- to route events to. +--- An extension of the library function emit_event_for_endpoint, used to support devices with +--- multiple components mapped to the same endpoint. This is handled by extending the parameters to optionally +--- include a cluster id and attribute id for more specific routing --- --- @param device any a Matter device object ---- @param ep_info number|table endpoint_id or ib (includes endpoint_id, cluster_id, attribute_id) +--- @param ep_info number|table endpoint_id or an ib (the ib data includes endpoint_id, cluster_id, and attribute_id fields) --- @param event any a capability event object function utils.emit_event_for_endpoint(device, ep_info, event) if type(ep_info) == "number" then ep_info = { endpoint_id = ep_info } - elseif type(ep_info) == "table" then - ep_info = { - endpoint_id = ep_info.endpoint_id, - cluster_id = ep_info.cluster_id, - attribute_id = ep_info.attribute_id - } end if device:get_field(fields.IS_PARENT_CHILD_DEVICE) then local child = utils.find_child(device, ep_info.endpoint_id) @@ -230,8 +210,7 @@ function utils.emit_event_for_endpoint(device, ep_info, event) return end end - local opts = { endpoint_info = ep_info, capability_id = event.capability.ID } - local comp_id = utils.endpoint_to_component(device, opts) + local comp_id = utils.endpoint_to_component(device, ep_info) local comp = device.profile.components[comp_id] device:emit_component_event(comp, event) end