@@ -51,9 +51,12 @@ local SWITCH_INITIALIZED = "__switch_intialized"
51
51
-- in the device table for devices that joined prior to this transition, and it
52
52
-- will not be set for new devices.
53
53
local COMPONENT_TO_ENDPOINT_MAP = " __component_to_endpoint_map"
54
- -- COMPONENT_TO_ENDPOINT_MAP_NEW_DEVICES is for new devices that can be supported
55
- -- by a MCD configuration.
56
- local COMPONENT_TO_ENDPOINT_MAP_NEW_DEVICES = " __component_to_endpoint_map_button"
54
+ -- COMPONENT_TO_ENDPOINT_MAP_BUTTON is for devices with button endpoints, to
55
+ -- preserve the MCD functionality for button devices from the matter-button
56
+ -- driver after it was merged into the matter-switch driver. Note that devices
57
+ -- containing both button endpoints and switch endpoints will use this field
58
+ -- rather than COMPONENT_TO_ENDPOINT_MAP.
59
+ local COMPONENT_TO_ENDPOINT_MAP_BUTTON = " __component_to_endpoint_map_button"
57
60
local ENERGY_MANAGEMENT_ENDPOINT = " __energy_management_endpoint"
58
61
local IS_PARENT_CHILD_DEVICE = " __is_parent_child_device"
59
62
local COLOR_TEMP_BOUND_RECEIVED_KELVIN = " __colorTemp_bound_received_kelvin"
@@ -453,15 +456,15 @@ local function find_default_endpoint(device)
453
456
end
454
457
455
458
local function component_to_endpoint (device , component )
456
- local map = device :get_field (COMPONENT_TO_ENDPOINT_MAP_NEW_DEVICES ) or device :get_field (COMPONENT_TO_ENDPOINT_MAP ) or {}
459
+ local map = device :get_field (COMPONENT_TO_ENDPOINT_MAP_BUTTON ) or device :get_field (COMPONENT_TO_ENDPOINT_MAP ) or {}
457
460
if map [component ] then
458
461
return map [component ]
459
462
end
460
463
return find_default_endpoint (device )
461
464
end
462
465
463
466
local function endpoint_to_component (device , ep )
464
- local map = device :get_field (COMPONENT_TO_ENDPOINT_MAP_NEW_DEVICES ) or device :get_field (COMPONENT_TO_ENDPOINT_MAP ) or {}
467
+ local map = device :get_field (COMPONENT_TO_ENDPOINT_MAP_BUTTON ) or device :get_field (COMPONENT_TO_ENDPOINT_MAP ) or {}
465
468
for component , endpoint in pairs (map ) do
466
469
if endpoint == ep then
467
470
return component
@@ -584,43 +587,32 @@ local function find_child(parent, ep_id)
584
587
end
585
588
586
589
local function build_component_map (device , main_endpoint )
587
- local component_name , endpoints
590
+ -- create component mapping on the main profile button endpoints
588
591
local button_eps = device :get_endpoints (clusters .Switch .ID , {feature_bitmap = clusters .Switch .types .SwitchFeature .MOMENTARY_SWITCH })
589
- local fan_eps = device :get_endpoints (clusters .FanControl .ID )
590
- table.sort (button_eps )
591
- table.sort (fan_eps )
592
-
593
- if # button_eps > 0 and STATIC_BUTTON_PROFILE_SUPPORTED [# button_eps ] then
594
- component_name = " button"
595
- endpoints = button_eps
596
- elseif # fan_eps > 0 then
597
- component_name = " fan"
598
- endpoints = fan_eps
599
- else
600
- return
601
- end
602
-
603
- local component_map = {}
604
- component_map [" main" ] = main_endpoint
605
- for component_num , ep in ipairs (endpoints ) do
606
- if ep ~= main_endpoint then
607
- local component = component_name
608
- if # endpoints > 1 then
609
- component = component .. component_num
592
+ if tbl_contains (STATIC_BUTTON_PROFILE_SUPPORTED , # button_eps ) then
593
+ table.sort (button_eps )
594
+ local component_map = {}
595
+ component_map [" main" ] = main_endpoint
596
+ for component_num , ep in ipairs (button_eps ) do
597
+ if ep ~= main_endpoint then
598
+ local button_component = " button"
599
+ if # button_eps > 1 then
600
+ button_component = button_component .. component_num
601
+ end
602
+ component_map [button_component ] = ep
610
603
end
611
- component_map [component ] = ep
612
604
end
605
+ device :set_field (COMPONENT_TO_ENDPOINT_MAP_BUTTON , component_map , {persist = true })
613
606
end
614
- device :set_field (COMPONENT_TO_ENDPOINT_MAP_NEW_DEVICES , component_map , {persist = true })
615
607
end
616
608
617
- local function build_mcd_profile (device , main_endpoint )
609
+ local function build_profile (device , main_endpoint )
618
610
local button_eps = device :get_endpoints (clusters .Switch .ID , {feature_bitmap = clusters .Switch .types .SwitchFeature .MOMENTARY_SWITCH })
619
611
local fan_eps = device :get_endpoints (clusters .FanControl .ID )
620
612
local profile_name
621
613
local battery_supported
622
614
623
- if # button_eps > 0 and STATIC_BUTTON_PROFILE_SUPPORTED [ # button_eps ] then
615
+ if tbl_contains ( STATIC_BUTTON_PROFILE_SUPPORTED , # button_eps ) then
624
616
profile_name = string.gsub (# button_eps .. " -button" , " 1%-" , " " ) -- remove the "1-" in a device with 1 button ep
625
617
if device_type_supports_button_switch_combination (device , main_endpoint ) then
626
618
profile_name = " light-level-" .. profile_name
@@ -632,7 +624,7 @@ local function build_mcd_profile(device, main_endpoint)
632
624
device :send (attribute_list_read )
633
625
end
634
626
elseif # fan_eps > 0 then
635
- profile_name = " light-color-level-fan"
627
+ profile_name = " light-color-level-fan" -- currently the only supported fan+light configuration
636
628
else
637
629
return
638
630
end
@@ -704,7 +696,7 @@ local function handle_light_switch_with_onOff_server_clusters(device, main_endpo
704
696
end
705
697
706
698
local function initialize_switch (driver , device , main_endpoint )
707
- build_mcd_profile (device , main_endpoint )
699
+ build_profile (device , main_endpoint )
708
700
build_component_map (device , main_endpoint )
709
701
configure_buttons (device )
710
702
0 commit comments