-
Notifications
You must be signed in to change notification settings - Fork 523
[Aqara/Locks] Improvement of credential info management #2712
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
Open
seojune79
wants to merge
8
commits into
SmartThingsCommunity:main
Choose a base branch
from
seojune79:Aqara-Lock-CredentialInfo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a8e635c
Update the system to manage credentialInfoTable within the persist area
seojune79 d7d7b71
Improvement of credential info management during Hub switch-over or r…
seojune79 478df5e
Remove whitespace
seojune79 eaad1cd
Revision of credential data management
seojune79 4cc53ea
Modify to save the current data if PERSIST_DATA is nil.
seojune79 a983b4a
Fix code indentation
seojune79 ea494de
Adding test cases
seojune79 c7a5f13
Remove the unused variables
seojune79 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
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
77 changes: 77 additions & 0 deletions
77
drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.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,77 @@ | ||
| local test = require "integration_test" | ||
| local t_utils = require "integration_test.utils" | ||
| local capabilities = require "st.capabilities" | ||
| local zigbee_test_utils = require "integration_test.zigbee_test_utils" | ||
|
|
||
| local remoteControlStatus = capabilities.remoteControlStatus | ||
| local antiLockStatus = capabilities["stse.antiLockStatus"] | ||
| test.add_package_capability("antiLockStatus.yaml") | ||
| local lockCredentialInfo = capabilities["stse.lockCredentialInfo"] | ||
| test.add_package_capability("lockCredentialInfo.yaml") | ||
| local lockAlarm = capabilities["lockAlarm"] | ||
| test.add_package_capability("lockAlarm.yaml") | ||
| local Battery = capabilities.battery | ||
| local BatteryLevel = capabilities.batteryLevel | ||
| local Lock = capabilities.lock | ||
|
|
||
| local PRI_CLU = 0xFCC0 | ||
|
|
||
| local HOST_COUNT = "__host_count" | ||
| local PERSIST_DATA = "__persist_area" | ||
|
|
||
| local mock_device = test.mock_device.build_test_zigbee_device( | ||
| { | ||
| profile = t_utils.get_profile_definition("aqara-lock-battery.yml"), | ||
| fingerprinted_endpoint_id = 0x01, | ||
| zigbee_endpoints = { | ||
| [1] = { | ||
| id = 1, | ||
| manufacturer = "Lumi", | ||
| model = "aqara.lock.akr001", | ||
| server_clusters = { PRI_CLU } | ||
| } | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| zigbee_test_utils.prepare_zigbee_env_info() | ||
| local function test_init() | ||
| local SUPPORTED_ALARM_VALUES = { "damaged", "forcedOpeningAttempt", "unableToLockTheDoor", "notClosedForALongTime", | ||
| "highTemperature", "attemptsExceeded" } | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", | ||
| lockAlarm.supportedAlarmValues(SUPPORTED_ALARM_VALUES, { visibility = { displayed = false } }))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", | ||
| Lock.supportedUnlockDirections({"fromInside", "fromOutside"}, { visibility = { displayed = false } }))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", Battery.type("AA"))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", BatteryLevel.type("AA"))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", Battery.quantity(6))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", BatteryLevel.quantity(6))) | ||
| local credentialInfoData = { | ||
| { credentialId = 1, credentialType = "keypad", userId = "1", userLabel = "june", userType = "host" } | ||
| } | ||
| mock_device:set_field(PERSIST_DATA, credentialInfoData, { persist = true }) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", | ||
| lockCredentialInfo.credentialInfo(credentialInfoData, { visibility = { displayed = false } }))) | ||
| test.mock_device.add_test_device(mock_device) | ||
| end | ||
| test.set_test_init_function(test_init) | ||
|
|
||
| test.register_coroutine_test( | ||
| "Handle added lifecycle - only regular user", | ||
| function() | ||
| mock_device:set_field(HOST_COUNT, 1, { persist = true }) | ||
| test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) | ||
|
|
||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", | ||
| remoteControlStatus.remoteControlEnabled('true', { visibility = { displayed = false } }))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", Battery.battery(100))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", BatteryLevel.battery("normal"))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", | ||
| lockAlarm.alarm.clear({ visibility = { displayed = false } }))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", | ||
| antiLockStatus.antiLockStatus('unknown', { visibility = { displayed = false } }))) | ||
| test.socket.capability:__expect_send(mock_device:generate_test_message("main", Lock.lock("locked"))) | ||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be an
elseclause where we callbackup_datain the case that there is nothing persisted? I think this will help ensure existing devices have the state for this capability persisted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please elaborate on this part a bit more? Are you suggesting that adding a check for backup_data would be beneficial if capability information could be deleted during normal use? I'd appreciate further explanation to ensure my understanding is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sync function is called on
device_init. Devices out there right now, do not have PERSIST_DATA set on the device object yet. We want any device that does not yet have this persisted, to have it persisted as soon as we detect that it hasnt been persisted. So my suggestion is, iftableis nil, then we should read the current state and persist it in the driver datastore withcredential_utils.backup_data. If we do not detect and persist in the device_init handler, then we are waiting for a capability command to come in that will cause the persistence, which may or may not happen before a hub failover.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your kind explanation; I now fully understand the situation. As per your suggestion, I have modified the code to read and set the current value if PERSIST_DATA is nil.