@@ -93,23 +93,33 @@ function utils.device_type_supports_button_switch_combination(device, endpoint_i
9393 return utils .tbl_contains (dimmable_eps , endpoint_id )
9494end
9595
96- -- Some devices report multiple device types which are a subset of
97- -- a superset device type (Ex. Dimmable Light is a superset of On/Off Light).
98- -- We should map to the largest superset device type supported.
99- -- This can be done by matching to the device type with the highest ID
96+ --- Some devices report multiple device types which are a subset of a superset
97+ --- device type (Ex. Dimmable Light is a superset of On/Off Light). We should map
98+ --- to the largest superset device type supported.
99+ --- This can be done by matching to the device type with the highest ID
100+ --- note: that superset device types have a higher ID than those of their subset
101+ --- is heuristic and could therefore break in the future, were the spec expanded
100102function utils .find_max_subset_device_type (ep , device_type_set )
101103 if ep .endpoint_id == 0 then return end -- EP-scoped device types not permitted on Root Node
102- local primary_dt_id = ep .device_types [1 ] and ep .device_types [1 ].device_type_id
103- if utils .tbl_contains (device_type_set , primary_dt_id ) then
104- for _ , dt in ipairs (ep .device_types ) do
105- -- only device types in the subset should be considered.
106- if utils .tbl_contains (device_type_set , dt .device_type_id ) then
107- primary_dt_id = math.max (primary_dt_id , dt .device_type_id )
108- end
104+ local primary_dt_id = - 1
105+ for _ , dt in ipairs (ep .device_types ) do
106+ -- only device types in the subset should be considered.
107+ if utils .tbl_contains (device_type_set , dt .device_type_id ) then
108+ primary_dt_id = math.max (primary_dt_id , dt .device_type_id )
109+ end
110+ end
111+ return (primary_dt_id > 0 ) and primary_dt_id or nil
112+ end
113+
114+ --- Lights and Switches are Device Types that have Superset-style functionality
115+ --- For all other device types, this function should be used to identify the primary device type
116+ function utils .find_primary_device_type (ep_info )
117+ for _ , dt in ipairs (ep_info .device_types ) do
118+ if dt .device_type_id ~= fields .DEVICE_TYPE_ID .BRIDGED_NODE then
119+ -- if this is not a bridged node, return the first device type seen
120+ return dt .device_type_id
109121 end
110- return primary_dt_id
111122 end
112- return nil
113123end
114124
115125--- find_default_endpoint is a helper function to handle situations where
0 commit comments