fix(coordinator): kurze Aussetzer machen die Lampe nicht unbedienbar
This commit is contained in:
@@ -21,7 +21,7 @@ from .api import (
|
||||
NinlightError,
|
||||
NinlightRequestError,
|
||||
)
|
||||
from .const import CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL, DOMAIN
|
||||
from .const import CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL, DOMAIN, MAX_POLL_FAILURES
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -58,6 +58,8 @@ class NinlightCoordinator(DataUpdateCoordinator[NinlightData]):
|
||||
self.lock = asyncio.Lock()
|
||||
# While a firmware update runs, the update entity watches the lamp itself.
|
||||
self.ota_in_progress = False
|
||||
# Consecutive poll failures; a short outage should not flip the lamp unavailable.
|
||||
self._consecutive_poll_failures = 0
|
||||
|
||||
async def _async_update_data(self) -> NinlightData:
|
||||
if self.ota_in_progress and self.data is not None:
|
||||
@@ -69,7 +71,18 @@ class NinlightCoordinator(DataUpdateCoordinator[NinlightData]):
|
||||
except NinlightAuthError as err:
|
||||
raise ConfigEntryAuthFailed(f"{self.client.host}: token rejected") from err
|
||||
except NinlightError as err:
|
||||
self._consecutive_poll_failures += 1
|
||||
if self.data is not None and self._consecutive_poll_failures < MAX_POLL_FAILURES:
|
||||
_LOGGER.debug(
|
||||
"%s: poll failed (%d/%d), keeping last known state: %s",
|
||||
self.client.host,
|
||||
self._consecutive_poll_failures,
|
||||
MAX_POLL_FAILURES,
|
||||
err,
|
||||
)
|
||||
return self.data
|
||||
raise UpdateFailed(f"{self.client.host}: {err}") from err
|
||||
self._consecutive_poll_failures = 0
|
||||
return NinlightData(state, info)
|
||||
|
||||
async def async_call[T](self, action: Callable[[NinlightClient], Awaitable[T]]) -> T:
|
||||
@@ -100,4 +113,5 @@ class NinlightCoordinator(DataUpdateCoordinator[NinlightData]):
|
||||
async def async_set_state(self, **fields: Any) -> None:
|
||||
"""Write and adopt the lamp's complete answer directly - no debounced refresh."""
|
||||
state = await self.async_call(lambda client: client.set_state(**fields))
|
||||
self._consecutive_poll_failures = 0
|
||||
self.async_set_updated_data(NinlightData(state, self.data.info))
|
||||
|
||||
Reference in New Issue
Block a user