@@ -571,7 +571,7 @@ local function build_component_map(device, main_endpoint, button_eps, light_eps)
571
571
for component_num , ep in ipairs (eps ) do
572
572
if ep ~= main_endpoint then
573
573
local component = component_name
574
- if # eps > 2 then
574
+ if # eps > 1 then
575
575
component = component .. component_num
576
576
end
577
577
component_map [component ] = ep
@@ -580,10 +580,10 @@ local function build_component_map(device, main_endpoint, button_eps, light_eps)
580
580
device :set_field (component_field , component_map , {persist = true })
581
581
end
582
582
583
- local function build_button_profile (device , main_endpoint , num_button_eps )
583
+ local function build_button_profile (device , endpoint , num_button_eps )
584
584
local profile_name
585
585
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
587
587
profile_name = " light-level-" .. num_button_eps .. " -button"
588
588
else
589
589
profile_name = num_button_eps .. " -button"
@@ -604,8 +604,8 @@ local function build_button_profile(device, main_endpoint, num_button_eps)
604
604
device :set_field (BUTTON_DEVICE_PROFILED , true )
605
605
end
606
606
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
609
609
device :try_update_metadata ({profile = " fan-light-color-level" })
610
610
device :set_field (FAN_DEVICE_PROFILED , true )
611
611
else
@@ -679,6 +679,20 @@ local function initialize_buttons_and_switches(driver, device, main_endpoint)
679
679
table.sort (button_eps )
680
680
table.sort (fan_eps )
681
681
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
+
682
696
if # switch_eps > 0 then
683
697
-- Without support for bindings, only clusters that are implemented as server are counted. This count is handled
684
698
-- while building switch child profiles
@@ -692,31 +706,21 @@ local function initialize_buttons_and_switches(driver, device, main_endpoint)
692
706
end
693
707
end
694
708
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
-
707
709
device :set_field (SWITCH_INITIALIZED , true , {persist = true })
708
710
end
709
711
710
712
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 {}
712
715
if map [component ] then
713
716
return map [component ]
714
717
end
715
718
return find_default_endpoint (device )
716
719
end
717
720
718
721
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 {}
720
724
for component , endpoint in pairs (map ) do
721
725
if endpoint == ep then
722
726
return component
@@ -1407,7 +1411,7 @@ local function fan_mode_sequence_handler(driver, device, ib, response)
1407
1411
capabilities .fanMode .fanMode .high .NAME
1408
1412
}
1409
1413
end
1410
- local event = capabilities .airPurifierFanMode .supportedFanModes (supportedFanModes , {visibility = {displayed = false }})
1414
+ local event = capabilities .fanMode .supportedFanModes (supportedFanModes , {visibility = {displayed = false }})
1411
1415
device :emit_event_for_endpoint (ib .endpoint_id , event )
1412
1416
end
1413
1417
0 commit comments