Skip to content

Commit 38f240f

Browse files
committed
include switch override logic
1 parent da4a05f commit 38f240f

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

drivers/SmartThings/matter-switch/src/test/test_multi_switch_parent_child_plugs.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ local function test_init_child_profile_override()
197197
test.socket.matter:__expect_send({mock_device_child_profile_override.id, subscribe_request})
198198

199199
test.socket.device_lifecycle:__queue_receive({ mock_device_child_profile_override.id, "doConfigure" })
200-
mock_device_child_profile_override:expect_metadata_update({ profile = "plug-binary" })
200+
mock_device_child_profile_override:expect_metadata_update({ profile = "switch-binary" })
201201
mock_device_child_profile_override:expect_metadata_update({ provisioning_state = "PROVISIONED" })
202202

203203
for _, child in pairs(mock_children_child_profile_override) do

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,22 @@ function DeviceConfiguration.match_profile(driver, device)
182182
if #server_onoff_ep_ids > 0 then
183183
SwitchDeviceConfiguration.create_child_devices(driver, device, server_onoff_ep_ids, main_endpoint_id)
184184
updated_profile = SwitchDeviceConfiguration.assign_profile_for_onoff_ep(device, main_endpoint_id)
185-
local find_substr = function(s, p) return string.find(s or "", p, 1, true) end
186-
187-
if find_substr(updated_profile, "plug-binary") or find_substr(updated_profile, "plug-level") then
188-
local electrical_tags = ""
189-
if #embedded_cluster_utils.get_endpoints(device, clusters.ElectricalPowerMeasurement.ID) > 0 then electrical_tags = electrical_tags .. "-power" end
190-
if #embedded_cluster_utils.get_endpoints(device, clusters.ElectricalEnergyMeasurement.ID) > 0 then electrical_tags = electrical_tags .. "-energy-powerConsumption" end
191-
if electrical_tags ~= "" then updated_profile = string.gsub(updated_profile, "-binary", "") .. electrical_tags end
192-
elseif find_substr(updated_profile, "light-color-level") and #device:get_endpoints(clusters.FanControl.ID) > 0 then
185+
local generic_profile = function(s) return string.find(updated_profile or "", s, 1, true) end
186+
187+
if generic_profile("plug-binary") or generic_profile("plug-level") then
188+
if switch_utils.check_switch_category_vendor_overrides(device) then
189+
updated_profile = string.gsub(updated_profile, "plug", "switch")
190+
else
191+
local electrical_tags = ""
192+
if #embedded_cluster_utils.get_endpoints(device, clusters.ElectricalPowerMeasurement.ID) > 0 then electrical_tags = electrical_tags .. "-power" end
193+
if #embedded_cluster_utils.get_endpoints(device, clusters.ElectricalEnergyMeasurement.ID) > 0 then electrical_tags = electrical_tags .. "-energy-powerConsumption" end
194+
if electrical_tags ~= "" then updated_profile = string.gsub(updated_profile, "-binary", "") .. electrical_tags end
195+
end
196+
elseif generic_profile("light-color-level") and #device:get_endpoints(clusters.FanControl.ID) > 0 then
193197
updated_profile = "light-color-level-fan"
194-
elseif find_substr(updated_profile, "light-level") and #device:get_endpoints(clusters.OccupancySensing.ID) > 0 then
198+
elseif generic_profile("light-level") and #device:get_endpoints(clusters.OccupancySensing.ID) > 0 then
195199
updated_profile = "light-level-motion"
196-
elseif find_substr(updated_profile, "light-level-colorTemperature") or find_substr(updated_profile, "light-color-level") then
200+
elseif generic_profile("light-level-colorTemperature") or generic_profile("light-color-level") then
197201
-- ignore attempts to dynamically profile light-level-colorTemperature and light-color-level devices for now, since
198202
-- these may lose fingerprinted Kelvin ranges when dynamically profiled.
199203
return

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,32 @@ SwitchFields.child_device_profile_overrides_per_vendor_id = {
123123
{ product_id = 0x1008, target_profile = "light-power-energy-powerConsumption" }, -- 2 Buttons(Generic Switch), 1 Channel(On/Off Light)
124124
{ product_id = 0x1009, target_profile = "light-power-energy-powerConsumption" }, -- 4 Buttons(Generic Switch), 2 Channels(On/Off Light)
125125
{ product_id = 0x100A, target_profile = "light-level-power-energy-powerConsumption" }, -- 1 Buttons(Generic Switch), 1 Channels(Dimmable Light)
126-
}
126+
},
127+
}
128+
129+
SwitchFields.switch_category_vendor_overrides = {
130+
[0x1432] = -- Elko
131+
{0x1000},
132+
[0x130A] = -- Eve
133+
{0x005D, 0x0043},
134+
[0x1339] = -- GE
135+
{0x007D, 0x0074, 0x0075},
136+
[0x1372] = -- Innovation Matters
137+
{0x0002},
138+
[0x1021] = -- Legrand
139+
{0x0005},
140+
[0x109B] = -- Leviton
141+
{0x1001, 0x1000, 0x100B, 0x100E, 0x100C, 0x100D, 0x1009, 0x1003, 0x1004, 0x1002},
142+
[0x142B] = -- LeTianPai
143+
{0x1004, 0x1003, 0x1002},
144+
[0x1509] = -- SmartSetup
145+
{0x0004, 0x0001},
146+
[0x1321] = -- SONOFF
147+
{0x000B, 0x000C, 0x000D},
148+
[0x147F] = -- U-Tec
149+
{0x0004},
150+
[0x139C] = -- Zemismart
151+
{0xEEE2, 0xAB08, 0xAB31, 0xAB04, 0xAB01, 0xAB43, 0xAB02, 0xAB03, 0xAB05}
127152
}
128153

129154
SwitchFields.CUMULATIVE_REPORTS_NOT_SUPPORTED = "__cumulative_reports_not_supported"

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ function utils.check_field_name_updates(device)
7575
end
7676
end
7777

78+
function utils.check_switch_category_vendor_overrides(device)
79+
for _, product_id in ipairs(fields.switch_category_vendor_overrides[device.manufacturer_info.vendor_id] or {}) do
80+
if device.manufacturer_info.product_id == product_id then
81+
return true
82+
end
83+
end
84+
end
85+
7886
--- device_type_supports_button_switch_combination helper function used to check
7987
--- whether the device type for an endpoint is currently supported by a profile for
8088
--- combination button/switch devices.

0 commit comments

Comments
 (0)