Skip to content

Conversation

@seojune79
Copy link
Contributor

@seojune79 seojune79 commented Jan 16, 2026

Check all that apply

Type of Change

  • WWST Certification Request
    • If this is your first time contributing code:
      • I have reviewed the README.md file
      • I have reviewed the CODE_OF_CONDUCT.md file
      • I have signed the CLA
    • I plan on entering a WWST Certification Request or have entered a request through the WWST Certification console at developer.smartthings.com
  • Bug fix
  • New feature
  • Refactor

Checklist

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have verified my changes by testing with a device or have communicated a plan for testing
  • I am adding new behavior, such as adding a sub-driver, and have added and run new unit tests to cover the new behavior

Description of Change

Summary of Completed Tests

@github-actions
Copy link

github-actions bot commented Jan 16, 2026

Test Results

   71 files    483 suites   0s ⏱️
2 493 tests 2 493 ✅ 0 💤 0 ❌
4 279 runs  4 279 ✅ 0 💤 0 ❌

Results for commit c7a5f13.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 16, 2026

File Coverage
All files 57%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/Aqara/aqara-lock/src/init.lua 53%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/Aqara/aqara-lock/src/credential_utils.lua 66%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against c7a5f13

@kdbang
Copy link
Collaborator

kdbang commented Jan 19, 2026

linter fail

Checking drivers/Aqara/aqara-lock/src/credential_utils.lua 1 warning

    drivers/Aqara/aqara-lock/src/credential_utils.lua:99:1: (W611) line contains only whitespace

@seojune79
Copy link
Contributor Author

linter fail

Checking drivers/Aqara/aqara-lock/src/credential_utils.lua 1 warning

    drivers/Aqara/aqara-lock/src/credential_utils.lua:99:1: (W611) line contains only whitespace

I have removed the whitespace.

local HOST_COUNT = "__host_count"
local PERSIST_DATA = "__persist_area"

credential_utils.attrCopy = function(table)
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@cjswedes cjswedes left a 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?

@seojune79
Copy link
Contributor Author

This is looking good to me. Has there been any testing done?

Thank you for your positive feedback!
Regarding testing, while my environment makes it challenging to directly verify the specific scenarios where issues were previously identified, such as hub replacement or main/sub changes, I have confirmed that the code is operating normally and without issues through the following steps:

  1. Registered an Aqara door lock using the SmartThings Aqara-Lock driver and proceeded with user additions and other related functions.
  2. Added specific log code to the current Pull Request (PR) to monitor and confirm normal operation, then packaged and installed this on the hub.
  3. Replaced and utilized the driver via the SmartThings app.
  4. Repeated step 3 for 2-3 cycles to ensure consistency.

(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.

@kdbang
Copy link
Collaborator

kdbang commented Jan 28, 2026

@seojune79 Can you share the invitation link including this PR. I will test switch over scenario.

@seojune79
Copy link
Contributor Author

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:
Invitation Link for Acceptance Server

Basic Information
────────────────────────────────────────────────────
 Driver Id    c8c7deb2-49da-4d00-9bfb-731e6bd7c480  
 Name         Aqara Lock
 Version      2026-01-28T04:29:16.132505912
 Package Key  aqara-lock
 Description  SmartThings driver for Aqara Doorlock 
 Permissions  zigbee
────────────────────────────────────────────────────

@kdbang
Copy link
Collaborator

kdbang commented Jan 28, 2026

@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.

@cjswedes cjswedes requested review from greens and tpmanley January 28, 2026 16:28
Comment on lines 14 to 16
credentialResource[key] = value
end
return credentialResource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing here is inconsistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix it.

Copy link
Contributor

@greens greens left a 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?

@seojune79
Copy link
Contributor Author

Would now be a good time to add more unit test coverage?

Yes, I will take this opportunity to give it a try.

@seojune79
Copy link
Contributor Author

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.

@greens
Copy link
Contributor

greens commented Jan 30, 2026

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.

@greens
Copy link
Contributor

greens commented Jan 30, 2026

Checking drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua 4 warnings

    drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua:4:7: (W211) unused variable cluster_base
    drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua:5:7: (W211) unused variable data_types
    drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua:20:7: (W211) unused variable PRI_ATTR
    drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua:21:7: (W211) unused variable MFG_CODE

@seojune79
Copy link
Contributor Author

Checking drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua 4 warnings

    drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua:4:7: (W211) unused variable cluster_base
    drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua:5:7: (W211) unused variable data_types
    drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua:20:7: (W211) unused variable PRI_ATTR
    drivers/Aqara/aqara-lock/src/test/test_aqara_lock_L100.lua:21:7: (W211) unused variable MFG_CODE

unused variable

I have removed all unused variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants