Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure refresh schedule is setup after a failed call to Solcast #213

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion custom_components/foxess_em/battery/battery_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def refresh(self, *args) -> None: # pylint: disable=unused-argument
except NoDataError as ex:
_LOGGER.warning(ex)
except Exception as ex:
_LOGGER.error(ex)
_LOGGER.error(f"{ex!r}")

def update_callback(self) -> None:
"""Schedule a refresh"""
Expand Down
24 changes: 19 additions & 5 deletions custom_components/foxess_em/forecast/forecast_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async def load(self, *args) -> None:
_LOGGER.debug(
"Finished loading forecast data from cache, notifying listeners"
)
await self._async_get_site_info()
self._notify_listeners()
else:
await self.async_refresh()
Expand Down Expand Up @@ -145,17 +146,30 @@ async def async_refresh(self, *args) -> None: # pylint: disable=unused-argument
await self._api.refresh()
self._last_update = datetime.now().astimezone()

_LOGGER.debug("Finished refreshing forecast data, notifying listeners")
self._notify_listeners()
except NoDataError as ex:
_LOGGER.warning(ex)
except Exception as ex:
_LOGGER.error(f"{ex!r}")

await self._async_get_site_info()

async def _async_get_site_info(
self, *args
) -> None: # pylint: disable=unused-argument
"""Refresh site info"""
try:
_LOGGER.debug("Refreshing Solcast site info")

api_status = await self._api.api_status()
self._api_count = api_status["daily_limit_consumed"]
self._api_limit = api_status["daily_limit"]
await self._setup_refresh()

_LOGGER.debug("Finished refreshing forecast data, notifying listeners")
self._notify_listeners()
except NoDataError as ex:
_LOGGER.warning(ex)
_LOGGER.debug("Finished refreshing Solcast site info")
except Exception as ex:
_LOGGER.error(ex)
_LOGGER.error(f"{ex!r}")

def resample_data(self) -> DataFrame:
"""Return resampled data"""
Expand Down