feat: Add auto-lock timer sensor with dashboard badge (#509)#577
feat: Add auto-lock timer sensor with dashboard badge (#509)#577tykeal wants to merge 1 commit intoFutureTense:mainfrom
Conversation
2563ce3 to
17bb947
Compare
There was a problem hiding this comment.
Pull request overview
This PR implements issue #509 by exposing the auto-lock countdown as a new Home Assistant timestamp sensor and wiring it into the generated Lovelace dashboard so users can see the timer while it’s running.
Changes:
- Added
sensor.autolock_timer(timestamp device class) with timer-style attributes (duration,remaining,finishes_at,is_running). - Updated coordinator to push immediate updates when the auto-lock timer starts/cancels (instead of waiting for the periodic refresh).
- Fixed autolock minute number entities to coerce
floatinputs toint, and added/updated tests for the new behavior and dashboard badge.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
custom_components/keymaster/sensor.py |
Adds the new auto-lock timer sensor entity and its coordinator update handling. |
custom_components/keymaster/helpers.py |
Extends KeymasterTimer to track duration and centralizes expiry cleanup/check logic. |
custom_components/keymaster/coordinator.py |
Pushes async_set_updated_data immediately after timer start/cancel for responsiveness. |
custom_components/keymaster/number.py |
Converts autolock minute values from float to int in async_set_native_value. |
custom_components/keymaster/lovelace.py |
Adds a conditional “Auto Lock Timer” badge and supports custom visibility conditions. |
tests/test_sensor.py |
Adds tests covering the new sensor behavior and seconds formatting helper. |
tests/test_number.py |
Adds parametric test verifying float-to-int conversion for autolock minute numbers. |
tests/test_lovelace.py |
Adds test ensuring the autolock timer badge is generated with the intended visibility conditions. |
tests/test_coordinator.py |
Adds tests/expectations for immediate coordinator data push on timer start/cancel. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #577 +/- ##
==========================================
+ Coverage 84.14% 86.05% +1.91%
==========================================
Files 10 25 +15
Lines 801 2804 +2003
==========================================
+ Hits 674 2413 +1739
- Misses 127 391 +264
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I'd like to see 100% patch coverage 😃 |
Of course you would. So would I! ;) I'll get that fixed. |
17bb947 to
386b4e4
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 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.
Add a timestamp sensor that tracks the auto-lock countdown timer, with timer-emulating attributes (duration, remaining, finishes_at, is_running). The sensor shows a timestamp when the timer is running and 'unknown' when idle. Dashboard integration: - Add conditional badge to generated Lovelace dashboard - Badge only visible when timer is running (not unknown/unavailable) Timer responsiveness: - Push coordinator data updates immediately when timer starts/cancels - Previously entities only saw timer changes on ~30s refresh cycle Timer state consistency: - Refactor KeymasterTimer to use shared _cleanup_expired() method - All property accessors now consistently clear duration on expiry - Snapshot timer values atomically in sensor to avoid race conditions Fix float-to-int conversion: - Convert autolock minute values from float to int in number entity - HA NumberEntity passes float values that caused ValueError in _seconds_to_hhmmss format string when using :02d specifier Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
386b4e4 to
fe47550
Compare
|
@firstof9 100% coverage on the change now :) |
|
Does "auto lock" account for the door status, if it exists? |
Summary
Implements the feature requested in #509 — display the auto-lock countdown timer on the Home Assistant dashboard.
Changes
New auto-lock timer sensor (
sensor.autolock_timer):device_class=TIMESTAMP) that shows when the auto-lock timer will fireduration,remaining,finishes_at,is_runningunknownwhen timer is idle, a timestamp when runningDashboard integration:
Timer responsiveness:
Timer state consistency:
KeymasterTimerto use shared_cleanup_expired()/_check_expired()methods_durationon timer expiry (previously onlycancel()did)Bug fix — float-to-int conversion:
NumberEntitypassesfloatvalues toasync_set_native_valueautolock_min_day/autolock_min_night) are typed asintbut were stored asfloatafter user modificationValueErrorin the sensor's:02dformat specifier, making the entity stayunknownTesting
Closes #509