Skip to content
Open
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
356 changes: 225 additions & 131 deletions drivers/SmartThings/matter-switch/src/init.lua

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ local aqara_mock_device = test.mock_device.build_test_matter_device({
clusters = {
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"},
{cluster_id = clusters.ElectricalPowerMeasurement.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 2 },
{cluster_id = clusters.ElectricalEnergyMeasurement.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 5 }
{cluster_id = clusters.ElectricalEnergyMeasurement.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 5 },
{cluster_id = clusters.PowerTopology.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 1 } -- NODE_TOPOLOGY
},
device_types = {
{device_type_id = 0x0016, device_type_revision = 1}, -- RootNode
Expand Down Expand Up @@ -271,21 +272,20 @@ test.register_coroutine_test(
function()
test.socket.matter:__queue_receive(
{
-- don't use "aqara_mock_children[aqara_child1_ep].id,"
-- because energy management is at the root endpoint.
aqara_mock_device.id,
aqara_mock_children[aqara_child1_ep].id,
clusters.ElectricalPowerMeasurement.attributes.ActivePower:build_test_report_data(aqara_mock_device, 1, 17000)
}
)

test.socket.capability:__expect_send(
-- when energy management is in the root endpoint, the event is sent to the first switch endpoint in CHILD_EDGE.
aqara_mock_children[aqara_child1_ep]:generate_test_message("main", capabilities.powerMeter.power({value = 17.0, unit="W"}))
)

aqara_mock_children[aqara_child1_ep]:expect_native_attr_handler_registration("powerMeter", "power")

test.socket.matter:__queue_receive(
{
aqara_mock_device.id,
aqara_mock_children[aqara_child1_ep].id,
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported:build_test_report_data(aqara_mock_device, 1, cumulative_report_val_19)
}
)
Expand All @@ -298,7 +298,7 @@ test.register_coroutine_test(
-- This is because related variable settings are required in set_poll_report_timer_and_schedule().
test.socket.matter:__queue_receive(
{
aqara_mock_device.id,
aqara_mock_children[aqara_child1_ep].id,
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported:build_test_report_data(aqara_mock_device, 1, cumulative_report_val_29)
}
)
Expand All @@ -309,10 +309,8 @@ test.register_coroutine_test(

test.socket.matter:__queue_receive(
{
aqara_mock_device.id,
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported:build_test_report_data(
aqara_mock_device, 1, cumulative_report_val_39
)
aqara_mock_children[aqara_child1_ep].id,
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported:build_test_report_data(aqara_mock_device, 1, cumulative_report_val_39)
}
)

Expand All @@ -334,4 +332,3 @@ test.register_coroutine_test(
)

test.run_registered_tests()

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local test = require "integration_test"
local capabilities = require "st.capabilities"
local clusters = require "st.matter.clusters"
local t_utils = require "integration_test.utils"
local uint32 = require "st.matter.data_types.Uint32"
local version = require "version"

if version.api < 11 then
Expand Down Expand Up @@ -44,6 +45,7 @@ local mock_device = test.mock_device.build_test_matter_device({
clusters = {
{ cluster_id = clusters.ElectricalEnergyMeasurement.ID, cluster_type = "SERVER", feature_map = 14, },
{ cluster_id = clusters.ElectricalPowerMeasurement.ID, cluster_type = "SERVER", feature_map = 0, },
{ cluster_id = clusters.PowerTopology.ID, cluster_type = "SERVER", feature_map = 4, }, -- SET_TOPOLOGY
},
device_types = {
{ device_type_id = 0x0510, device_type_revision = 1 }, -- Electrical Sensor
Expand All @@ -56,9 +58,29 @@ local mock_device = test.mock_device.build_test_matter_device({
{cluster_id = clusters.LevelControl.ID, cluster_type = "SERVER", feature_map = 2}
},
device_types = {
{ device_type_id = 0x010A, device_type_revision = 1 } -- OnOff Plug
{ device_type_id = 0x010B, device_type_revision = 1 }, -- OnOff Dimmable Plug
}
}
},
{
endpoint_id = 3,
clusters = {
{ cluster_id = clusters.ElectricalEnergyMeasurement.ID, cluster_type = "SERVER", feature_map = 14, },
{ cluster_id = clusters.PowerTopology.ID, cluster_type = "SERVER", feature_map = 4, }, -- SET_TOPOLOGY
},
device_types = {
{ device_type_id = 0x0510, device_type_revision = 1 }, -- Electrical Sensor
}
},
{
endpoint_id = 4,
clusters = {
{ cluster_id = clusters.OnOff.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 0, },
{ cluster_id = clusters.LevelControl.ID, cluster_type = "SERVER", feature_map = 2},
},
device_types = {
{ device_type_id = 0x010B, device_type_revision = 1 }, -- OnOff Dimmable Plug }
}
},
},
})

Expand All @@ -82,16 +104,20 @@ local mock_device_periodic = test.mock_device.build_test_matter_device({
{
endpoint_id = 1,
clusters = {
{ cluster_id = clusters.OnOff.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 0, },
{ cluster_id = clusters.ElectricalEnergyMeasurement.ID, cluster_type = "SERVER", feature_map = 10, },
{ cluster_id = clusters.PowerTopology.ID, cluster_type = "SERVER", feature_map = 4, } -- SET_TOPOLOGY
},
device_types = {
{ device_type_id = 0x0510, device_type_revision = 1 } -- Electrical Sensor
{ device_type_id = 0x010A, device_type_revision = 1 }, -- OnOff Plug
{ device_type_id = 0x0510, device_type_revision = 1 }, -- Electrical Sensor
}
},
},
})

local subscribed_attributes_periodic = {
clusters.OnOff.attributes.OnOff,
clusters.ElectricalEnergyMeasurement.attributes.PeriodicEnergyImported,
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported,
}
Expand Down Expand Up @@ -653,19 +679,52 @@ test.register_coroutine_test(
test.register_coroutine_test(
"Test profile change on init for Electrical Sensor device type",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" })
local read_req = clusters.PowerTopology.attributes.AvailableEndpoints:read(mock_device.id, 1)
read_req:merge(clusters.PowerTopology.attributes.AvailableEndpoints:read(mock_device.id, 3))
test.socket.matter:__expect_send({ mock_device.id, read_req })
local subscribe_request = subscribed_attributes[1]:subscribe(mock_device)
for i, cluster in ipairs(subscribed_attributes) do
if i > 1 then
subscribe_request:merge(cluster:subscribe(mock_device))
end
end
test.socket.matter:__expect_send({ mock_device.id, subscribe_request })
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" })
mock_device:expect_metadata_update({ profile = "plug-level-power-energy-powerConsumption" })
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" })
test.wait_for_events()
test.socket.matter:__queue_receive({ mock_device.id, clusters.PowerTopology.attributes.AvailableEndpoints:build_test_report_data(mock_device, 1, {uint32(2)})})
test.socket.matter:__queue_receive({ mock_device.id, clusters.PowerTopology.attributes.AvailableEndpoints:build_test_report_data(mock_device, 3, {uint32(4)})})
mock_device:expect_metadata_update({ profile = "plug-level-power-energy-powerConsumption" })
mock_device:expect_device_create({
type = "EDGE_CHILD",
label = "nil 2",
profile = "plug-level-energy-powerConsumption",
parent_device_id = mock_device.id,
parent_assigned_child_key = string.format("%d", 4)
})
end,
{ test_init = test_init }
)

test.register_coroutine_test(
"Test profile change on init for only Periodic Electrical Sensor device type",
function()
test.socket.device_lifecycle:__queue_receive({ mock_device_periodic.id, "added" })
local read_req = clusters.PowerTopology.attributes.AvailableEndpoints:read(mock_device_periodic.id, 1)
test.socket.matter:__expect_send({ mock_device_periodic.id, read_req })
local subscribe_request = subscribed_attributes_periodic[1]:subscribe(mock_device_periodic)
for i, cluster in ipairs(subscribed_attributes_periodic) do
if i > 1 then
subscribe_request:merge(cluster:subscribe(mock_device_periodic))
end
end
test.socket.matter:__expect_send({ mock_device_periodic.id, subscribe_request })
test.socket.device_lifecycle:__queue_receive({ mock_device_periodic.id, "doConfigure" })
mock_device_periodic:expect_metadata_update({ profile = "plug-energy-powerConsumption" })
mock_device_periodic:expect_metadata_update({ provisioning_state = "PROVISIONED" })
test.wait_for_events()
test.socket.matter:__queue_receive({ mock_device_periodic.id, clusters.PowerTopology.attributes.AvailableEndpoints:build_test_report_data(mock_device_periodic, 1, {uint32(1)})})
mock_device_periodic:expect_metadata_update({ profile = "plug-energy-powerConsumption" })
end,
{ test_init = test_init_periodic }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ end

local function test_init_dimmer()
test.mock_device.add_test_device(mock_device_dimmer)
test.socket.device_lifecycle:__queue_receive({ mock_device_dimmer.id, "added" })
test.socket.device_lifecycle:__queue_receive({ mock_device_dimmer.id, "init" })
test.socket.device_lifecycle:__queue_receive({ mock_device_dimmer.id, "doConfigure" })
mock_device_dimmer:expect_metadata_update({ profile = "switch-level" })
mock_device_dimmer:expect_metadata_update({ provisioning_state = "PROVISIONED" })
Expand Down Expand Up @@ -505,6 +507,7 @@ local function test_init_mounted_on_off_control()
test.socket.matter:__expect_send({mock_device_mounted_on_off_control.id, subscribe_request})

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

Expand All @@ -526,6 +529,7 @@ local function test_init_mounted_dimmable_load_control()
test.socket.matter:__expect_send({mock_device_mounted_dimmable_load_control.id, subscribe_request})

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

Expand Down Expand Up @@ -566,6 +570,7 @@ local function test_init_parent_child_different_types()
test.socket.matter:__expect_send({mock_device_parent_child_different_types.id, subscribe_request})

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

mock_device_parent_child_different_types:expect_device_create({
Expand Down Expand Up @@ -617,6 +622,7 @@ local function test_init_light_level_motion()
test.socket.matter:__expect_send({mock_device_light_level_motion.id, subscribe_request})

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ local function test_init()
test.socket.matter:__expect_send({mock_device.id, subscribe_request})

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

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

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

for _, child in pairs(mock_children_non_sequential) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ local child_profile_override = t_utils.get_profile_definition("switch-binary.yml
local parent_ep = 10
local child1_ep = 20
local child2_ep = 30
local child3_ep = 40
local child4_ep = 50

local mock_device = test.mock_device.build_test_matter_device({
label = "Matter Switch",
Expand Down Expand Up @@ -69,6 +71,24 @@ local mock_device = test.mock_device.build_test_matter_device({
{device_type_id = 0x010A, device_type_revision = 2} -- On/Off Plug
}
},
{
endpoint_id = child3_ep,
clusters = {
{cluster_id = clusters.OnOff.ID, cluster_type = "SERVER"},
},
device_types = {
{device_type_id = 0x010A, device_type_revision = 2} -- On/Off Plug
}
},
{
endpoint_id = child4_ep,
clusters = {
{cluster_id = clusters.OnOff.ID, cluster_type = "SERVER"},
},
device_types = {
{device_type_id = 0x010A, device_type_revision = 2} -- On/Off Plug
}
}
}
})

Expand Down Expand Up @@ -146,6 +166,7 @@ local function test_init()
test.socket.matter:__expect_send({mock_device.id, subscribe_request})

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

for _, child in pairs(mock_children) do
Expand All @@ -167,6 +188,22 @@ local function test_init()
parent_device_id = mock_device.id,
parent_assigned_child_key = string.format("%d", child2_ep)
})

mock_device:expect_device_create({
type = "EDGE_CHILD",
label = "Matter Switch 4",
profile = "plug-binary",
parent_device_id = mock_device.id,
parent_assigned_child_key = string.format("%d", child3_ep)
})

mock_device:expect_device_create({
type = "EDGE_CHILD",
label = "Matter Switch 5",
profile = "plug-binary",
parent_device_id = mock_device.id,
parent_assigned_child_key = string.format("%d", child4_ep)
})
end

local mock_children_child_profile_override = {}
Expand Down Expand Up @@ -196,6 +233,7 @@ local function test_init_child_profile_override()
test.socket.matter:__expect_send({mock_device_child_profile_override.id, subscribe_request})

test.socket.device_lifecycle:__queue_receive({ mock_device_child_profile_override.id, "doConfigure" })
mock_device_child_profile_override:expect_metadata_update({ profile = "plug-binary" })
mock_device_child_profile_override:expect_metadata_update({ provisioning_state = "PROVISIONED" })

for _, child in pairs(mock_children_child_profile_override) do
Expand Down
Loading