Skip to content

Commit 6130969

Browse files
committed
Clean up info changed handling
1 parent 37c73da commit 6130969

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

drivers/SmartThings/matter-thermostat/src/init.lua

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -501,24 +501,14 @@ local function device_init(driver, device)
501501
end
502502

503503
local function info_changed(driver, device, event, args)
504-
-- Note this is needed because device:subscribe() does not recalculate
505-
-- the subscribed attributes each time it is run, that only happens at init.
506-
-- This will change in the 0.48.x release of the lua libs.
507-
for cap_id, attributes in pairs(subscribed_attributes) do
508-
if device:supports_capability_by_id(cap_id) then
509-
for _, attr in ipairs(attributes) do
510-
device:add_subscribed_attribute(attr)
511-
end
512-
end
504+
if device:get_field(SUPPORTED_COMPONENT_CAPABILITIES) then
505+
--re-up subscription with new capabilities using the modular supports_capability override
506+
device:extend_device("supports_capability_by_id", supports_capability_by_id_modular)
513507
end
514508

515509
if device.profile.id ~= args.old_st_store.profile.id then
516-
if device:get_field(SUPPORTED_COMPONENT_CAPABILITIES) then
517-
--re-up subscription with new capabilities using the modular supports_capability override
518-
device:extend_device("supports_capability_by_id", supports_capability_by_id_modular)
519-
end
510+
device:subscribe()
520511
end
521-
device:subscribe()
522512
schedule_polls_for_cumulative_energy_imported(device)
523513
end
524514

drivers/SmartThings/matter-thermostat/src/test/test_matter_thermo_featuremap.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,12 @@ test.register_coroutine_test(
253253
end
254254
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
255255

256-
test.socket.device_lifecycle:__queue_receive(mock_device:generate_info_changed({}))
256+
local updates = {
257+
profile = {
258+
id = "new-profile"
259+
}
260+
}
261+
test.socket.device_lifecycle:__queue_receive(mock_device:generate_info_changed(updates))
257262
end
258263
)
259264

0 commit comments

Comments
 (0)