Skip to content

Commit 22c2547

Browse files
Set fan as the main component and light as secondary component
1 parent 3c96c20 commit 22c2547

File tree

1 file changed

+13
-8
lines changed
  • drivers/SmartThings/matter-switch/src

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ local function find_child(parent, ep_id)
552552
return parent:get_child_by_parent_assigned_key(string.format("%d", ep_id))
553553
end
554554

555-
local function build_component_map(device, main_endpoint, button_eps, fan_eps)
555+
local function build_component_map(device, main_endpoint, button_eps, light_eps)
556556
local eps
557557
local component_name
558558
local component_field
@@ -561,9 +561,9 @@ local function build_component_map(device, main_endpoint, button_eps, fan_eps)
561561
eps = button_eps
562562
component_name = "button"
563563
component_field = COMPONENT_TO_ENDPOINT_MAP_BUTTON
564-
elseif fan_eps ~= nil then
565-
eps = fan_eps
566-
component_name = "fan"
564+
elseif light_eps ~= nil then
565+
eps = light_eps
566+
component_name = "light"
567567
component_field = COMPONENT_TO_ENDPOINT_MAP_FAN
568568
end
569569
if eps == nil then return end
@@ -572,7 +572,10 @@ local function build_component_map(device, main_endpoint, button_eps, fan_eps)
572572
component_map["main"] = main_endpoint
573573
for component_num, ep in ipairs(eps) do
574574
if ep ~= main_endpoint then
575-
local component = component_name .. component_num
575+
local component = component_name
576+
if #eps > 2 then
577+
component = component .. component_num
578+
end
576579
component_map[component] = ep
577580
end
578581
end
@@ -691,13 +694,15 @@ local function initialize_buttons_and_switches(driver, device, main_endpoint)
691694
end
692695
end
693696

694-
-- Any button or fan endpoints found will be added as additional components in the profile containing the
695-
-- main endpoint. The resulting endpoint to component map is saved in the COMPONENT_TO_ENDPOINT_MAP_BUTTON field
697+
-- Any button endpoints found will be added as additional components in the profile containing the
698+
-- main endpoint. An fan endpoint will be considered the main endpoint and other additional switch
699+
-- endpoints will be added as additional components. The resulting endpoint to component map is
700+
-- saved in the corresponding component to endpoint map field.
696701
if #button_eps > 0 then
697702
build_component_map(device, main_endpoint, button_eps)
698703
build_button_profile(device, main_endpoint, #button_eps)
699704
elseif #fan_eps > 0 then
700-
build_component_map(device, main_endpoint, fan_eps)
705+
build_component_map(device, main_endpoint, switch_eps)
701706
build_fan_profile(device, main_endpoint, #fan_eps)
702707
end
703708

0 commit comments

Comments
 (0)