fix(lock): prevent KeyError when Lock Bolt coordinator is missing#797
Open
fix(lock): prevent KeyError when Lock Bolt coordinator is missing#797
Conversation
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>
b5291ce to
4e3f1d6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
coordinators: {}inhass.dataat config entry setup so the key is guaranteed to exist regardless of whether any YD_BT1 locks are found["coordinators"][lock.mac]access inlock.pywith.get()calls; log a warning and skip the device instead of crashing the entire lock platformRoot Cause
A race condition:
setup_coordinators()callsget_locks()and may get an empty or incomplete list (API hiccup, timing), so thecoordinatorskey is never added tohass.data. When the lock platform later callsget_locks()again and finds a YD_BT1 Lock Bolt, the direct dict access crashes withKeyError: 'coordinators', taking down all Wyze lock entities.Test plan
Closes #778
🤖 Generated with Claude Code