fix(#32): keep helper alive when a source sensor disappears#38
Open
AlexMKX wants to merge 5 commits into
Open
Conversation
…removed Reload the entry instead of removing it. The helper now stays in the registry; its binary sensor becomes unavailable until the source sensor returns.
…urce is missing - async_setup_entry no longer returns False when a source entity_id is not in the registry; logs a warning and proceeds, letting the state-change listener pick up the entity when it appears. - WaspInABoxSensor.available is False whenever a source state is missing/unknown/unavailable, so HA shows the helper as 'unavailable' rather than a stale value. - async_added_to_hass replays state unconditionally so the unavailable state is reflected even when one of the sources is absent from the registry at startup.
- _resolve() now takes a label ('Motion'/'Door') so the warning makes
clear which source is missing; the duplicated 'wasp_in_a_box:'
prefix is dropped (logger namespace already provides it).
- test_source_returns_makes_helper_available asserts the helper
reports 'off' (both sources off) initially, not just !=
'unavailable'.
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.
Fixes #32.
Problem
async_registry_updatedremoves the helper's own ConfigEntry whenever a source sensor (motion or door) is removed from the entity registry. This is what users see as 'the helper disappears after restart' — typically a Zigbee/MQTT device is rebuilt or re-paired, the source entity is briefly absent, and the helper is then permanently gone with all dependent automations broken.async_setup_entryalso returnsFalseif a source entity_id is not in the registry at startup, marking the entry as setup_error.Fix
async_registry_updatednow reloads the entry on source removal instead of removing it. The helper stays; its binary_sensor becomesunavailableuntil the source returns.async_setup_entryno longer hard-fails on a missing source. It logs a warning (now labeled as 'Motion' / 'Door' so it's obvious which one is missing) and proceeds — the existingasync_track_state_change_eventlistener picks up the entity when it appears.availableproperty onWaspInABoxSensor:Falsewhenever a source state is missing/unknown/unavailable. Users seeunavailable(semantically correct) instead of a stale value.async_added_to_hassreplays state unconditionally so the unavailable state is reflected at startup even when a source is absent.Tests
Three new regression tests in
tests/test_init.py, all passing:test_source_removal_preserves_entry— source removal preserves the ConfigEntry.test_setup_with_missing_source_loads_unavailable— setup with a missing source loads the entry and exposes the helper asunavailable.test_source_returns_makes_helper_available— end-to-end recovery: remove → unavailable → recreate → available.All existing tests still pass (6/6).
ruff checkandruff formatclean.Commits