Skip to content

Conversation

@raman325
Copy link
Collaborator

@raman325 raman325 commented Jan 20, 2026

Summary

  • Add async_set_updated_data() calls after decrementing accesslimit_count in _lock_unlocked() for both parent and child locks
  • Call _update_slot() after decrement to check if slot should be deactivated and clear PIN from lock when count reaches 0
  • Add async_write_ha_state() in number entity's async_set_native_value() for immediate UI feedback when user changes the value

The UI notification happens before _update_slot() so users see the count change immediately, even before the potentially slow PIN clear operation completes.

Test plan

  • Set a code slot to allow only 1 use
  • Use the code to unlock the door
  • Verify the "Uses Remaining" entity updates immediately (within ~1 second)
  • Verify the code is cleared from the lock when count reaches 0 (not 30+ seconds later)
  • Manually change the "Uses Remaining" value in the UI
  • Verify the change reflects immediately without waiting for refresh

Related

Reported in PR #538 comments by @tykeal

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings January 20, 2026 16:44
@raman325
Copy link
Collaborator Author

@tykeal try this PR for the number of uses fix

@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 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 83.27%. Comparing base (a9a30ef) to head (bcacb3e).
⚠️ Report is 13 commits behind head on beta.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             beta     #554      +/-   ##
==========================================
+ Coverage   80.86%   83.27%   +2.41%     
==========================================
  Files          19       21       +2     
  Lines        2341     2482     +141     
==========================================
+ Hits         1893     2067     +174     
+ Misses        448      415      -33     
Flag Coverage Δ
python 83.27% <100.00%> (?)

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.

@raman325 raman325 added the bugfix Fixes a bug label Jan 20, 2026
Copy link

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 an issue where the "Uses Remaining" number entity does not update immediately when a lock code is used. The fix adds calls to async_set_updated_data() immediately after decrementing the accesslimit_count in the _lock_unlocked() event handler, ensuring entities are notified of the change without waiting for the next scheduled coordinator update (which runs every 60 seconds).

Changes:

  • Added async_set_updated_data() calls after decrementing accesslimit_count for parent locks (line 840)
  • Added async_set_updated_data() calls after decrementing accesslimit_count for regular locks (line 846)

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

@raman325 raman325 force-pushed the fix/number-entity-state-write branch from bd56fc7 to 61d9e0f Compare January 20, 2026 16:52
@raman325
Copy link
Collaborator Author

raman325 commented Jan 20, 2026

@eallison978 try this PR, I fixed the wrong area and did it the wrong way, this should address all of it

@raman325 raman325 changed the title fix: immediately update UI when accesslimit_count decrements fix: immediately update UI when accesslimit_count changes Jan 20, 2026
@eallison978
Copy link

I used HACS to install this. How long do you think it will before HACS recognizes it?

@raman325
Copy link
Collaborator Author

ah, so you were using code that hasn't been fixed yet. You'd have to download the branch and install it manually, and if you haven't done that, you wouldn't have the fix from the other PR either. Hopefully between that PR and this one it is addressed, and then it will be resolved in the next release

@eallison978
Copy link

eallison978 commented Jan 20, 2026 via email

@eallison978
Copy link

fwiw ... 0.1.2 is what I'm running

@raman325
Copy link
Collaborator Author

no worries thanks for giving it a whirl and if you do end up doing a manual install would appreciate the feedback!

@eallison978
Copy link

If I decide to wait for the HACS update, do you have an idea how long that wait would be?

@tykeal
Copy link
Contributor

tykeal commented Jan 20, 2026

@raman325 gave it an install and here's my finding:

UI seems to be lagging off by one. Put in 3 and when I opened the lock it didn't decrement until I did it again. From then on it counted down properly.

That being said, I ran through 3 (4) cycles quickly in less than a minute (actually ended up being even more) as it didn't start pulling the code until it was at 0 and had been there for at least 30 seconds :-/ so, it's getting better...

@raman325 raman325 force-pushed the fix/number-entity-state-write branch from 61d9e0f to 7be7044 Compare January 21, 2026 02:06
When accesslimit_count changes (either by code usage or user input),
update the UI immediately instead of waiting for coordinator refresh.

Changes:
- Add async_set_updated_data() calls in _lock_unlocked() after
  decrementing accesslimit_count (for both parent and child locks)
- Call _update_slot() after decrement to check if slot should be
  deactivated and clear PIN from lock when count reaches 0
- Add async_write_ha_state() in number entity's async_set_native_value()
  for immediate feedback when user changes the value

The UI notification happens before _update_slot() so users see the
count change immediately, even before the potentially slow PIN clear
operation completes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@raman325 raman325 force-pushed the fix/number-entity-state-write branch from 7be7044 to bcacb3e Compare January 21, 2026 02:10
@raman325
Copy link
Collaborator Author

raman325 commented Jan 21, 2026

@tykeal third times a charm?

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.

4 participants