Fix cover restore to avoid staying stuck unavailable after restart

This commit is contained in:
Ingrid JARDILLIER
2026-06-11 21:52:35 +02:00
parent b688219e1a
commit 8db90ed88c
+10 -3
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
self.async_write_ha_state()
# If no last_state, keep the defaults (50% for position covers)
# 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()