-
Notifications
You must be signed in to change notification settings - Fork 521
Support the battery capability in smoke/co subdriver #1978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6f88987
Support the battery capability in smoke/co subdriver
nickolas-deboom d091d04
Fix capability name
nickolas-deboom a54538e
Use only one battery capability in each profile
nickolas-deboom 3425a91
Use attribute name in place of hardcoded value
nickolas-deboom c596068
Fix capability order in profile
nickolas-deboom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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: co-battery | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: carbonMonoxideDetector | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: hardwareFault | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: SmokeDetector |
18 changes: 18 additions & 0 deletions
18
drivers/SmartThings/matter-sensor/profiles/co-comeas-battery.yml
This file contains hidden or 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,18 @@ | ||
| name: co-comeas-battery | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: carbonMonoxideDetector | ||
| version: 1 | ||
| - id: carbonMonoxideMeasurement | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: hardwareFault | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: SmokeDetector |
19 changes: 19 additions & 0 deletions
19
drivers/SmartThings/matter-sensor/profiles/smoke-battery.yml
This file contains hidden or 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,19 @@ | ||
| name: smoke-battery | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: smokeDetector | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: hardwareFault | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: SmokeDetector | ||
| preferences: | ||
| - preferenceId: certifiedpreferences.smokeSensorSensitivity | ||
| explicit: true | ||
21 changes: 21 additions & 0 deletions
21
drivers/SmartThings/matter-sensor/profiles/smoke-co-battery.yml
This file contains hidden or 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,21 @@ | ||
| name: smoke-co-battery | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: smokeDetector | ||
| version: 1 | ||
| - id: carbonMonoxideDetector | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: hardwareFault | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: SmokeDetector | ||
| preferences: | ||
| - preferenceId: certifiedpreferences.smokeSensorSensitivity | ||
| explicit: true |
23 changes: 23 additions & 0 deletions
23
drivers/SmartThings/matter-sensor/profiles/smoke-co-comeas-battery.yml
This file contains hidden or 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,23 @@ | ||
| name: smoke-co-comeas-battery | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: smokeDetector | ||
| version: 1 | ||
| - id: carbonMonoxideDetector | ||
| version: 1 | ||
| - id: carbonMonoxideMeasurement | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: hardwareFault | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: SmokeDetector | ||
| preferences: | ||
| - preferenceId: certifiedpreferences.smokeSensorSensitivity | ||
| explicit: true |
31 changes: 31 additions & 0 deletions
31
drivers/SmartThings/matter-sensor/profiles/smoke-co-temp-humidity-comeas-battery.yml
This file contains hidden or 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,31 @@ | ||
| name: smoke-co-temp-humidity-comeas-battery | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: smokeDetector | ||
| version: 1 | ||
| - id: carbonMonoxideDetector | ||
| version: 1 | ||
| - id: relativeHumidityMeasurement | ||
| version: 1 | ||
| - id: temperatureMeasurement | ||
| version: 1 | ||
| - id: carbonMonoxideMeasurement | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: hardwareFault | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: SmokeDetector | ||
| preferences: | ||
| - preferenceId: certifiedpreferences.smokeSensorSensitivity | ||
| explicit: true | ||
| - preferenceId: tempOffset | ||
| explicit: true | ||
| - preferenceId: humidityOffset | ||
| explicit: true |
This file contains hidden or 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
This file contains hidden or 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
131 changes: 131 additions & 0 deletions
131
drivers/SmartThings/matter-sensor/src/test/test_matter_smoke_co_alarm_battery.lua
This file contains hidden or 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,131 @@ | ||
| -- Copyright 2024 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 capabilities = require "st.capabilities" | ||
| local t_utils = require "integration_test.utils" | ||
| local uint32 = require "st.matter.data_types.Uint32" | ||
|
|
||
| local clusters = require "st.matter.clusters" | ||
| clusters.SmokeCoAlarm = require "SmokeCoAlarm" | ||
| local version = require "version" | ||
| if version.api < 10 then | ||
| clusters.SmokeCoAlarm = require "SmokeCoAlarm" | ||
| clusters.CarbonMonoxideConcentrationMeasurement = require "CarbonMonoxideConcentrationMeasurement" | ||
| end | ||
|
|
||
| local mock_device = test.mock_device.build_test_matter_device({ | ||
| profile = t_utils.get_profile_definition("smoke-co-temp-humidity-comeas-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.SmokeCoAlarm.ID, cluster_type = "SERVER", feature_map = clusters.SmokeCoAlarm.types.Feature.CO_ALARM | clusters.SmokeCoAlarm.types.Feature.SMOKE_ALARM}, | ||
| {cluster_id = clusters.TemperatureMeasurement.ID, cluster_type = "SERVER"}, | ||
| {cluster_id = clusters.RelativeHumidityMeasurement.ID, cluster_type = "SERVER"}, | ||
| {cluster_id = clusters.CarbonMonoxideConcentrationMeasurement.ID, cluster_type = "SERVER", feature_map = clusters.CarbonMonoxideConcentrationMeasurement.types.Feature.NUMERIC_MEASUREMENT}, | ||
| {cluster_id = clusters.PowerSource.ID, cluster_type = "SERVER", feature_map = clusters.PowerSource.types.PowerSourceFeature.BATTERY}, | ||
| }, | ||
| device_types = { | ||
| {device_type_id = 0x0076, device_type_revision = 1} -- Smoke CO Alarm | ||
| } | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| local cluster_subscribe_list = { | ||
| clusters.SmokeCoAlarm.attributes.SmokeState, | ||
| clusters.SmokeCoAlarm.attributes.TestInProgress, | ||
| clusters.SmokeCoAlarm.attributes.COState, | ||
| clusters.SmokeCoAlarm.attributes.HardwareFaultAlert, | ||
| clusters.TemperatureMeasurement.attributes.MeasuredValue, | ||
| clusters.TemperatureMeasurement.attributes.MinMeasuredValue, | ||
| clusters.TemperatureMeasurement.attributes.MaxMeasuredValue, | ||
| clusters.RelativeHumidityMeasurement.attributes.MeasuredValue, | ||
| clusters.CarbonMonoxideConcentrationMeasurement.attributes.MeasuredValue, | ||
| clusters.CarbonMonoxideConcentrationMeasurement.attributes.MeasurementUnit, | ||
| clusters.PowerSource.attributes.BatPercentRemaining, | ||
| } | ||
|
|
||
| local function test_init() | ||
| local read_attribute_list = clusters.PowerSource.attributes.AttributeList:read() | ||
| test.socket.matter:__expect_send({mock_device.id, read_attribute_list}) | ||
| local subscribe_request = cluster_subscribe_list[1]:subscribe(mock_device) | ||
| for i, cluster in ipairs(cluster_subscribe_list) 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.mock_device.add_test_device(mock_device) | ||
| end | ||
|
|
||
| test.set_test_init_function(test_init) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Test profile change when battery percent remaining attribute (attribute ID 12) is available", | ||
| function() | ||
| test.socket.matter:__queue_receive( | ||
| { | ||
| mock_device.id, | ||
| clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device, 1, {uint32(12)}) | ||
| } | ||
| ) | ||
| mock_device:expect_metadata_update({ profile = "smoke-co-temp-humidity-comeas-battery" }) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Test that profile does not change when battery percent remaining attribute is not available", | ||
| function() | ||
| test.socket.matter:__queue_receive( | ||
| { | ||
| mock_device.id, | ||
| clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device, 1, {uint32(0)}) | ||
| } | ||
| ) | ||
| end | ||
| ) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Battery percent reports should generate correct messages", | ||
| function() | ||
| test.socket.matter:__queue_receive( | ||
| { | ||
| mock_device.id, | ||
| clusters.PowerSource.attributes.BatPercentRemaining:build_test_report_data(mock_device, 1, 150) | ||
| } | ||
| ) | ||
| test.socket.capability:__expect_send( | ||
| mock_device:generate_test_message( | ||
| "main", capabilities.battery.battery(math.floor(150 / 2.0 + 0.5)) | ||
| ) | ||
| ) | ||
| end | ||
| ) | ||
|
|
||
| test.run_registered_tests() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.