@@ -677,7 +677,7 @@ local function build_multicomponent_profile(device, main_endpoint, secondary_end
677
677
profile_name = " switch-binary"
678
678
end
679
679
680
- if not battery_supported then
680
+ if not battery_supported then -- battery profiles are configured later, in power_source_attribute_list_handler
681
681
profile_name = string.gsub (profile_name , " 1%-" , " " ) -- remove the "1-" in a device with 1 button ep
682
682
device :try_update_metadata ({profile = profile_name })
683
683
end
@@ -721,33 +721,33 @@ local function build_child_switch_profiles(driver, device, switch_eps, main_endp
721
721
return num_switch_server_eps
722
722
end
723
723
724
- local function handle_light_switch_with_onOff_server_clusters (device , main_endpoint , num_switch_server_eps )
725
- local cluster_id = 0
726
- for _ , ep in ipairs (device .endpoints ) do
727
- -- main_endpoint only supports server cluster by definition of get_endpoints()
728
- if main_endpoint == ep .endpoint_id then
729
- for _ , dt in ipairs (ep .device_types ) do
730
- -- no device type that is not in the switch subset should be considered.
731
- if (ON_OFF_SWITCH_ID <= dt .device_type_id and dt .device_type_id <= ON_OFF_COLOR_DIMMER_SWITCH_ID ) then
732
- cluster_id = math.max (cluster_id , dt .device_type_id )
733
- end
724
+ local function handle_light_switch_with_onOff_server_clusters (device , main_endpoint )
725
+ local cluster_id = 0
726
+ for _ , ep in ipairs (device .endpoints ) do
727
+ -- main_endpoint only supports server cluster by definition of get_endpoints()
728
+ if main_endpoint == ep .endpoint_id then
729
+ for _ , dt in ipairs (ep .device_types ) do
730
+ -- no device type that is not in the switch subset should be considered.
731
+ if (ON_OFF_SWITCH_ID <= dt .device_type_id and dt .device_type_id <= ON_OFF_COLOR_DIMMER_SWITCH_ID ) then
732
+ cluster_id = math.max (cluster_id , dt .device_type_id )
734
733
end
735
- break
736
734
end
735
+ break
737
736
end
737
+ end
738
738
739
- if device_type_profile_map [cluster_id ] then
740
- device :try_update_metadata ({profile = device_type_profile_map [cluster_id ]})
741
- end
739
+ if device_type_profile_map [cluster_id ] then
740
+ device :try_update_metadata ({profile = device_type_profile_map [cluster_id ]})
741
+ end
742
742
end
743
743
744
744
local function initialize_buttons_and_switches (driver , device , main_endpoint )
745
- local switch_eps = device :get_endpoints (clusters .OnOff .ID )
746
745
local button_eps = device :get_endpoints (clusters .Switch .ID , {feature_bitmap = clusters .Switch .types .SwitchFeature .MOMENTARY_SWITCH })
747
746
local fan_eps = device :get_endpoints (clusters .FanControl .ID )
748
- table.sort ( switch_eps )
747
+ local switch_eps = device : get_endpoints ( clusters . OnOff . ID )
749
748
table.sort (button_eps )
750
749
table.sort (fan_eps )
750
+ table.sort (switch_eps )
751
751
752
752
if # button_eps > 0 then
753
753
build_component_map (device , main_endpoint , button_eps , GENERIC_SWITCH_ID )
@@ -766,7 +766,7 @@ local function initialize_buttons_and_switches(driver, device, main_endpoint)
766
766
-- However, this workaround profiles devices that claim to be Light Switches, but that break spec and implement OnOff as 'server'.
767
767
-- Note: since their device type isn't supported, these devices join as a matter-thing.
768
768
if num_switch_server_eps > 0 and detect_matter_thing (device ) then
769
- handle_light_switch_with_onOff_server_clusters (device , main_endpoint , num_switch_server_eps )
769
+ handle_light_switch_with_onOff_server_clusters (device , main_endpoint )
770
770
end
771
771
end
772
772
0 commit comments