From 90fdded0d8bdbee5df8d9892af36f817037f075e Mon Sep 17 00:00:00 2001 From: Steve Saunders Date: Sat, 26 Oct 2024 07:33:40 +1100 Subject: [PATCH] Time only for reported next update today --- custom_components/solcast_solar/__init__.py | 3 ++- custom_components/solcast_solar/coordinator.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/custom_components/solcast_solar/__init__.py b/custom_components/solcast_solar/__init__.py index 23d48641..3987df0c 100644 --- a/custom_components/solcast_solar/__init__.py +++ b/custom_components/solcast_solar/__init__.py @@ -220,7 +220,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: raise ConfigEntryNotReady(status) coordinator = SolcastUpdateCoordinator(hass, solcast, version) - await coordinator.setup() + if not await coordinator.setup(): + raise ConfigEntryNotReady('Internal error: Coordinator setup failed') await coordinator.async_config_entry_first_refresh() hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator diff --git a/custom_components/solcast_solar/coordinator.py b/custom_components/solcast_solar/coordinator.py index 7133fbcd..7b92833f 100644 --- a/custom_components/solcast_solar/coordinator.py +++ b/custom_components/solcast_solar/coordinator.py @@ -69,7 +69,7 @@ async def _async_update_data(self): """ return self.solcast.get_data() - async def setup(self): + async def setup(self) -> bool: """Set up time change tracking.""" self._last_day = dt.now(self.solcast.options.tz).day try: @@ -81,8 +81,10 @@ async def setup(self): self.tasks['midnight_update'] = async_track_utc_time_change(self._hass, self.__update_utcmidnight_usage_sensor_data, hour=0, minute=0, second=0) for timer, _ in self.tasks.items(): _LOGGER.debug("Started task %s", timer) + return True except: _LOGGER.error("Exception in setup: %s", traceback.format_exc()) + return False async def update_integration_listeners(self, *args): """Get updated sensor values.""" @@ -238,7 +240,7 @@ async def __forecast_update(self, force=False): if len(self._intervals) > 0: next_update = self._intervals[0].astimezone(self.solcast.options.tz) - next_update = next_update.strftime(DATE_FORMAT) if next_update.date() == dt.now().date() else next_update.strftime(TIME_FORMAT) + next_update = next_update.strftime(TIME_FORMAT) if next_update.date() == dt.now().date() else next_update.strftime(DATE_FORMAT) else: next_update = None