From 5008c27e7a6f94365180f5e3c991ac7eb31b615d Mon Sep 17 00:00:00 2001 From: Ruslan Sayfutdinov Date: Thu, 29 Apr 2021 05:31:08 +0100 Subject: [PATCH] Relax type annotation for DataUpdateCoordinator data (#49827) --- homeassistant/helpers/update_coordinator.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/update_coordinator.py b/homeassistant/helpers/update_coordinator.py index f9b97698220..09844640ce7 100644 --- a/homeassistant/helpers/update_coordinator.py +++ b/homeassistant/helpers/update_coordinator.py @@ -52,7 +52,12 @@ class DataUpdateCoordinator(Generic[T]): self.update_method = update_method self.update_interval = update_interval - self.data: T | None = None + # It's None before the first successful update. + # Components should call async_config_entry_first_refresh + # to make sure the first update was successful. + # Set type to just T to remove annoying checks that data is not None + # when it was already checked during setup. + self.data: T = None # type: ignore[assignment] self._listeners: list[CALLBACK_TYPE] = [] self._job = HassJob(self._handle_refresh_interval) @@ -133,7 +138,7 @@ class DataUpdateCoordinator(Generic[T]): """ await self._debounced_refresh.async_call() - async def _async_update_data(self) -> T | None: + async def _async_update_data(self) -> T: """Fetch the latest data from the source.""" if self.update_method is None: raise NotImplementedError("Update method not implemented")