Skip to content

Conversation

@raman325
Copy link
Owner

@raman325 raman325 commented Jan 8, 2026

Proposed change

When a lock has code slots with masked PINs (all *'s) that aren't managed by Lock Code Manager, the async_get_usercodes() function would crash with RuntimeError: coroutine raised StopIteration.

This occurred because the code iterated over ALL slots from the lock's cache, but the next() call at line 434 tried to find a matching LCM config entry for each slot. Slots not managed by LCM have no corresponding config entry, causing StopIteration to be raised inside the async function, which Python 3.7+ converts to RuntimeError.

The fix adds an early check: if the slot isn't in the configured code_slots, we record an empty string and skip the config entry lookup entirely.

Also adds a regression test to prevent this from recurring.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue:
  • This PR is related to issue:

🤖 Generated with Claude Code

When a lock has code slots with masked PINs (all *'s) that aren't
managed by Lock Code Manager, the async_get_usercodes() function
would crash with "RuntimeError: coroutine raised StopIteration".

This occurred because the code tried to find a matching LCM config
entry for every slot on the lock, but slots not managed by LCM have
no corresponding config entry.

The fix adds an early check: if the slot isn't in the configured
code_slots, we record an empty string and skip the config entry
lookup entirely.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 8, 2026 06:09
@github-actions github-actions bot added bug Something isn't working python Pull requests that update Python code labels Jan 8, 2026
Fixes CI conflict with HA 2026.1.0 final release.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Jan 8, 2026
Copy link
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 a RuntimeError: coroutine raised StopIteration crash that occurred when a Z-Wave JS lock has code slots with masked PINs (all *'s) that are not managed by Lock Code Manager. The bug was caused by attempting to find a matching LCM config entry for unmanaged slots using next(), which raised StopIteration when no match was found.

Key changes:

  • Added early validation to skip config entry lookup for unmanaged slots with masked PINs
  • Added regression test to prevent this issue from recurring
  • Removed redundant conditional check around logging statement

Reviewed changes

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

File Description
custom_components/lock_code_manager/providers/zwave_js.py Added early return logic to handle unmanaged slots with masked PINs, preventing StopIteration from being raised
tests/providers/test_zwave_js.py Added comprehensive regression test that verifies the fix by testing both managed and unmanaged slots with masked PINs

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

raman325 and others added 2 commits January 8, 2026 01:19
Fixes CI test failures with pytest-asyncio 1.3.0 that occur due to
event loop scoping issues ("Timeout context manager should be used
inside a task").

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The autouse=True on the aiohttp_client override was causing event loop
scoping issues in CI with pytest-asyncio 1.3.0.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@raman325 raman325 merged commit 561bb49 into main Jan 8, 2026
7 checks passed
@raman325 raman325 deleted the fix branch January 8, 2026 06:25
@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.13%. Comparing base (8920cb3) to head (4a0b78c).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
...components/lock_code_manager/providers/zwave_js.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #760      +/-   ##
==========================================
- Coverage   93.21%   93.13%   -0.08%     
==========================================
  Files          29       29              
  Lines        2357     2359       +2     
  Branches       77       77              
==========================================
  Hits         2197     2197              
- Misses        160      162       +2     
Flag Coverage Δ
python 92.79% <75.00%> (-0.09%) ⬇️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Pull requests that update a dependency file python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants