Skip to content

Commit 73aa8dc

Browse files
committed
Add greater dynamic profiling to matter switch
1 parent 9331e5d commit 73aa8dc

File tree

9 files changed

+219
-190
lines changed

9 files changed

+219
-190
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ function SwitchLifecycleHandlers.device_init(driver, device)
8585
if device:get_field(fields.IS_PARENT_CHILD_DEVICE) then
8686
device:set_find_child(switch_utils.find_child)
8787
end
88-
local main_endpoint = switch_utils.find_default_endpoint(device)
88+
local default_endpoint_id = switch_utils.find_default_endpoint(device)
8989
-- ensure subscription to all endpoint attributes- including those mapped to child devices
9090
for idx, ep in ipairs(device.endpoints) do
91-
if ep.endpoint_id ~= main_endpoint then
91+
if ep.endpoint_id ~= default_endpoint_id then
9292
if device:supports_server_cluster(clusters.OnOff.ID, ep) then
9393
local child_profile = switch_cfg.assign_child_profile(device, ep)
9494
if idx == 1 and string.find(child_profile, "energy") then
@@ -101,7 +101,7 @@ function SwitchLifecycleHandlers.device_init(driver, device)
101101
id = math.max(id, dt.device_type_id)
102102
end
103103
for _, attr in pairs(fields.device_type_attribute_map[id] or {}) do
104-
if id == fields.GENERIC_SWITCH_ID and
104+
if id == fields.DEVICE_TYPE_ID.GENERIC_SWITCH and
105105
attr ~= clusters.PowerSource.attributes.BatPercentRemaining and
106106
attr ~= clusters.PowerSource.attributes.BatChargeLevel then
107107
device:add_subscribed_event(attr)

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ if version.api < 11 then
2727
clusters.PowerTopology = require "embedded_clusters.PowerTopology"
2828
end
2929

30-
if version.api < 16 then
31-
clusters.Descriptor = require "embedded_clusters.Descriptor"
32-
end
33-
3430
local aqara_parent_ep = 4
3531
local aqara_child1_ep = 1
3632
local aqara_child2_ep = 2

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ local mock_device = test.mock_device.build_test_matter_device({
5656
{cluster_id = clusters.LevelControl.ID, cluster_type = "SERVER", feature_map = 2}
5757
},
5858
device_types = {
59-
{ device_type_id = 0x010A, device_type_revision = 1 } -- OnOff Plug
59+
{ device_type_id = 0x010B, device_type_revision = 1 }, -- Dimmable Plug In Unit
6060
}
6161
}
6262
},
@@ -88,10 +88,20 @@ local mock_device_periodic = test.mock_device.build_test_matter_device({
8888
{ device_type_id = 0x0510, device_type_revision = 1 } -- Electrical Sensor
8989
}
9090
},
91+
{
92+
endpoint_id = 2,
93+
clusters = {
94+
{ cluster_id = clusters.OnOff.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 0, },
95+
},
96+
device_types = {
97+
{ device_type_id = 0x010A, device_type_revision = 1 }, -- On Off Plug In Unit
98+
}
99+
}
91100
},
92101
})
93102

94103
local subscribed_attributes_periodic = {
104+
clusters.OnOff.attributes.OnOff,
95105
clusters.ElectricalEnergyMeasurement.attributes.PeriodicEnergyImported,
96106
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported,
97107
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ local function test_init_mounted_on_off_control()
505505
test.socket.matter:__expect_send({mock_device_mounted_on_off_control.id, subscribe_request})
506506

507507
test.socket.device_lifecycle:__queue_receive({ mock_device_mounted_on_off_control.id, "doConfigure" })
508+
mock_device_mounted_on_off_control:expect_metadata_update({ profile = "switch-binary" })
508509
mock_device_mounted_on_off_control:expect_metadata_update({ provisioning_state = "PROVISIONED" })
509510
end
510511

@@ -526,6 +527,7 @@ local function test_init_mounted_dimmable_load_control()
526527
test.socket.matter:__expect_send({mock_device_mounted_dimmable_load_control.id, subscribe_request})
527528

528529
test.socket.device_lifecycle:__queue_receive({ mock_device_mounted_dimmable_load_control.id, "doConfigure" })
530+
mock_device_mounted_dimmable_load_control:expect_metadata_update({ profile = "switch-level" })
529531
mock_device_mounted_dimmable_load_control:expect_metadata_update({ provisioning_state = "PROVISIONED" })
530532
end
531533

@@ -566,6 +568,7 @@ local function test_init_parent_child_different_types()
566568
test.socket.matter:__expect_send({mock_device_parent_child_different_types.id, subscribe_request})
567569

568570
test.socket.device_lifecycle:__queue_receive({ mock_device_parent_child_different_types.id, "doConfigure" })
571+
mock_device_parent_child_different_types:expect_metadata_update({ profile = "switch-binary" })
569572
mock_device_parent_child_different_types:expect_metadata_update({ provisioning_state = "PROVISIONED" })
570573

571574
mock_device_parent_child_different_types:expect_device_create({
@@ -617,6 +620,7 @@ local function test_init_light_level_motion()
617620
test.socket.matter:__expect_send({mock_device_light_level_motion.id, subscribe_request})
618621

619622
test.socket.device_lifecycle:__queue_receive({ mock_device_light_level_motion.id, "doConfigure" })
623+
mock_device_light_level_motion:expect_metadata_update({ profile = "light-level-motion" })
620624
mock_device_light_level_motion:expect_metadata_update({ provisioning_state = "PROVISIONED" })
621625
end
622626

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ local function test_init()
189189
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
190190

191191
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
192+
mock_device:expect_metadata_update({ profile = "light-binary" })
192193
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
193194

194195
for _, child in pairs(mock_children) do
@@ -260,6 +261,7 @@ local function test_init_parent_child_endpoints_non_sequential()
260261
test.socket.matter:__expect_send({mock_device_parent_child_endpoints_non_sequential.id, subscribe_request})
261262

262263
test.socket.device_lifecycle:__queue_receive({ mock_device_parent_child_endpoints_non_sequential.id, "doConfigure" })
264+
mock_device_parent_child_endpoints_non_sequential:expect_metadata_update({ profile = "light-binary" })
263265
mock_device_parent_child_endpoints_non_sequential:expect_metadata_update({ provisioning_state = "PROVISIONED" })
264266

265267
for _, child in pairs(mock_children_non_sequential) do

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ local function test_init()
146146
test.socket.matter:__expect_send({mock_device.id, subscribe_request})
147147

148148
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
149+
mock_device:expect_metadata_update({ profile = "plug-binary" })
149150
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
150151

151152
for _, child in pairs(mock_children) do
@@ -196,6 +197,7 @@ local function test_init_child_profile_override()
196197
test.socket.matter:__expect_send({mock_device_child_profile_override.id, subscribe_request})
197198

198199
test.socket.device_lifecycle:__queue_receive({ mock_device_child_profile_override.id, "doConfigure" })
200+
mock_device_child_profile_override:expect_metadata_update({ profile = "switch-binary" })
199201
mock_device_child_profile_override:expect_metadata_update({ provisioning_state = "PROVISIONED" })
200202

201203
for _, child in pairs(mock_children_child_profile_override) do

0 commit comments

Comments
 (0)