🐛 Fix KeyError in async_unload_entry #12
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/c5-unload-keyerror"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
async_setup_entryonly wrote a single sharedhass.data[DOMAIN]["cookies"]key, butasync_unload_entrypoppedhass.data[DOMAIN][entry.entry_id]. Unloading any config entry therefore raisedKeyError; the integration could not be cleanly removed without restarting HA, and two config entries for different accounts would trample each other's cookies.hass.data[DOMAIN][entry.entry_id] = {"cookies": ...}and usepop(entry.entry_id, None)in unload. Entities captureentry.entry_idin their constructors and read the cookie jar via the per-entry path.Side-effects
test_unload_entry_cleans_upis dropped; the test now passes normally and asserts both the LOADED→NOT_LOADED transition and that the entry's data is removed fromhass.data[DOMAIN].test_setup_entry_authenticates_and_loadsis updated to check the new, per-entry data shape.Test plan
pytest tests/— 20 passed, 1 xfailed (the remaining xfail is C1, tracked in PR #11).ruff check .— green.Note
This is a surgical fix; the coordinator refactor (C2+C4+C6+H7+M6) will later replace this
hass.data[DOMAIN][entry_id]pattern withentry.runtime_databut that requires restructuring how entities access shared state.