-
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
base: main
Are you sure you want to change the base?
[Aqara/Locks] Improvement of credential info management #2712
Conversation
Test Results 71 files 483 suites 0s ⏱️ Results for commit c7a5f13. ♻️ This comment has been updated with latest results. |
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against c7a5f13 |
|
linter fail |
I have removed the whitespace. |
| local HOST_COUNT = "__host_count" | ||
| local PERSIST_DATA = "__persist_area" | ||
|
|
||
| credential_utils.attrCopy = function(table) |
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.
I believe this is an unnecessary function. utils.deep_copy is already doing this recursively for the whole table.
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 feedback. I have revised the implementation to manage data at the table unit level now.
| local credentialInfoTable = device:get_field(PERSIST_DATA) | ||
| if credentialInfoTable ~= nil then | ||
| device:emit_event(lockCredentialInfo.credentialInfo(credentialInfoTable, { visibility = { displayed = false } })) | ||
| end |
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 else clause where we call backup_data in 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, if table is nil, then we should read the current state and persist it in the driver datastore with credential_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.
cjswedes
left a comment
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 is looking good to me. Has there been any testing done?
Thank you for your positive feedback!
(I designed test cases based on the common understanding that the init handler is executed during hub replacement or main/sub changes.) Based on these checks, I am confident that the added code is unlikely to introduce any unforeseen side effects or malfunctions. |
|
@seojune79 Can you share the invitation link including this PR. I will test switch over scenario. |
Here is the invitation link and driver information for the switch-over scenario testing:
|
|
@cjswedes @seojune79 I tested switch over scenario many times with this PR. but I can't find any issue. It seems that the credentialInfo are saved and moved well. |
| credentialResource[key] = value | ||
| end | ||
| return credentialResource |
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.
spacing here is inconsistent
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.
I will fix it.
greens
left a comment
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.
Would now be a good time to add more unit test coverage?
Yes, I will take this opportunity to give it a try. |
|
Due to system restrictions, it is not possible to use the shared key arbitrarily, which limits the creation of test cases. I kindly ask for your understanding regarding this matter. I will add test cases once the system has been improved. |
Ah yes. Of course. I remember that now. |
|
I have removed all unused variables. |
Check all that apply
Type of Change
Checklist
Description of Change
Summary of Completed Tests