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 sensor #1863

Merged
merged 4 commits into from
Jan 30, 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-sensor 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 Contact Sensor device. This device supports BatPercentRemaining and so is profiled to contact-battery. See the relevant logs below:

2025-01-29_19:13:46.047 | I | broker     | <Matter Sensor (a687db78)> <MatterDevice: e236c578-a7be-4dc3-a5be-48e994ed5aff [E3BA971501FF2304-62C81BCFBD013D86] (Tuo Contact Sensor)> received lifecycle event: added
2025-01-29_19:13:46.067 | I | broker     | <Matter Sensor (a687db78)> <MatterDevice: e236c578-a7be-4dc3-a5be-48e994ed5aff [E3BA971501FF2304-62C81BCFBD013D86] (Tuo Contact Sensor)> sending InteractionRequest: <InteractionRequest || type: SUBSCRIBE, info_blocks: [<InteractionInfoBlock || cluster: PowerSource, attribute: BatPercentRemaining>, <InteractionInfoBlock || cluster: BooleanState, attribute: StateValue>]>
2025-01-29_19:13:46.107 | I | broker     | <Matter Sensor (a687db78)> <MatterDevice: e236c578-a7be-4dc3-a5be-48e994ed5aff [E3BA971501FF2304-62C81BCFBD013D86] (Tuo Contact Sensor)> received lifecycle event: doConfigure
2025-01-29_19:13:46.129 | I | broker     | <Matter Sensor (a687db78)> <MatterDevice: e236c578-a7be-4dc3-a5be-48e994ed5aff [E3BA971501FF2304-62C81BCFBD013D86] (Tuo Contact Sensor)> sending InteractionRequest: <InteractionRequest || type: READ, info_blocks: [<InteractionInfoBlock || cluster: PowerSource, attribute: AttributeList>]>
2025-01-29_19:13:50.692 | I | broker     | <Matter Sensor (a687db78)> <MatterDevice: e236c578-a7be-4dc3-a5be-48e994ed5aff [E3BA971501FF2304-62C81BCFBD013D86] (Tuo Contact Sensor)> received InteractionResponse: <InteractionResponse || type: REPORT_DATA, response_blocks: [<InteractionResponseInfoBlock || status: SUCCESS, <InteractionInfoBlock || endpoint: 0x01, cluster: BooleanState, attribute: StateValue, data: Boolean: true>>, <InteractionResponseInfoBlock || status: SUCCESS, <InteractionInfoBlock || endpoint: 0x01, cluster: PowerSource, attribute: BatPercentRemaining, data: Uint8: \xC8>>, <InteractionResponseInfoBlock || status: SUCCESS, <InteractionInfoBlock || endpoint: 0x00, cluster: BasicInformation, attribute: SoftwareVersion, data: Uint8: \x01>>]>
2025-01-29_19:13:50.708 | I | broker     | <Matter Sensor (a687db78)> <MatterDevice: e236c578-a7be-4dc3-a5be-48e994ed5aff [E3BA971501FF2304-62C81BCFBD013D86] (Tuo Contact Sensor)> emitting event: {"attribute_id":"contact","capability_id":"contactSensor","component_id":"main","state":{"value":"closed"}}
2025-01-29_19:13:50.768 | I | broker     | <Matter Sensor (a687db78)> <MatterDevice: e236c578-a7be-4dc3-a5be-48e994ed5aff [E3BA971501FF2304-62C81BCFBD013D86] (Tuo Contact Sensor)> emitting event: {"attribute_id":"battery","capability_id":"battery","component_id":"main","state":{"value":100}}
2025-01-29_19:13:50.842 | I | broker     | <Matter Sensor (a687db78)> <MatterDevice: e236c578-a7be-4dc3-a5be-48e994ed5aff [E3BA971501FF2304-62C81BCFBD013D86] (Tuo Contact Sensor)> received InteractionResponse: <InteractionResponse || type: REPORT_DATA, response_blocks: [<InteractionResponseInfoBlock || status: SUCCESS, <InteractionInfoBlock || endpoint: 0x01, cluster: PowerSource, attribute: AttributeList, data: Array: [Uint8: \x00, Uint8: \x01, Uint8: \x02, Uint8: \x0C, Uint8: \x0E, Uint8: \x0F, Uint8: \x10, Uint8: \x13, Uint8: \x19, Uint16: \xFF\xF8, Uint16: \xFF\xF9, Uint16: \xFF\xFB, Uint16: \xFF\xFC, Uint16: \xFF\xFD]>>, <InteractionResponseInfoBlock || status: SUCCESS, <InteractionInfoBlock || cluster: PowerSource, attribute: AttributeList>>]>
2025-01-29_19:13:50.848 | I | broker     | <Matter Sensor (a687db78)> <MatterDevice: e236c578-a7be-4dc3-a5be-48e994ed5aff [E3BA971501FF2304-62C81BCFBD013D86] (Tuo Contact Sensor)> Updating device profile to contact-battery.

Copy link

Duplicate profile check: Warning - duplicate profiles detected.
matter-motion-batteryLevel-illuminance.yml == motion-illuminance-batteryLevel.yml
matter-motion-batteryLevel.yml == motion-batteryLevel.yml

Copy link

github-actions bot commented Jan 10, 2025

Channel deleted.

Copy link

github-actions bot commented Jan 10, 2025

Test Results

   64 files    408 suites   0s ⏱️
2 019 tests 2 019 ✅ 0 💤 0 ❌
3 495 runs  3 495 ✅ 0 💤 0 ❌

Results for commit e84deec.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jan 10, 2025

File Coverage
All files 87%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-sensor/src/air-quality-sensor/init.lua 92%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-sensor/src/smoke-co-alarm/init.lua 83%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-sensor/src/init.lua 91%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-sensor/src/embedded-cluster-utils.lua 45%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against e84deec

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!

@@ -157,8 +154,10 @@ local function do_configure(driver, device)
profile_name = profile_name .. "-leak"
end

if supports_battery_percentage_remaining(device) then
if battery_supported == battery_support.BATTERY_PERCENTAGE then
Copy link
Contributor

@ctowns ctowns Jan 27, 2025

Choose a reason for hiding this comment

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

Just moving this comment over from the previous mega PR since I don't think it has been resolved yet:

I believe there is a confluence page somewhere that indicates the expected order of capabilities in a profile. I cannot seem to find it, but I believe @hcarter-775 might have updated it somewhat recently.

Anyway, in a similar vein, we should document the expected order of our profile name tags so that when we are creating new profiles, we can ensure that their name are internally consistent. For example, this function essentially outlines the order I am talking about (motion is first, contact is second...preferences are last). This way it is clear the order of precedence when using all these combinations of flags to create the profile name.

@hcarter-775 do you know where this confluence page that has the capability ordering documented is located? I believe we had looked at it together during the 1.3 stuff but I do not remember where it was so I am wondering if you remember?

@ctowns
Copy link
Contributor

ctowns commented Jan 27, 2025

@nickolas-deboom can you fill out the "Summary of Completed Tests" section as well? Are there any real devices this can be tested against that we have in the office?

@nickolas-deboom
Copy link
Contributor Author

nickolas-deboom commented Jan 27, 2025

@nickolas-deboom can you fill out the "Summary of Completed Tests" section as well? Are there any real devices this can be tested against that we have in the office?

I have a battery-powered Eve weather device that I can test out tomorrow!

@nickolas-deboom nickolas-deboom merged commit 95be9d1 into main Jan 30, 2025
12 checks passed
@nickolas-deboom nickolas-deboom deleted the add-batteryLevel-to-matter-sensor branch January 30, 2025 21:11
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.

3 participants