Merge pull request #28 from ijardillier/fix/cover-restore-state

Fix cover restore to avoid staying stuck unavailable after restart
This commit is contained in:
Daniel Moindrot
2026-06-12 08:02:54 +02:00
committed by GitHub
+9 -2
View File
@@ -126,7 +126,11 @@ class AirSendCover(RestoreEntity, CoverEntity):
# Get the last known state
last_state = await self.async_get_last_state()
if last_state:
# Only restore from a meaningful previous state. If HASS was
# restarted while the entity was "unavailable" (e.g. AirSend
# connectivity loss), don't carry that over: keep the defaults
# so the entity comes back available instead of staying stuck.
if last_state and last_state.state not in ('unavailable', 'unknown'):
# Restore position for covers with position support (type 4099)
if self._device.is_cover_with_position:
# Try to restore position from attributes
@@ -144,5 +148,8 @@ class AirSendCover(RestoreEntity, CoverEntity):
self._closed = True
elif last_state.state == 'open':
self._closed = False
# If no usable last_state, keep the defaults (50% for position covers)
# Always publish the current state so the entity doesn't stay
# stuck on a stale cached state across a restart.
self.async_write_ha_state()
# If no last_state, keep the defaults (50% for position covers)