Skip to content

Commit

Permalink
Time only for reported next update today
Browse files Browse the repository at this point in the history
  • Loading branch information
autoSteve committed Oct 25, 2024
1 parent dd6c6ff commit 90fdded
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion custom_components/solcast_solar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions custom_components/solcast_solar/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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."""
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 90fdded

Please sign in to comment.