Skip to content

Commit 2d59ee9

Browse files
Remove unneeded parameter from handle_light_switch_with_onOff_server_clusters
Also restore accidentally removed comment
1 parent 87328b0 commit 2d59ee9

File tree

1 file changed

+18
-18
lines changed
  • drivers/SmartThings/matter-switch/src

1 file changed

+18
-18
lines changed

drivers/SmartThings/matter-switch/src/init.lua

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ local function build_multicomponent_profile(device, main_endpoint, secondary_end
677677
profile_name = "switch-binary"
678678
end
679679

680-
if not battery_supported then
680+
if not battery_supported then -- battery profiles are configured later, in power_source_attribute_list_handler
681681
profile_name = string.gsub(profile_name, "1%-", "") -- remove the "1-" in a device with 1 button ep
682682
device:try_update_metadata({profile = profile_name})
683683
end
@@ -721,33 +721,33 @@ local function build_child_switch_profiles(driver, device, switch_eps, main_endp
721721
return num_switch_server_eps
722722
end
723723

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)
734733
end
735-
break
736734
end
735+
break
737736
end
737+
end
738738

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
742742
end
743743

744744
local function initialize_buttons_and_switches(driver, device, main_endpoint)
745-
local switch_eps = device:get_endpoints(clusters.OnOff.ID)
746745
local button_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
747746
local fan_eps = device:get_endpoints(clusters.FanControl.ID)
748-
table.sort(switch_eps)
747+
local switch_eps = device:get_endpoints(clusters.OnOff.ID)
749748
table.sort(button_eps)
750749
table.sort(fan_eps)
750+
table.sort(switch_eps)
751751

752752
if #button_eps > 0 then
753753
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)
766766
-- However, this workaround profiles devices that claim to be Light Switches, but that break spec and implement OnOff as 'server'.
767767
-- Note: since their device type isn't supported, these devices join as a matter-thing.
768768
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)
770770
end
771771
end
772772

0 commit comments

Comments
 (0)