Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,13 @@ local function profile_changed(latest_profile, previous_profile)
if prev_component == nil then
return true
end
if #synced_component.capabilities ~= #prev_component.capabilities then
return true
end
-- Build a table of capability IDs from the previous component. Then, use this map to check
-- that all capabilities in the synced component existed in the previous component.
local prev_cap_ids = {}
for _, capability in ipairs(prev_component.capabilities or {}) do
for _, capability in pairs(prev_component.capabilities or {}) do
prev_cap_ids[capability.id] = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Since component.capabilities are already keyed by capability ID, I don't think we need to build up the new table but I don't think we need to change it if it has already been tested as is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think I did this to try and be clever. The idea was that I loop through this once and make the table, so now when I loop through the other list I just check in O(1) if the key exists, therefore making this a O(n) + O(n) operation rather than O(n^2).

Of course, we're talking a speed up on max 10 values so this is likely slowing things down or doing nothing at all.

end
for _, capability in ipairs(synced_component.capabilities or {}) do
for _, capability in pairs(synced_component.capabilities or {}) do
if not prev_cap_ids[capability.id] then
return true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,13 @@ function AirQualitySensorUtils.profile_changed(latest_profile, previous_profile)
if prev_component == nil then
return true
end
if #synced_component.capabilities ~= #prev_component.capabilities then
return true
end
-- Build a table of capability IDs from the previous component. Then, use this map to check
-- that all capabilities in the synced component existed in the previous component.
local prev_cap_ids = {}
for _, capability in ipairs(prev_component.capabilities or {}) do
for _, capability in pairs(prev_component.capabilities or {}) do
prev_cap_ids[capability.id] = true
end
for _, capability in ipairs(synced_component.capabilities or {}) do
for _, capability in pairs(synced_component.capabilities or {}) do
if not prev_cap_ids[capability.id] then
return true
end
Expand Down
7 changes: 2 additions & 5 deletions drivers/SmartThings/matter-switch/src/switch_utils/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,13 @@ function utils.profile_changed(latest_profile, previous_profile)
if prev_component == nil then
return true
end
if #synced_component.capabilities ~= #prev_component.capabilities then
return true
end
-- Build a table of capability IDs from the previous component. Then, use this map to check
-- that all capabilities in the synced component existed in the previous component.
local prev_cap_ids = {}
for _, capability in ipairs(prev_component.capabilities or {}) do
for _, capability in pairs(prev_component.capabilities or {}) do
prev_cap_ids[capability.id] = true
end
for _, capability in ipairs(synced_component.capabilities or {}) do
for _, capability in pairs(synced_component.capabilities or {}) do
if not prev_cap_ids[capability.id] then
return true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ test.register_coroutine_test(
if i > 1 then subscribe_request:merge(clus:subscribe(mock_device_capabilities_disabled)) end
end
test.socket.device_lifecycle:__queue_receive(mock_device_capabilities_disabled:generate_info_changed(
{profile = {id = "00000000-1111-2222-3333-000000000004", components = { main = {capabilities={{id="fanSpeedPercent", version=1}, {id="fanMode", version=1}, {id="firmwareUpdate", version=1}, {id="refresh", version=1}}}}}})
{profile = {id = "00000000-1111-2222-3333-000000000004", components = { main = {capabilities={["fanSpeedPercent"] = {id="fanSpeedPercent", version=1}, ["fanMode"] = {id="fanMode", version=1}, ["firmwareUpdate"] = {id="firmwareUpdate", version=1}, ["refresh"] = {id="refresh", version=1}}}}}})
)
test.socket.matter:__expect_send({mock_device_capabilities_disabled.id, subscribe_request})
end,
Expand All @@ -180,7 +180,7 @@ test.register_coroutine_test(
if i > 1 then subscribe_request:merge(clus:subscribe(mock_device_capabilities_disabled)) end
end
test.socket.device_lifecycle:__queue_receive(mock_device_capabilities_disabled:generate_info_changed(
{profile = {id = "00000000-1111-2222-3333-000000000004", components = { main = {capabilities={{id="firmwareUpdate", version=1}, {id="refresh", version=1}}}}}})
{profile = {id = "00000000-1111-2222-3333-000000000004", components = { main = {capabilities={["firmwareUpdate"] = {id="firmwareUpdate", version=1}, ["refresh"] = {id="refresh", version=1}}}}}})
)
end,
{ test_init = function() test.mock_device.add_test_device(mock_device_capabilities_disabled) end }
Expand Down
Loading