Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion custom_components/shade_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,17 @@ def __init__(self, hass: HomeAssistant, zones: dict[str, Zone]) -> None:
self._cover_to_zone[cover] = zone
self._hold_timers: dict[str, object] = {}
self._unsubs: list = []
self._stopped = False

# -- lifecycle ----------------------------------------------------------

@callback
def async_start(self, delay: float = STARTUP_DELAY) -> None:
"""Subscribe to everything and schedule the first reconcile."""
if self._stopped:
# Replaced by a reload before HA finished booting; the deferred
# start must not resurrect this engine alongside its successor.
return
self._unsubs.append(
async_track_state_change_event(self.hass, [SUN_ENTITY], self._sun_changed)
)
Expand All @@ -318,9 +323,15 @@ async def _initial(_now) -> None:

self._unsubs.append(async_call_later(self.hass, delay, _initial))

@callback
def track_unsub(self, unsub) -> None:
"""Register an external subscription to cancel on stop."""
self._unsubs.append(unsub)

@callback
def async_stop(self) -> None:
"""Unsubscribe from everything; the engine issues no further commands."""
self._stopped = True
for unsub in self._unsubs:
unsub()
self._unsubs.clear()
Expand Down Expand Up @@ -661,7 +672,9 @@ def _start(_event: Event) -> None:
if hass.state is CoreState.running:
engine.async_start()
else:
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, _start)
engine.track_unsub(
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, _start)
)
return True


Expand Down
2 changes: 1 addition & 1 deletion custom_components/shade_engine/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"issue_tracker": "https://github.com/vfilby/shade-engine/issues",
"requirements": [],
"single_config_entry": true,
"version": "0.7.0"
"version": "0.7.1"
}
Loading