Skip to content

fix: use effective device_class for battery entity lookup#570

Merged
tykeal merged 2 commits intoFutureTense:mainfrom
tykeal:battery_level
Mar 4, 2026
Merged

fix: use effective device_class for battery entity lookup#570
tykeal merged 2 commits intoFutureTense:mainfrom
tykeal:battery_level

Conversation

@tykeal
Copy link
Copy Markdown
Collaborator

@tykeal tykeal commented Feb 28, 2026

Summary

The battery entity lookup introduced in PR #569 used original_device_class to find battery sensors on lock devices. This only checks the integration-set device class and misses entities where the device class is resolved via user override.

Fix

Use (entry.device_class or entry.original_device_class) to mirror Home Assistant's own resolution logic for the effective device class, matching both user-overridden and integration-set values.

Fixes #549

The battery entity lookup introduced in PR FutureTense#569 used
original_device_class to find battery sensors on lock devices.
This only checks the integration-set device class and misses
entities where the device class is resolved via user override.

Use (entry.device_class or entry.original_device_class) to mirror
Home Assistant's own resolution logic for the effective device
class, matching both user-overridden and integration-set values.

Fixes FutureTense#549

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
@tykeal tykeal requested a review from raman325 February 28, 2026 20:47
@tykeal
Copy link
Copy Markdown
Collaborator Author

tykeal commented Feb 28, 2026

@raman325 I should have listened apparently! Found an issue while working on getting the Schlage provider built out!

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 28, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.69%. Comparing base (cdb4922) to head (7b03d5b).
⚠️ Report is 39 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #570      +/-   ##
==========================================
+ Coverage   84.14%   84.69%   +0.55%     
==========================================
  Files          10       25      +15     
  Lines         801     2751    +1950     
==========================================
+ Hits          674     2330    +1656     
- Misses        127      421     +294     
Flag Coverage Δ
python 84.69% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes battery sensor discovery for lock devices by using Home Assistant’s effective sensor device class resolution, ensuring battery badges appear even when the device class is set via user override.

Changes:

  • Update _find_battery_entity to match sensors using (entry.device_class or entry.original_device_class) rather than only original_device_class.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread custom_components/keymaster/lovelace.py
Add test_find_battery_entity_user_overridden_device_class to verify
that _find_battery_entity correctly finds battery sensors when the
device_class is set via user override rather than original_device_class.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tykeal tykeal merged commit dafb4b7 into FutureTense:main Mar 4, 2026
10 checks passed
@tykeal tykeal deleted the battery_level branch March 4, 2026 19:52
@tykeal tykeal added the bugfix Fixes a bug label Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] : add battery level to the dynamic dashboard

3 participants