diff --git a/drivers/SmartThings/matter-switch/src/switch_utils/device_configuration.lua b/drivers/SmartThings/matter-switch/src/switch_utils/device_configuration.lua index adc0da500e..eebe734fcd 100644 --- a/drivers/SmartThings/matter-switch/src/switch_utils/device_configuration.lua +++ b/drivers/SmartThings/matter-switch/src/switch_utils/device_configuration.lua @@ -25,7 +25,7 @@ function SwitchDeviceConfiguration.assign_profile_for_onoff_ep(device, server_on -- per spec, the Switch device types support OnOff as CLIENT, though some vendors break spec and support it as SERVER. local primary_dt_id = switch_utils.find_max_subset_device_type(ep_info, fields.DEVICE_TYPE_ID.LIGHT) or switch_utils.find_max_subset_device_type(ep_info, fields.DEVICE_TYPE_ID.SWITCH) - or ep_info.device_types[1] and ep_info.device_types[1].device_type_id + or switch_utils.find_primary_device_type(ep_info) local generic_profile = fields.device_type_profile_map[primary_dt_id] diff --git a/drivers/SmartThings/matter-switch/src/switch_utils/fields.lua b/drivers/SmartThings/matter-switch/src/switch_utils/fields.lua index c350a7adaf..3a0bdc9fdb 100644 --- a/drivers/SmartThings/matter-switch/src/switch_utils/fields.lua +++ b/drivers/SmartThings/matter-switch/src/switch_utils/fields.lua @@ -36,6 +36,7 @@ SwitchFields.CURRENT_HUESAT_ATTR_MAX = 254 SwitchFields.DEVICE_TYPE_ID = { AGGREGATOR = 0x000E, + BRIDGED_NODE = 0x0013, CAMERA = 0x0142, CHIME = 0x0146, DIMMABLE_PLUG_IN_UNIT = 0x010B, diff --git a/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua b/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua index 718e186dcf..01a9d2d971 100644 --- a/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua +++ b/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua @@ -93,23 +93,33 @@ function utils.device_type_supports_button_switch_combination(device, endpoint_i return utils.tbl_contains(dimmable_eps, endpoint_id) end --- Some devices report multiple device types which are a subset of --- a superset device type (Ex. Dimmable Light is a superset of On/Off Light). --- We should map to the largest superset device type supported. --- This can be done by matching to the device type with the highest ID +--- Some devices report multiple device types which are a subset of a superset +--- device type (Ex. Dimmable Light is a superset of On/Off Light). We should map +--- to the largest superset device type supported. +--- This can be done by matching to the device type with the highest ID +--- note: that superset device types have a higher ID than those of their subset +--- is heuristic and could therefore break in the future, were the spec expanded function utils.find_max_subset_device_type(ep, device_type_set) if ep.endpoint_id == 0 then return end -- EP-scoped device types not permitted on Root Node - local primary_dt_id = ep.device_types[1] and ep.device_types[1].device_type_id - if utils.tbl_contains(device_type_set, primary_dt_id) then - for _, dt in ipairs(ep.device_types) do - -- only device types in the subset should be considered. - if utils.tbl_contains(device_type_set, dt.device_type_id) then - primary_dt_id = math.max(primary_dt_id, dt.device_type_id) - end + local primary_dt_id = -1 + for _, dt in ipairs(ep.device_types) do + -- only device types in the subset should be considered. + if utils.tbl_contains(device_type_set, dt.device_type_id) then + primary_dt_id = math.max(primary_dt_id, dt.device_type_id) + end + end + return (primary_dt_id > 0) and primary_dt_id or nil +end + +--- Lights and Switches are Device Types that have Superset-style functionality +--- For all other device types, this function should be used to identify the primary device type +function utils.find_primary_device_type(ep_info) + for _, dt in ipairs(ep_info.device_types) do + if dt.device_type_id ~= fields.DEVICE_TYPE_ID.BRIDGED_NODE then + -- if this is not a bridged node, return the first device type seen + return dt.device_type_id end - return primary_dt_id end - return nil end --- find_default_endpoint is a helper function to handle situations where