Skip to content
Merged
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
6 changes: 3 additions & 3 deletions drivers/SmartThings/matter-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ function SwitchLifecycleHandlers.device_init(driver, device)
if device:get_field(fields.IS_PARENT_CHILD_DEVICE) then
device:set_find_child(switch_utils.find_child)
end
local main_endpoint = switch_utils.find_default_endpoint(device)
local default_endpoint_id = switch_utils.find_default_endpoint(device)
-- ensure subscription to all endpoint attributes- including those mapped to child devices
for idx, ep in ipairs(device.endpoints) do
if ep.endpoint_id ~= main_endpoint then
if ep.endpoint_id ~= default_endpoint_id then
if device:supports_server_cluster(clusters.OnOff.ID, ep) then
local child_profile = switch_cfg.assign_child_profile(device, ep)
if idx == 1 and string.find(child_profile, "energy") then
Expand All @@ -101,7 +101,7 @@ function SwitchLifecycleHandlers.device_init(driver, device)
id = math.max(id, dt.device_type_id)
end
for _, attr in pairs(fields.device_type_attribute_map[id] or {}) do
if id == fields.GENERIC_SWITCH_ID and
if id == fields.DEVICE_TYPE_ID.GENERIC_SWITCH and
attr ~= clusters.PowerSource.attributes.BatPercentRemaining and
attr ~= clusters.PowerSource.attributes.BatChargeLevel then
device:add_subscribed_event(attr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ if version.api < 11 then
clusters.PowerTopology = require "embedded_clusters.PowerTopology"
end

if version.api < 16 then
clusters.Descriptor = require "embedded_clusters.Descriptor"
end

local aqara_parent_ep = 4
local aqara_child1_ep = 1
local aqara_child2_ep = 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ 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 }, -- Dimmable Plug In Unit
}
}
},
Expand Down Expand Up @@ -88,10 +88,20 @@ local mock_device_periodic = test.mock_device.build_test_matter_device({
{ device_type_id = 0x0510, device_type_revision = 1 } -- Electrical Sensor
}
},
{
endpoint_id = 2,
clusters = {
{ cluster_id = clusters.OnOff.ID, cluster_type = "SERVER", cluster_revision = 1, feature_map = 0, },
},
device_types = {
{ device_type_id = 0x010A, device_type_revision = 1 }, -- On Off Plug In Unit
}
}
},
})

local subscribed_attributes_periodic = {
clusters.OnOff.attributes.OnOff,
clusters.ElectricalEnergyMeasurement.attributes.PeriodicEnergyImported,
clusters.ElectricalEnergyMeasurement.attributes.CumulativeEnergyImported,
}
Expand Down
107 changes: 107 additions & 0 deletions drivers/SmartThings/matter-switch/src/test/test_matter_switch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,52 @@ local mock_device_no_hue_sat = test.mock_device.build_test_matter_device({
}
})

local mock_device_color_temp = test.mock_device.build_test_matter_device({
profile = t_utils.get_profile_definition("light-level-colorTemperature.yml"),
manufacturer_info = {
vendor_id = 0x0000,
product_id = 0x0000,
},
endpoints = {
{
endpoint_id = 1,
clusters = {
{cluster_id = clusters.OnOff.ID, cluster_type = "SERVER"},
{cluster_id = clusters.ColorControl.ID, cluster_type = "BOTH", feature_map = 30},
{cluster_id = clusters.LevelControl.ID, cluster_type = "SERVER"}
},
device_types = {
{device_type_id = 0x0100, device_type_revision = 1}, -- On/Off Light
{device_type_id = 0x010C, device_type_revision = 1} -- Color Temperature Light
}
}
}
})

local mock_device_extended_color = test.mock_device.build_test_matter_device({
profile = t_utils.get_profile_definition("light-color-level.yml"),
manufacturer_info = {
vendor_id = 0x0000,
product_id = 0x0000,
},
endpoints = {
{
endpoint_id = 1,
clusters = {
{cluster_id = clusters.OnOff.ID, cluster_type = "SERVER"},
{cluster_id = clusters.ColorControl.ID, cluster_type = "BOTH", feature_map = 30},
{cluster_id = clusters.LevelControl.ID, cluster_type = "SERVER", feature_map = 2}
},
device_types = {
{device_type_id = 0x0100, device_type_revision = 1}, -- On/Off Light
{device_type_id = 0x0101, device_type_revision = 1}, -- Dimmable Light
{device_type_id = 0x010C, device_type_revision = 1}, -- Color Temperature Light
{device_type_id = 0x010D, device_type_revision = 1}, -- Extended Color Light
}
}
}
})

local cluster_subscribe_list = {
clusters.OnOff.attributes.OnOff,
clusters.LevelControl.attributes.CurrentLevel,
Expand Down Expand Up @@ -146,6 +192,67 @@ local function test_init_no_hue_sat()
set_color_mode(mock_device_no_hue_sat, 1, clusters.ColorControl.types.ColorMode.CURRENTX_AND_CURRENTY)
end


local cluster_subscribe_list_color_temp = {
clusters.OnOff.attributes.OnOff,
clusters.LevelControl.attributes.CurrentLevel,
clusters.LevelControl.attributes.MaxLevel,
clusters.LevelControl.attributes.MinLevel,
clusters.ColorControl.attributes.ColorTemperatureMireds,
clusters.ColorControl.attributes.ColorTempPhysicalMaxMireds,
clusters.ColorControl.attributes.ColorTempPhysicalMinMireds
}

local function test_init_color_temp()
test.mock_device.add_test_device(mock_device_color_temp)
local subscribe_request = cluster_subscribe_list_color_temp[1]:subscribe(mock_device_color_temp)
for i, cluster in ipairs(cluster_subscribe_list_color_temp) do
if i > 1 then
subscribe_request:merge(cluster:subscribe(mock_device_color_temp))
end
end
test.socket.matter:__expect_send({mock_device_color_temp.id, subscribe_request})
test.socket.device_lifecycle:__queue_receive({ mock_device_color_temp.id, "added" })
test.socket.matter:__expect_send({mock_device_color_temp.id, subscribe_request})

test.socket.device_lifecycle:__queue_receive({ mock_device_color_temp.id, "init" })
test.socket.matter:__expect_send({mock_device_color_temp.id, subscribe_request})

test.socket.device_lifecycle:__queue_receive({ mock_device_color_temp.id, "doConfigure" })
mock_device_color_temp:expect_metadata_update({ provisioning_state = "PROVISIONED" })
end

local function test_init_extended_color()
test.mock_device.add_test_device(mock_device_extended_color)
local subscribe_request = cluster_subscribe_list[1]:subscribe(mock_device_extended_color)
for i, cluster in ipairs(cluster_subscribe_list) do
if i > 1 then
subscribe_request:merge(cluster:subscribe(mock_device_extended_color))
end
end
test.socket.matter:__expect_send({mock_device_extended_color.id, subscribe_request})
test.socket.device_lifecycle:__queue_receive({ mock_device_extended_color.id, "added" })
test.socket.matter:__expect_send({mock_device_extended_color.id, subscribe_request})

test.socket.device_lifecycle:__queue_receive({ mock_device_extended_color.id, "init" })
test.socket.matter:__expect_send({mock_device_extended_color.id, subscribe_request})

test.socket.device_lifecycle:__queue_receive({ mock_device_extended_color.id, "doConfigure" })
mock_device_extended_color:expect_metadata_update({ provisioning_state = "PROVISIONED" })
end

test.register_message_test(
"Test that Color Temperature Light device does not switch profiles",
{},
{ test_init = test_init_color_temp }
)

test.register_message_test(
"Test that Extended Color Light device does not switch profiles",
{},
{ test_init = test_init_extended_color }
)

test.register_message_test(
"On command should send the appropriate commands",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,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 +527,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 +568,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 +620,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 @@ -146,6 +146,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 Down Expand Up @@ -196,6 +197,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 = "switch-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
Loading