-
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.
Add batteryLevel capability to the matter lock driver (#1608)
add support for batteryLevel in matter lock
- Loading branch information
1 parent
d3170a1
commit b9f8bfd
Showing
7 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
drivers/SmartThings/matter-lock/profiles/base-lock-batteryLevel.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,25 @@ | ||
name: base-lock-batteryLevel | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: lock | ||
version: 1 | ||
config: | ||
values: | ||
- key: "lock.value" | ||
enabledValues: | ||
- locked | ||
- unlocked | ||
- not fully locked | ||
- id: lockCodes | ||
version: 1 | ||
- id: tamperAlert | ||
version: 1 | ||
- id: batteryLevel | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: SmartLock |
23 changes: 23 additions & 0 deletions
23
drivers/SmartThings/matter-lock/profiles/lock-lockalarm-batteryLevel.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,23 @@ | ||
name: lock-lockalarm-batteryLevel | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: lock | ||
version: 1 | ||
config: | ||
values: | ||
- key: "lock.value" | ||
enabledValues: | ||
- locked | ||
- unlocked | ||
- not fully locked | ||
- id: lockAlarm | ||
version: 1 | ||
- id: batteryLevel | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: SmartLock |
21 changes: 21 additions & 0 deletions
21
drivers/SmartThings/matter-lock/profiles/lock-nocodes-notamper-batteryLevel.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,21 @@ | ||
name: lock-nocodes-notamper-batteryLevel | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: lock | ||
version: 1 | ||
config: | ||
values: | ||
- key: "lock.value" | ||
enabledValues: | ||
- locked | ||
- unlocked | ||
- not fully locked | ||
- id: batteryLevel | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: SmartLock |
23 changes: 23 additions & 0 deletions
23
drivers/SmartThings/matter-lock/profiles/lock-without-codes-batteryLevel.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,23 @@ | ||
name: lock-without-codes-batteryLevel | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: lock | ||
version: 1 | ||
config: | ||
values: | ||
- key: "lock.value" | ||
enabledValues: | ||
- locked | ||
- unlocked | ||
- not fully locked | ||
- id: tamperAlert | ||
version: 1 | ||
- id: batteryLevel | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: SmartLock |
16 changes: 16 additions & 0 deletions
16
drivers/SmartThings/matter-lock/profiles/nonfunctional-lock-batteryLevel.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: nonfunctional-lock-batteryLevel | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: lockCodes | ||
version: 1 | ||
- id: tamperAlert | ||
version: 1 | ||
- id: batteryLevel | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: SmartLock |
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
104 changes: 104 additions & 0 deletions
104
drivers/SmartThings/matter-lock/src/test/test_matter_lock_batteryLevel.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,104 @@ | ||
-- 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" | ||
test.add_package_capability("lockAlarm.yml") | ||
local t_utils = require "integration_test.utils" | ||
local clusters = require "st.matter.clusters" | ||
|
||
local mock_device_record = { | ||
profile = t_utils.get_profile_definition("lock-nocodes-notamper-batteryLevel.yml"), | ||
manufacturer_info = {vendor_id = 0x101D, product_id = 0x1}, | ||
endpoints = { | ||
{ | ||
endpoint_id = 2, | ||
clusters = { | ||
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"}, | ||
}, | ||
device_types = { | ||
device_type_id = 0x0016, device_type_revision = 1, -- RootNode | ||
} | ||
}, | ||
{ | ||
endpoint_id = 10, | ||
clusters = { | ||
{cluster_id = clusters.DoorLock.ID, cluster_type = "SERVER", feature_map = 0x0000}, | ||
{cluster_id = clusters.PowerSource.ID, cluster_type = "SERVER", feature_map = 0x0002}, | ||
}, | ||
}, | ||
}, | ||
} | ||
local mock_device = test.mock_device.build_test_matter_device(mock_device_record) | ||
|
||
|
||
local function test_init() | ||
local subscribe_request = clusters.DoorLock.attributes.LockState:subscribe(mock_device) | ||
subscribe_request:merge(clusters.PowerSource.attributes.BatChargeLevel:subscribe(mock_device)) | ||
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_message_test( | ||
"Handle BatChargeLevel capability handling with batteryLevel.", { | ||
{ | ||
channel = "matter", | ||
direction = "receive", | ||
message = { | ||
mock_device.id, | ||
clusters.PowerSource.attributes.BatChargeLevel:build_test_report_data( | ||
mock_device, 10, clusters.PowerSource.types.BatChargeLevelEnum.CRITICAL | ||
), | ||
}, | ||
}, | ||
{ | ||
channel = "capability", | ||
direction = "send", | ||
message = mock_device:generate_test_message("main", capabilities.batteryLevel.battery.critical()), | ||
}, | ||
{ | ||
channel = "matter", | ||
direction = "receive", | ||
message = { | ||
mock_device.id, | ||
clusters.PowerSource.attributes.BatChargeLevel:build_test_report_data( | ||
mock_device, 10, clusters.PowerSource.types.BatChargeLevelEnum.WARNING | ||
), | ||
}, | ||
}, | ||
{ | ||
channel = "capability", | ||
direction = "send", | ||
message = mock_device:generate_test_message("main", capabilities.batteryLevel.battery.warning()), | ||
}, | ||
{ | ||
channel = "matter", | ||
direction = "receive", | ||
message = { | ||
mock_device.id, | ||
clusters.PowerSource.attributes.BatChargeLevel:build_test_report_data( | ||
mock_device, 10, clusters.PowerSource.types.BatChargeLevelEnum.OK | ||
), | ||
}, | ||
}, | ||
{ | ||
channel = "capability", | ||
direction = "send", | ||
message = mock_device:generate_test_message("main", capabilities.batteryLevel.battery.normal()), | ||
}, | ||
} | ||
) | ||
|
||
test.run_registered_tests() |