Skip to content

Commit 9946633

Browse files
Bug fixes from test results
1 parent 4b7727c commit 9946633

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

drivers/SmartThings/matter-switch/fingerprints.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,12 @@ matterGeneric:
26422642
- id: 0x0101 # Dimmable Light
26432643
- id: 0x000F # Generic Switch
26442644
deviceProfileName: light-level-button
2645+
- id: "matter/fan/light"
2646+
deviceLabel: Matter Fan Light
2647+
deviceTypes:
2648+
- id: 0x002B # Fan
2649+
- id: 0x010D # Extended Color Light
2650+
deviceProfileName: fan-light-color-level
26452651

26462652
matterThing:
26472653
- id: SmartThings/MatterThing

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

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ local function build_component_map(device, main_endpoint, button_eps, light_eps)
571571
for component_num, ep in ipairs(eps) do
572572
if ep ~= main_endpoint then
573573
local component = component_name
574-
if #eps > 2 then
574+
if #eps > 1 then
575575
component = component .. component_num
576576
end
577577
component_map[component] = ep
@@ -580,10 +580,10 @@ local function build_component_map(device, main_endpoint, button_eps, light_eps)
580580
device:set_field(component_field, component_map, {persist = true})
581581
end
582582

583-
local function build_button_profile(device, main_endpoint, num_button_eps)
583+
local function build_button_profile(device, endpoint, num_button_eps)
584584
local profile_name
585585
local battery_supported
586-
if device_type_supports_multicomponent_configuration(device, main_endpoint, DIMMABLE_LIGHT_DEVICE_TYPE_ID) then
586+
if device_type_supports_multicomponent_configuration(device, endpoint, DIMMABLE_LIGHT_DEVICE_TYPE_ID) then
587587
profile_name = "light-level-" .. num_button_eps .. "-button"
588588
else
589589
profile_name = num_button_eps .. "-button"
@@ -604,8 +604,8 @@ local function build_button_profile(device, main_endpoint, num_button_eps)
604604
device:set_field(BUTTON_DEVICE_PROFILED, true)
605605
end
606606

607-
local function build_fan_profile(device, main_endpoint, num_fan_eps)
608-
if device_type_supports_multicomponent_configuration(device, main_endpoint, EXTENDED_COLOR_LIGHT_DEVICE_TYPE_ID) and #num_fan_eps == 1 then
607+
local function build_fan_profile(device, endpoint, num_fan_eps)
608+
if device_type_supports_multicomponent_configuration(device, endpoint, EXTENDED_COLOR_LIGHT_DEVICE_TYPE_ID) and num_fan_eps == 1 then
609609
device:try_update_metadata({profile = "fan-light-color-level"})
610610
device:set_field(FAN_DEVICE_PROFILED, true)
611611
else
@@ -679,6 +679,20 @@ local function initialize_buttons_and_switches(driver, device, main_endpoint)
679679
table.sort(button_eps)
680680
table.sort(fan_eps)
681681

682+
-- Any button endpoints found will be added as additional components in the profile containing the
683+
-- main endpoint. A fan endpoint will be considered the main endpoint and other additional switch
684+
-- endpoints will be added as additional components. The resulting endpoint to component map is
685+
-- saved in the corresponding component to endpoint map field.
686+
if #button_eps > 0 then
687+
build_component_map(device, main_endpoint, button_eps, nil)
688+
build_button_profile(device, main_endpoint, #button_eps)
689+
elseif #fan_eps > 0 then
690+
build_component_map(device, main_endpoint, nil, switch_eps)
691+
build_fan_profile(device, switch_eps[1], #fan_eps)
692+
device:set_field(SWITCH_INITIALIZED, true, {persist = true})
693+
return
694+
end
695+
682696
if #switch_eps > 0 then
683697
-- Without support for bindings, only clusters that are implemented as server are counted. This count is handled
684698
-- while building switch child profiles
@@ -692,31 +706,21 @@ local function initialize_buttons_and_switches(driver, device, main_endpoint)
692706
end
693707
end
694708

695-
-- Any button endpoints found will be added as additional components in the profile containing the
696-
-- main endpoint. A fan endpoint will be considered the main endpoint and other additional switch
697-
-- endpoints will be added as additional components. The resulting endpoint to component map is
698-
-- saved in the corresponding component to endpoint map field.
699-
if #button_eps > 0 then
700-
build_component_map(device, main_endpoint, button_eps)
701-
build_button_profile(device, main_endpoint, #button_eps)
702-
elseif #fan_eps > 0 then
703-
build_component_map(device, main_endpoint, switch_eps)
704-
build_fan_profile(device, main_endpoint, #fan_eps)
705-
end
706-
707709
device:set_field(SWITCH_INITIALIZED, true, {persist = true})
708710
end
709711

710712
local function component_to_endpoint(device, component)
711-
local map = device:get_field(COMPONENT_TO_ENDPOINT_MAP_BUTTON) or device:get_field(COMPONENT_TO_ENDPOINT_MAP) or {}
713+
local map = device:get_field(COMPONENT_TO_ENDPOINT_MAP_BUTTON) or device:get_field(COMPONENT_TO_ENDPOINT_MAP_FAN) or
714+
device:get_field(COMPONENT_TO_ENDPOINT_MAP) or {}
712715
if map[component] then
713716
return map[component]
714717
end
715718
return find_default_endpoint(device)
716719
end
717720

718721
local function endpoint_to_component(device, ep)
719-
local map = device:get_field(COMPONENT_TO_ENDPOINT_MAP_BUTTON) or device:get_field(COMPONENT_TO_ENDPOINT_MAP) or {}
722+
local map = device:get_field(COMPONENT_TO_ENDPOINT_MAP_BUTTON) or device:get_field(COMPONENT_TO_ENDPOINT_MAP_FAN) or
723+
device:get_field(COMPONENT_TO_ENDPOINT_MAP) or {}
720724
for component, endpoint in pairs(map) do
721725
if endpoint == ep then
722726
return component
@@ -1407,7 +1411,7 @@ local function fan_mode_sequence_handler(driver, device, ib, response)
14071411
capabilities.fanMode.fanMode.high.NAME
14081412
}
14091413
end
1410-
local event = capabilities.airPurifierFanMode.supportedFanModes(supportedFanModes, {visibility = {displayed = false}})
1414+
local event = capabilities.fanMode.supportedFanModes(supportedFanModes, {visibility = {displayed = false}})
14111415
device:emit_event_for_endpoint(ib.endpoint_id, event)
14121416
end
14131417

0 commit comments

Comments
 (0)