Skip to content

Commit 5edce5a

Browse files
Fix minor issue with mandatory capabilites
Swap mandatory capabilities for switch and valve. Also remove check for Aqara W100 from supports_modular_profile as this device would support modular profiles.
1 parent dbcf123 commit 5edce5a

File tree

3 files changed

+38
-41
lines changed

3 files changed

+38
-41
lines changed

drivers/SmartThings/matter-switch/src/common-utils.lua

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ common_utils.COLOR_TEMP_LIGHT_DEVICE_TYPE_ID = 0x010C
6363
common_utils.EXTENDED_COLOR_LIGHT_DEVICE_TYPE_ID = 0x010D
6464
common_utils.ON_OFF_PLUG_DEVICE_TYPE_ID = 0x010A
6565
common_utils.DIMMABLE_PLUG_DEVICE_TYPE_ID = 0x010B
66-
common_utils.ON_OFF_SWITCH_ID = 0x0103
67-
common_utils.ON_OFF_DIMMER_SWITCH_ID = 0x0104
68-
common_utils.ON_OFF_COLOR_DIMMER_SWITCH_ID = 0x0105
69-
common_utils.MOUNTED_ON_OFF_CONTROL_ID = 0x010F
70-
common_utils.MOUNTED_DIMMABLE_LOAD_CONTROL_ID = 0x0110
71-
common_utils.GENERIC_SWITCH_ID = 0x000F
72-
common_utils.ELECTRICAL_SENSOR_ID = 0x0510
73-
common_utils.WATER_VALVE_ID = 0x0042
66+
common_utils.ON_OFF_SWITCH_DEVICE_TYPE_ID = 0x0103
67+
common_utils.ON_OFF_DIMMER_SWITCH_DEVICE_TYPE_ID = 0x0104
68+
common_utils.ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID = 0x0105
69+
common_utils.MOUNTED_ON_OFF_CONTROL_DEVICE_TYPE_ID = 0x010F
70+
common_utils.MOUNTED_DIMMABLE_LOAD_CONTROL_DEVICE_TYPE_ID = 0x0110
71+
common_utils.GENERIC_SWITCH_DEVICE_TYPE_ID = 0x000F
72+
common_utils.ELECTRICAL_SENSOR_DEVICE_TYPE_ID = 0x0510
73+
common_utils.WATER_VALVE_DEVICE_TYPE_ID = 0x0042
7474

7575
common_utils.device_type_profile_map = {
7676
[common_utils.ON_OFF_LIGHT_DEVICE_TYPE_ID] = "light-binary",
@@ -79,14 +79,14 @@ common_utils.device_type_profile_map = {
7979
[common_utils.EXTENDED_COLOR_LIGHT_DEVICE_TYPE_ID] = "light-color-level",
8080
[common_utils.ON_OFF_PLUG_DEVICE_TYPE_ID] = "plug-binary",
8181
[common_utils.DIMMABLE_PLUG_DEVICE_TYPE_ID] = "plug-level",
82-
[common_utils.ON_OFF_SWITCH_ID] = "switch-binary",
83-
[common_utils.ON_OFF_DIMMER_SWITCH_ID] = "switch-level",
84-
[common_utils.ON_OFF_COLOR_DIMMER_SWITCH_ID] = "switch-color-level",
85-
[common_utils.MOUNTED_ON_OFF_CONTROL_ID] = "switch-binary",
86-
[common_utils.MOUNTED_DIMMABLE_LOAD_CONTROL_ID] = "switch-level",
82+
[common_utils.ON_OFF_SWITCH_DEVICE_TYPE_ID] = "switch-binary",
83+
[common_utils.ON_OFF_DIMMER_SWITCH_DEVICE_TYPE_ID] = "switch-level",
84+
[common_utils.ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID] = "switch-color-level",
85+
[common_utils.MOUNTED_ON_OFF_CONTROL_DEVICE_TYPE_ID] = "switch-binary",
86+
[common_utils.MOUNTED_DIMMABLE_LOAD_CONTROL_DEVICE_TYPE_ID] = "switch-level",
8787
}
8888

89-
common_utils.device_type_attribute_map = {
89+
local device_type_attribute_map = {
9090
[common_utils.ON_OFF_LIGHT_DEVICE_TYPE_ID] = {
9191
clusters.OnOff.attributes.OnOff
9292
},
@@ -127,16 +127,16 @@ common_utils.device_type_attribute_map = {
127127
clusters.LevelControl.attributes.MaxLevel,
128128
clusters.LevelControl.attributes.MinLevel
129129
},
130-
[common_utils.ON_OFF_SWITCH_ID] = {
130+
[common_utils.ON_OFF_SWITCH_DEVICE_TYPE_ID] = {
131131
clusters.OnOff.attributes.OnOff
132132
},
133-
[common_utils.ON_OFF_DIMMER_SWITCH_ID] = {
133+
[common_utils.ON_OFF_DIMMER_SWITCH_DEVICE_TYPE_ID] = {
134134
clusters.OnOff.attributes.OnOff,
135135
clusters.LevelControl.attributes.CurrentLevel,
136136
clusters.LevelControl.attributes.MaxLevel,
137137
clusters.LevelControl.attributes.MinLevel
138138
},
139-
[common_utils.ON_OFF_COLOR_DIMMER_SWITCH_ID] = {
139+
[common_utils.ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID] = {
140140
clusters.OnOff.attributes.OnOff,
141141
clusters.LevelControl.attributes.CurrentLevel,
142142
clusters.LevelControl.attributes.MaxLevel,
@@ -149,14 +149,14 @@ common_utils.device_type_attribute_map = {
149149
clusters.ColorControl.attributes.CurrentX,
150150
clusters.ColorControl.attributes.CurrentY
151151
},
152-
[common_utils.GENERIC_SWITCH_ID] = {
152+
[common_utils.GENERIC_SWITCH_DEVICE_TYPE_ID] = {
153153
clusters.PowerSource.attributes.BatPercentRemaining,
154154
clusters.Switch.events.InitialPress,
155155
clusters.Switch.events.LongPress,
156156
clusters.Switch.events.ShortRelease,
157157
clusters.Switch.events.MultiPressComplete
158158
},
159-
[common_utils.ELECTRICAL_SENSOR_ID] = {
159+
[common_utils.ELECTRICAL_SENSOR_DEVICE_TYPE_ID] = {
160160
clusters.ElectricalPowerMeasurement.attributes.ActivePower,
161161
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported,
162162
clusters.ElectricalEnergyMeasurement.attributes.PeriodicEnergyImported
@@ -185,7 +185,7 @@ common_utils.battery_support = {
185185
BATTERY_PERCENTAGE = "BATTERY_PERCENTAGE"
186186
}
187187

188-
common_utils.updated_fields = {
188+
local updated_fields = {
189189
{ current_field_name = "__component_to_endpoint_map_button", updated_field_name = common_utils.COMPONENT_TO_ENDPOINT_MAP },
190190
{ current_field_name = "__switch_intialized", updated_field_name = nil }
191191
}
@@ -205,13 +205,13 @@ local device_type_category_map = {
205205
[common_utils.EXTENDED_COLOR_LIGHT_DEVICE_TYPE_ID] = common_utils.device_categories.LIGHT,
206206
[common_utils.ON_OFF_PLUG_DEVICE_TYPE_ID] = common_utils.device_categories.PLUG,
207207
[common_utils.DIMMABLE_PLUG_DEVICE_TYPE_ID] = common_utils.device_categories.PLUG,
208-
[common_utils.ON_OFF_SWITCH_ID] = common_utils.device_categories.SWITCH,
209-
[common_utils.ON_OFF_DIMMER_SWITCH_ID] = common_utils.device_categories.SWITCH,
210-
[common_utils.ON_OFF_COLOR_DIMMER_SWITCH_ID] = common_utils.device_categories.SWITCH,
211-
[common_utils.MOUNTED_ON_OFF_CONTROL_ID] = common_utils.device_categories.SWITCH,
212-
[common_utils.MOUNTED_DIMMABLE_LOAD_CONTROL_ID] = common_utils.device_categories.SWITCH,
213-
[common_utils.GENERIC_SWITCH_ID] = common_utils.device_categories.BUTTON,
214-
[common_utils.WATER_VALVE_ID] = common_utils.device_categories.WATER_VALVE
208+
[common_utils.ON_OFF_SWITCH_DEVICE_TYPE_ID] = common_utils.device_categories.SWITCH,
209+
[common_utils.ON_OFF_DIMMER_SWITCH_DEVICE_TYPE_ID] = common_utils.device_categories.SWITCH,
210+
[common_utils.ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID] = common_utils.device_categories.SWITCH,
211+
[common_utils.MOUNTED_ON_OFF_CONTROL_DEVICE_TYPE_ID] = common_utils.device_categories.SWITCH,
212+
[common_utils.MOUNTED_DIMMABLE_LOAD_CONTROL_DEVICE_TYPE_ID] = common_utils.device_categories.SWITCH,
213+
[common_utils.GENERIC_SWITCH_DEVICE_TYPE_ID] = common_utils.device_categories.BUTTON,
214+
[common_utils.WATER_VALVE_DEVICE_TYPE_ID] = common_utils.device_categories.WATER_VALVE
215215
}
216216

217217
function common_utils.get_first_non_zero_endpoint(endpoints)
@@ -315,10 +315,7 @@ function common_utils.get_device_category(device, main_endpoint)
315315
end
316316

317317
local function supports_modular_profile(device)
318-
local modular_profiles_supported = version.api >= 14 and version.rpc >= 8 and
319-
not (device.manufacturer_info and
320-
device.manufacturer_info.vendor_id == common_utils.AQARA_MANUFACTURER_ID and
321-
device.manufacturer_info.product_id == common_utils.AQARA_CLIMATE_SENSOR_W100_ID)
318+
local modular_profiles_supported = version.api >= 14 and version.rpc >= 8
322319
if not modular_profiles_supported then
323320
device:set_field(SUPPORTS_MODULAR_PROFILE, false)
324321
return false
@@ -366,7 +363,7 @@ function common_utils.detect_bridge(device)
366363
end
367364

368365
function common_utils.check_field_name_updates(device)
369-
for _, field in ipairs(common_utils.updated_fields) do
366+
for _, field in ipairs(updated_fields) do
370367
if device:get_field(field.current_field_name) then
371368
if field.updated_field_name ~= nil then
372369
device:set_field(field.updated_field_name, device:get_field(field.current_field_name), {persist = true})
@@ -443,8 +440,8 @@ function common_utils.add_subscribed_attributes_and_events(device, main_endpoint
443440
for _, dt in ipairs(ep.device_types) do
444441
id = math.max(id, dt.device_type_id)
445442
end
446-
for _, attr in pairs(common_utils.device_type_attribute_map[id] or {}) do
447-
if id == common_utils.GENERIC_SWITCH_ID and
443+
for _, attr in pairs(device_type_attribute_map[id] or {}) do
444+
if id == common_utils.GENERIC_SWITCH_DEVICE_TYPE_ID and
448445
attr ~= clusters.PowerSource.attributes.BatPercentRemaining and
449446
attr ~= clusters.PowerSource.attributes.BatChargeLevel then
450447
device:add_subscribed_event(attr)

drivers/SmartThings/matter-switch/src/modular-profiles-utils.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ local profile_name_and_mandatory_capability_per_device_category = {
2525
[common_utils.device_categories.BUTTON] = { profile_name = "button-modular", mandatory_capability = capabilities.button.ID },
2626
[common_utils.device_categories.LIGHT] = { profile_name = "light-modular", mandatory_capability = capabilities.switch.ID },
2727
[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 },
29-
[common_utils.device_categories.WATER_VALVE] = { profile_name = "water-valve-modular", mandatory_capability = capabilities.switch.ID }
28+
[common_utils.device_categories.SWITCH] = { profile_name = "switch-modular", mandatory_capability = capabilities.switch.ID },
29+
[common_utils.device_categories.WATER_VALVE] = { profile_name = "water-valve-modular", mandatory_capability = capabilities.valve.ID }
3030
}
3131

3232
local function supports_capability_by_id_modular(device, capability, component)
@@ -88,7 +88,7 @@ local function handle_light_switch_with_onOff_server_clusters(device, main_endpo
8888
if main_endpoint == ep.endpoint_id then
8989
for _, dt in ipairs(ep.device_types) do
9090
-- No device type that is not in the switch subset should be considered
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
91+
if (common_utils.ON_OFF_SWITCH_DEVICE_TYPE_ID <= dt.device_type_id and dt.device_type_id <= common_utils.ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID) then
9292
device_type_id = math.max(device_type_id, dt.device_type_id)
9393
end
9494
end
@@ -97,14 +97,14 @@ local function handle_light_switch_with_onOff_server_clusters(device, main_endpo
9797
end
9898
if device_type_id == 0 then return end
9999
local capabilities_to_remove = {}
100-
if device_type_id == common_utils.ON_OFF_SWITCH_ID then
100+
if device_type_id == common_utils.ON_OFF_SWITCH_DEVICE_TYPE_ID then
101101
capabilities_to_remove = {capabilities.colorControl.ID, capabilities.colorTemperature.ID, capabilities.switchLevel.ID}
102-
elseif device_type_id == common_utils.ON_OFF_DIMMER_SWITCH_ID then
102+
elseif device_type_id == common_utils.ON_OFF_DIMMER_SWITCH_DEVICE_TYPE_ID then
103103
capabilities_to_remove = {capabilities.colorControl.ID, capabilities.colorTemperature.ID}
104104
if not common_utils.tbl_contains(component_capabilities, capabilities.switchLevel.ID) then
105105
table.insert(component_capabilities, capabilities.switchLevel.ID)
106106
end
107-
else -- device_type_id = ON_OFF_COLOR_DIMMER_SWITCH_ID
107+
else -- device_type_id = ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID
108108
if not common_utils.tbl_contains(component_capabilities, capabilities.switchLevel.ID) then
109109
table.insert(component_capabilities, capabilities.switchLevel.ID)
110110
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ local function handle_light_switch_with_onOff_server_clusters(device, main_endpo
6464
if main_endpoint == ep.endpoint_id then
6565
for _, dt in ipairs(ep.device_types) do
6666
-- No device type that is not in the switch subset should be considered.
67-
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
67+
if (common_utils.ON_OFF_SWITCH_DEVICE_TYPE_ID <= dt.device_type_id and dt.device_type_id <= common_utils.ON_OFF_COLOR_DIMMER_SWITCH_DEVICE_TYPE_ID) then
6868
cluster_id = math.max(cluster_id, dt.device_type_id)
6969
end
7070
end

0 commit comments

Comments
 (0)