@@ -21,12 +21,11 @@ local modular_profiles_utils = {}
21
21
22
22
modular_profiles_utils .SUPPORTED_COMPONENT_CAPABILITIES = " __supported_component_capabilities"
23
23
24
-
25
24
local profile_name_and_mandatory_capability_per_device_category = {
26
- [common_utils .device_categories .BUTTON ] = { profile_name = " button-modular" , mandatory_capability = capabilities .button .ID },
27
- [common_utils .device_categories .LIGHT ] = { profile_name = " light-modular" , mandatory_capability = capabilities .switch .ID },
28
- [common_utils .device_categories .PLUG ] = { profile_name = " plug-modular" , mandatory_capability = capabilities .switch .ID },
29
- [common_utils .device_categories .SWITCH ] = { profile_name = " switch-modular" , mandatory_capability = capabilities .valve .ID },
25
+ [common_utils .device_categories .BUTTON ] = { profile_name = " button-modular" , mandatory_capability = capabilities .button .ID },
26
+ [common_utils .device_categories .LIGHT ] = { profile_name = " light-modular" , mandatory_capability = capabilities .switch .ID },
27
+ [common_utils .device_categories .PLUG ] = { profile_name = " plug-modular" , mandatory_capability = capabilities .switch .ID },
28
+ [common_utils .device_categories .SWITCH ] = { profile_name = " switch-modular" , mandatory_capability = capabilities .valve .ID },
30
29
[common_utils .device_categories .WATER_VALVE ] = { profile_name = " water-valve-modular" , mandatory_capability = capabilities .switch .ID }
31
30
}
32
31
@@ -61,7 +60,7 @@ local function add_button_capabilities(device, category, main_endpoint, main_com
61
60
-- button-modular profile uses 'main', 'button2', button3', ... as component names.
62
61
-- Other profiles use 'main', 'button', 'button2', etc
63
62
if component_num == 1 and category == common_utils .device_categories .BUTTON then
64
- table.insert (main_component_capabilities , capabilities .button .ID )
63
+ table.insert (main_component_capabilities , 1 , capabilities .button .ID )
65
64
if battery_attr_support then
66
65
add_battery_capability (main_component_capabilities , battery_attr_support )
67
66
end
85
84
local function handle_light_switch_with_onOff_server_clusters (device , main_endpoint , component_capabilities )
86
85
local device_type_id = 0
87
86
for _ , ep in ipairs (device .endpoints ) do
88
- -- main_endpoint only supports server cluster by definition of get_endpoints()
87
+ -- The main endpoint only supports server cluster by definition of get_endpoints()
89
88
if main_endpoint == ep .endpoint_id then
90
89
for _ , dt in ipairs (ep .device_types ) do
91
- -- no device type that is not in the switch subset should be considered.
90
+ -- No device type that is not in the switch subset should be considered
92
91
if (common_utils .ON_OFF_SWITCH_ID <= dt .device_type_id and dt .device_type_id <= common_utils .ON_OFF_COLOR_DIMMER_SWITCH_ID ) then
93
92
device_type_id = math.max (device_type_id , dt .device_type_id )
94
93
end
@@ -124,15 +123,23 @@ local function handle_light_switch_with_onOff_server_clusters(device, main_endpo
124
123
end
125
124
end
126
125
126
+ local function optionally_insert_to_position (insert_to_position , component_capabilities , capability_id , position )
127
+ if insert_to_position then
128
+ table.insert (component_capabilities , position , capability_id )
129
+ else
130
+ table.insert (component_capabilities , capability_id )
131
+ end
132
+ end
133
+
127
134
local function match_modular_profile (driver , device , battery_attr_support )
128
135
local main_endpoint = common_utils .find_default_endpoint (device )
136
+ local switch_eps = device :get_endpoints (clusters .OnOff .ID )
137
+ local level_eps = device :get_endpoints (clusters .LevelControl .ID )
129
138
local color_hs_eps = device :get_endpoints (clusters .ColorControl .ID , {feature_bitmap = clusters .ColorControl .types .Feature .HS })
130
139
local color_xy_eps = device :get_endpoints (clusters .ColorControl .ID , {feature_bitmap = clusters .ColorControl .types .Feature .XY })
131
140
local color_temp_eps = device :get_endpoints (clusters .ColorControl .ID , {feature_bitmap = clusters .ColorControl .types .Feature .CT })
132
- local level_eps = device :get_endpoints (clusters .LevelControl .ID )
133
141
local power_eps = device :get_endpoints (clusters .ElectricalPowerMeasurement .ID )
134
142
local energy_eps = device :get_endpoints (clusters .ElectricalEnergyMeasurement .ID )
135
- local switch_eps = device :get_endpoints (clusters .OnOff .ID )
136
143
local fan_eps = device :get_endpoints (clusters .FanControl .ID )
137
144
local humidity_eps = device :get_endpoints (clusters .RelativeHumidityMeasurement .ID )
138
145
local temperature_eps = device :get_endpoints (clusters .TemperatureMeasurement .ID )
@@ -146,10 +153,28 @@ local function match_modular_profile(driver, device, battery_attr_support)
146
153
147
154
local MAIN_COMPONENT_IDX , CAPABILITIES_LIST_IDX = 1 , 2
148
155
149
- add_button_capabilities (device , category , main_endpoint , main_component_capabilities , extra_component_capabilities , battery_attr_support )
156
+ if # switch_eps > 0 then
157
+ -- If the device is a Button or Water Valve, add the switch capability since it is not a mandatory
158
+ -- capability for these device types
159
+ if category == common_utils .device_categories .BUTTON or category == common_utils .device_categories .WATER_VALVE then
160
+ table.insert (main_component_capabilities , capabilities .switch .ID )
161
+ end
162
+ -- Without support for bindings, only clusters that are implemented as server are counted. This count is handled
163
+ -- while building switch child profiles
164
+ local num_switch_server_eps = common_utils .build_child_switch_profiles (driver , device , main_endpoint )
165
+ -- Ensure that the proper capabilities are included for Light Switch device types that implement the OnOff
166
+ -- cluster as 'server'
167
+ if num_switch_server_eps > 0 and common_utils .detect_matter_thing (device ) then
168
+ handle_light_switch_with_onOff_server_clusters (device , main_endpoint , main_component_capabilities )
169
+ end
170
+ end
150
171
151
172
-- Only add capabilities related to lights if the corresponding cluster is
152
173
-- implemented on the main endpoint. Otherwise, it will be added as a child device.
174
+ if common_utils .tbl_contains (level_eps , main_endpoint ) then
175
+ table.insert (main_component_capabilities , capabilities .switchLevel .ID )
176
+ end
177
+
153
178
if common_utils .tbl_contains (color_hs_eps , main_endpoint ) or common_utils .tbl_contains (color_xy_eps , main_endpoint ) then
154
179
table.insert (main_component_capabilities , capabilities .colorControl .ID )
155
180
end
@@ -158,10 +183,6 @@ local function match_modular_profile(driver, device, battery_attr_support)
158
183
table.insert (main_component_capabilities , capabilities .colorTemperature .ID )
159
184
end
160
185
161
- if common_utils .tbl_contains (level_eps , main_endpoint ) then
162
- table.insert (main_component_capabilities , capabilities .switchLevel .ID )
163
- end
164
-
165
186
if # power_eps > 0 then
166
187
table.insert (main_component_capabilities , capabilities .powerMeter .ID )
167
188
end
@@ -171,27 +192,6 @@ local function match_modular_profile(driver, device, battery_attr_support)
171
192
table.insert (main_component_capabilities , capabilities .powerConsumptionReport .ID )
172
193
end
173
194
174
- if # switch_eps > 0 then
175
- -- If the device is a Button or Water Valve, add the switch capability since
176
- -- it is not a mandatory capability for these device types.
177
- if category == common_utils .device_categories .BUTTON or category == common_utils .device_categories .WATER_VALVE then
178
- table.insert (main_component_capabilities , capabilities .switch .ID )
179
- end
180
- -- Without support for bindings, only clusters that are implemented as server are counted. This count is handled
181
- -- while building switch child profiles
182
- local num_switch_server_eps = common_utils .build_child_switch_profiles (driver , device , main_endpoint )
183
- -- Ensure that the proper capabilities are included for Light Switch device types that implement the OnOff
184
- -- cluster as 'server'
185
- if num_switch_server_eps > 0 and common_utils .detect_matter_thing (device ) then
186
- handle_light_switch_with_onOff_server_clusters (device , main_endpoint , main_component_capabilities )
187
- end
188
- end
189
-
190
- if # fan_eps > 0 then
191
- table.insert (main_component_capabilities , capabilities .fanMode .ID )
192
- table.insert (main_component_capabilities , capabilities .fanSpeedPercent .ID )
193
- end
194
-
195
195
if # humidity_eps > 0 then
196
196
table.insert (main_component_capabilities , capabilities .relativeHumidityMeasurement .ID )
197
197
end
@@ -200,14 +200,22 @@ local function match_modular_profile(driver, device, battery_attr_support)
200
200
table.insert (main_component_capabilities , capabilities .temperatureMeasurement .ID )
201
201
end
202
202
203
+ if # fan_eps > 0 then
204
+ table.insert (main_component_capabilities , capabilities .fanMode .ID )
205
+ table.insert (main_component_capabilities , capabilities .fanSpeedPercent .ID )
206
+ end
207
+
203
208
if # valve_eps > 0 then
204
- table.insert (main_component_capabilities , capabilities .valve .ID )
209
+ local is_a_valve = category == common_utils .device_categories .WATER_VALVE
210
+ optionally_insert_to_position (is_a_valve , main_component_capabilities , capabilities .valve .ID , 1 )
205
211
if # device :get_endpoints (clusters .ValveConfigurationAndControl .ID ,
206
212
{feature_bitmap = clusters .ValveConfigurationAndControl .types .Feature .LEVEL }) > 0 then
207
- table.insert ( main_component_capabilities , capabilities .level .ID )
213
+ optionally_insert_to_position ( is_a_valve , main_component_capabilities , capabilities .level .ID , 2 )
208
214
end
209
215
end
210
216
217
+ add_button_capabilities (device , category , main_endpoint , main_component_capabilities , extra_component_capabilities , battery_attr_support )
218
+
211
219
table.insert (optional_supported_component_capabilities , {" main" , main_component_capabilities })
212
220
for _ , component_capability in ipairs (extra_component_capabilities ) do
213
221
table.insert (optional_supported_component_capabilities , component_capability )
0 commit comments