@@ -63,6 +63,14 @@ function utils.mired_to_kelvin(value, minOrMax)
6363 end
6464end
6565
66+ function utils .get_product_override_field (device , override_key )
67+ if fields .vendor_overrides [device .manufacturer_info .vendor_id ]
68+ and fields .vendor_overrides [device .manufacturer_info .vendor_id ][device .manufacturer_info .product_id ]
69+ then
70+ return fields .vendor_overrides [device .manufacturer_info .vendor_id ][device .manufacturer_info .product_id ][override_key ]
71+ end
72+ end
73+
6674function utils .check_field_name_updates (device )
6775 for _ , field in ipairs (fields .updated_fields ) do
6876 if device :get_field (field .current_field_name ) then
7886--- whether the device type for an endpoint is currently supported by a profile for
7987--- combination button/switch devices.
8088function utils .device_type_supports_button_switch_combination (device , endpoint_id )
81- for _ , ep in ipairs (device .endpoints ) do
82- if ep .endpoint_id == endpoint_id then
83- for _ , dt in ipairs (ep .device_types ) do
84- if dt .device_type_id == fields .DIMMABLE_LIGHT_DEVICE_TYPE_ID then
85- for _ , fingerprint in ipairs (fields .child_device_profile_overrides_per_vendor_id [0x115F ]) do
86- if device .manufacturer_info .product_id == fingerprint .product_id then
87- return false -- For Aqara Dimmer Switch with Button.
88- end
89- end
90- return true
91- end
92- end
93- end
89+ if utils .get_product_override_field (device , " ignore_combo_switch_button" ) then
90+ return false
9491 end
95- return false
92+ local dimmable_eps = utils .get_endpoints_by_device_type (device , fields .DIMMABLE_LIGHT_DEVICE_TYPE_ID )
93+ return utils .tbl_contains (dimmable_eps , endpoint_id )
9694end
9795
9896--- find_default_endpoint is a helper function to handle situations where
9997--- device does not have endpoint ids in sequential order from 1
10098function utils .find_default_endpoint (device )
101- if device .manufacturer_info .vendor_id == fields .AQARA_MANUFACTURER_ID and
102- device .manufacturer_info .product_id == fields .AQARA_CLIMATE_SENSOR_W100_ID then
103- -- In case of Aqara Climate Sensor W100, in order to sequentially set the button name to button 1, 2, 3
99+ -- Buttons should not be set on the main component for the Aqara Climate Sensor W100,
100+ if utils .get_product_override_field (device , " is_climate_sensor_w100" ) then
104101 return device .MATTER_DEFAULT_ENDPOINT
105102 end
106103
@@ -171,6 +168,19 @@ function utils.matter_handler(driver, device, response_block)
171168 device .log .info (string.format (" Fallback handler for %s" , response_block ))
172169end
173170
171+ -- get a list of endpoints for a specified device type.
172+ function utils .get_endpoints_by_device_type (device , device_type_id )
173+ local dt_eps = {}
174+ for _ , ep in ipairs (device .endpoints ) do
175+ for _ , dt in ipairs (ep .device_types ) do
176+ if dt .device_type_id == device_type_id then
177+ table.insert (dt_eps , ep .endpoint_id )
178+ end
179+ end
180+ end
181+ return dt_eps
182+ end
183+
174184-- helper function to create list of multi press values
175185function utils .create_multi_press_values_list (size , supportsHeld )
176186 local list = {" pushed" , " double" }
@@ -183,14 +193,7 @@ function utils.create_multi_press_values_list(size, supportsHeld)
183193end
184194
185195function utils .detect_bridge (device )
186- for _ , ep in ipairs (device .endpoints ) do
187- for _ , dt in ipairs (ep .device_types ) do
188- if dt .device_type_id == fields .AGGREGATOR_DEVICE_TYPE_ID then
189- return true
190- end
191- end
192- end
193- return false
196+ return # utils .get_endpoints_by_device_type (device , fields .AGGREGATOR_DEVICE_TYPE_ID ) > 0
194197end
195198
196199function utils .detect_matter_thing (device )
0 commit comments