Skip to content

fix(lock): prevent KeyError when Lock Bolt coordinator is missing#797

Open
SecKatie wants to merge 2 commits intomasterfrom
fix/lock-bolt-coordinator-keyerror
Open

fix(lock): prevent KeyError when Lock Bolt coordinator is missing#797
SecKatie wants to merge 2 commits intomasterfrom
fix/lock-bolt-coordinator-keyerror

Conversation

@SecKatie
Copy link
Copy Markdown
Owner

@SecKatie SecKatie commented Mar 5, 2026

Summary

  • Always initialize coordinators: {} in hass.data at config entry setup so the key is guaranteed to exist regardless of whether any YD_BT1 locks are found
  • Replace direct ["coordinators"][lock.mac] access in lock.py with .get() calls; log a warning and skip the device instead of crashing the entire lock platform

Root Cause

A race condition: setup_coordinators() calls get_locks() and may get an empty or incomplete list (API hiccup, timing), so the coordinators key is never added to hass.data. When the lock platform later calls get_locks() again and finds a YD_BT1 Lock Bolt, the direct dict access crashes with KeyError: 'coordinators', taking down all Wyze lock entities.

Test plan

  • Verify Wyze Lock (non-YD_BT1) still loads and locks/unlocks correctly
  • Verify Wyze Lock Bolt (YD_BT1) loads when coordinator is present
  • Confirm no crash occurs when coordinator is missing for a YD_BT1 device (warning logged instead)

Closes #778

🤖 Generated with Claude Code

SecKatie and others added 2 commits March 4, 2026 23:50
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Always initialize the 'coordinators' dict in hass.data at entry setup
so the key is guaranteed to exist. In lock.py, use .get() instead of
direct dict access and log a warning + skip when a YD_BT1 lock has no
coordinator, rather than crashing the entire lock platform.

Fixes a race condition where setup_coordinators() could find no YD_BT1
devices (e.g. due to an API hiccup) while the lock platform's own
get_locks() call did find one, causing KeyError: 'coordinators'.

Closes #778

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SecKatie SecKatie force-pushed the fix/lock-bolt-coordinator-keyerror branch from b5291ce to 4e3f1d6 Compare March 5, 2026 04:50
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.

[Bug] Wyze Lock is no Longer Working after v0.1.36 update

1 participant