-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Matter-sensor add support for mains powered sensors
- Loading branch information
Showing
6 changed files
with
263 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
drivers/SmartThings/matter-sensor/profiles/matter-motion-battery.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: matter-motion-battery | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: motionSensor | ||
version: 1 | ||
- id: battery | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: MotionSensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: matter-motion-battery | ||
name: motion-battery | ||
components: | ||
- id: main | ||
capabilities: | ||
|
16 changes: 16 additions & 0 deletions
16
drivers/SmartThings/matter-sensor/profiles/motion-illuminance-battery.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: motion-illuminance-battery | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: motionSensor | ||
version: 1 | ||
- id: battery | ||
version: 1 | ||
- id: illuminanceMeasurement | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: MotionSensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
drivers/SmartThings/matter-sensor/src/test/test_matter_sensor_featuremap.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
-- Copyright 2023 SmartThings | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
local test = require "integration_test" | ||
local t_utils = require "integration_test.utils" | ||
local clusters = require "st.matter.clusters" | ||
|
||
local mock_device_humidity_battery = test.mock_device.build_test_matter_device({ | ||
profile = t_utils.get_profile_definition("humidity-battery.yml"), | ||
manufacturer_info = { | ||
vendor_id = 0x0000, | ||
product_id = 0x0000, | ||
}, | ||
endpoints = { | ||
{ | ||
endpoint_id = 0, | ||
clusters = { | ||
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"}, | ||
}, | ||
device_types = { | ||
device_type_id = 0x0016, device_type_revision = 1, -- RootNode | ||
} | ||
}, | ||
{ | ||
endpoint_id = 1, | ||
clusters = { | ||
{cluster_id = clusters.RelativeHumidityMeasurement.ID, cluster_type = "SERVER"}, | ||
} | ||
}, | ||
{ | ||
endpoint_id = 2, | ||
clusters = { | ||
{cluster_id = clusters.PowerSource.ID, cluster_type = "SERVER", feature_map = 2}, | ||
} | ||
} | ||
} | ||
}) | ||
|
||
local mock_device_humidity_no_battery = test.mock_device.build_test_matter_device({ | ||
profile = t_utils.get_profile_definition("humidity-battery.yml"), | ||
manufacturer_info = { | ||
vendor_id = 0x0000, | ||
product_id = 0x0000, | ||
}, | ||
endpoints = { | ||
{ | ||
endpoint_id = 0, | ||
clusters = { | ||
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"}, | ||
}, | ||
device_types = { | ||
device_type_id = 0x0016, device_type_revision = 1, -- RootNode | ||
} | ||
}, | ||
{ | ||
endpoint_id = 1, | ||
clusters = { | ||
{cluster_id = clusters.RelativeHumidityMeasurement.ID, cluster_type = "SERVER"}, | ||
} | ||
} | ||
} | ||
}) | ||
|
||
local mock_device_temp_humidity = test.mock_device.build_test_matter_device({ | ||
profile = t_utils.get_profile_definition("temperature-humidity.yml"), | ||
manufacturer_info = { | ||
vendor_id = 0x0000, | ||
product_id = 0x0000, | ||
}, | ||
endpoints = { | ||
{ | ||
endpoint_id = 0, | ||
clusters = { | ||
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"}, | ||
}, | ||
device_types = { | ||
device_type_id = 0x0016, device_type_revision = 1, -- RootNode | ||
} | ||
}, | ||
{ | ||
endpoint_id = 1, | ||
clusters = { | ||
{cluster_id = clusters.RelativeHumidityMeasurement.ID, cluster_type = "SERVER"}, | ||
} | ||
}, | ||
{ | ||
endpoint_id = 2, | ||
clusters = { | ||
{cluster_id = clusters.TemperatureMeasurement.ID, cluster_type = "BOTH"}, | ||
} | ||
} | ||
} | ||
}) | ||
|
||
local cluster_subscribe_list_humidity_battery = { | ||
clusters.RelativeHumidityMeasurement.attributes.MeasuredValue, | ||
clusters.PowerSource.attributes.BatPercentRemaining | ||
} | ||
|
||
local cluster_subscribe_list_humidity_no_battery = { | ||
clusters.RelativeHumidityMeasurement.attributes.MeasuredValue | ||
} | ||
|
||
local cluster_subscribe_list_temp_humidity = { | ||
clusters.RelativeHumidityMeasurement.attributes.MeasuredValue, | ||
clusters.TemperatureMeasurement.attributes.MeasuredValue | ||
} | ||
|
||
local function test_init_humidity_battery() | ||
local subscribe_request_humidity_battery = cluster_subscribe_list_humidity_battery[1]:subscribe(mock_device_humidity_battery) | ||
for i, cluster in ipairs(cluster_subscribe_list_humidity_battery) do | ||
if i > 1 then | ||
subscribe_request_humidity_battery:merge(cluster:subscribe(mock_device_humidity_battery)) | ||
end | ||
end | ||
|
||
test.socket.matter:__expect_send({mock_device_humidity_battery.id, subscribe_request_humidity_battery}) | ||
test.mock_device.add_test_device(mock_device_humidity_battery) | ||
end | ||
|
||
local function test_init_humidity_no_battery() | ||
local subscribe_request_humidity_no_battery = cluster_subscribe_list_humidity_no_battery[1]:subscribe(mock_device_humidity_no_battery) | ||
for i, cluster in ipairs(cluster_subscribe_list_humidity_no_battery) do | ||
if i > 1 then | ||
subscribe_request_humidity_no_battery:merge(cluster:subscribe(mock_device_humidity_no_battery)) | ||
end | ||
end | ||
|
||
test.socket.matter:__expect_send({mock_device_humidity_no_battery.id, subscribe_request_humidity_no_battery}) | ||
test.mock_device.add_test_device(mock_device_humidity_no_battery) | ||
end | ||
|
||
local function test_init_temp_humidity() | ||
local subscribe_request_temp_humidity = cluster_subscribe_list_temp_humidity[1]:subscribe(mock_device_temp_humidity) | ||
for i, cluster in ipairs(cluster_subscribe_list_temp_humidity) do | ||
if i > 1 then | ||
subscribe_request_temp_humidity:merge(cluster:subscribe(mock_device_temp_humidity)) | ||
end | ||
end | ||
|
||
test.socket.matter:__expect_send({mock_device_temp_humidity.id, subscribe_request_temp_humidity}) | ||
test.mock_device.add_test_device(mock_device_temp_humidity) | ||
end | ||
|
||
test.register_coroutine_test( | ||
"Profile remains the same for battery-supported devices on doConfigure lifecycle event due to cluster feature map", | ||
function() | ||
test.socket.device_lifecycle:__queue_receive({ mock_device_humidity_battery.id, "doConfigure" }) | ||
mock_device_humidity_battery:expect_metadata_update({ profile = "humidity-battery" }) | ||
mock_device_humidity_battery:expect_metadata_update({ provisioning_state = "PROVISIONED" }) | ||
end, | ||
{ test_init = test_init_humidity_battery } | ||
) | ||
|
||
test.register_coroutine_test( | ||
"Profile change to non-battery profile on doConfigure lifecycle event due to cluster feature map", | ||
function() | ||
test.socket.device_lifecycle:__queue_receive({ mock_device_humidity_no_battery.id, "doConfigure" }) | ||
mock_device_humidity_no_battery:expect_metadata_update({ profile = "humidity" }) | ||
mock_device_humidity_no_battery:expect_metadata_update({ provisioning_state = "PROVISIONED" }) | ||
end, | ||
{ test_init = test_init_humidity_no_battery } | ||
) | ||
|
||
test.register_coroutine_test( | ||
"Profile change to non-battery profile on doConfigure lifecycle event due to cluster feature map", | ||
function() | ||
test.socket.device_lifecycle:__queue_receive({ mock_device_temp_humidity.id, "doConfigure" }) | ||
mock_device_temp_humidity:expect_metadata_update({ profile = "temperature-humidity" }) | ||
mock_device_temp_humidity:expect_metadata_update({ provisioning_state = "PROVISIONED" }) | ||
end, | ||
{ test_init = test_init_temp_humidity } | ||
) | ||
|
||
test.run_registered_tests() |