Skip to content
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

Add batteryLevel to matter switch #1862

Merged
merged 2 commits into from
Jan 31, 2025

Conversation

nickolas-deboom
Copy link
Contributor

@nickolas-deboom nickolas-deboom commented Jan 10, 2025

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

CHAD-12161

Matter drivers currently assume that BatPercentRemaining is available if the BAT feature is supported, but this attribute is only optionally required if this feature is present. The changes in this PR improve the profile selection logic in matter-switch by reading the AttributeList, checking if BatPercentRemaining or BatChargeLevel is available, and then profiling the device as needed.

Note that these changes were originally in PR 1796 but this PR was split up into 5 separate PRs, one for each affected driver.

Summary of Completed Tests

Tested with a matter button, which supports BatPercentRemaining. Relevant logs:

2025-01-30_16:08:45.116 | I | broker     | <Matter Switch (c8775dfd)> <MatterDevice: dd1a6065-2320-4d46-9651-d249e2045b83 [7AE8C08425F969BF-6AB3AA3F0FB2BDDC-11] (Matter Button)> received lifecycle event: added
2025-01-30_16:08:45.161 | I | broker     | <Matter Switch (c8775dfd)> <MatterDevice: dd1a6065-2320-4d46-9651-d249e2045b83 [7AE8C08425F969BF-6AB3AA3F0FB2BDDC-11] (Matter Button)> sending InteractionRequest: <InteractionRequest || type: READ, info_blocks: [<InteractionInfoBlock || cluster: PowerSource, attribute: AttributeList>]>
2025-01-30_16:08:45.541 | I | broker     | <Matter Switch (c8775dfd)> <MatterDevice: dd1a6065-2320-4d46-9651-d249e2045b83 [7AE8C08425F969BF-6AB3AA3F0FB2BDDC-11] (Matter Button)> received InteractionResponse: <InteractionResponse || type: REPORT_DATA, response_blocks: [<InteractionResponseInfoBlock || status: SUCCESS, <InteractionInfoBlock || endpoint: 0x0B, cluster: PowerSource, attribute: AttributeList, data: Array: [Uint16: \xFF\xF8, Uint16: \xFF\xF9, Uint16: \xFF\xFB, Uint16: \xFF\xFC, Uint8: \x00, Uint8: \x01, Uint8: \x02, Uint8: \x0C, Uint8: \x0E, Uint8: \x0F, Uint8: \x10, Uint8: \x1F, Uint16: \xFF\xFD]>>, <InteractionResponseInfoBlock || status: SUCCESS, <InteractionInfoBlock || cluster: PowerSource, attribute: AttributeList>>]>

The device was profiled to 7-button-battery (the profile it was already joined to).

Copy link

Duplicate profile check: Passed - no duplicate profiles detected.

Copy link

github-actions bot commented Jan 10, 2025

Test Results

   64 files    409 suites   0s ⏱️
2 021 tests 2 021 ✅ 0 💤 0 ❌
3 500 runs  3 500 ✅ 0 💤 0 ❌

Results for commit 8b4c907.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jan 10, 2025

File Coverage
All files 94%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/init.lua 96%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/eve-energy/init.lua 91%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/aqara-cube/init.lua 96%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/embedded-cluster-utils.lua 38%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 8b4c907

Copy link

github-actions bot commented Jan 10, 2025

Channel deleted.

Copy link
Contributor

@hcarter-775 hcarter-775 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@hcarter-775 hcarter-775 left a comment

Choose a reason for hiding this comment

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

Actually I jumped the gun. Before merging, there is some maybe messy conflict with the recent Aqara climate device PR. This should be handled and discussed if necessary before merging.

Improve the profile selection logic in matter-switch by reading the AttributeList, checking if BatPercentRemaining or BatChargeLevel is available, and then profile the device as needed.
@nickolas-deboom nickolas-deboom force-pushed the add-batteryLevel-to-matter-switch branch from 9483876 to cd45c95 Compare January 30, 2025 21:54
@nickolas-deboom nickolas-deboom merged commit 0d9ca0f into main Jan 31, 2025
12 checks passed
@nickolas-deboom nickolas-deboom deleted the add-batteryLevel-to-matter-switch branch January 31, 2025 17:24
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.

2 participants