diff --git a/custom_components/hildebrandglow_dcc/glow.py b/custom_components/hildebrandglow_dcc/glow.py index 456a138..fdcd8c0 100644 --- a/custom_components/hildebrandglow_dcc/glow.py +++ b/custom_components/hildebrandglow_dcc/glow.py @@ -47,7 +47,8 @@ def authenticate(cls, app_id: str, username: str, password: str) -> Dict[str, An pprint(data) raise InvalidAuth - async def handle_failed_auth(self, config: ConfigEntry, hass: HomeAssistant) -> None: + @staticmethod + async def handle_failed_auth(config: ConfigEntry, hass: HomeAssistant) -> None: """Attempt to refresh the current Glow token.""" glow_auth = await hass.async_add_executor_job( Glow.authenticate, @@ -89,8 +90,13 @@ def current_usage(self, resource: Dict[str, Any]) -> Dict[str, Any]: # Need to pull updated data from DCC first catchup_url = f"{self.BASE_URL}/resource/{resource}/catchup" - url = f"{self.BASE_URL}/resource/{resource}/readings?from=" + current_date + \ - "T00:00:00&to=" + current_date + "T23:59:59&period=P1D&offset=-60&function=sum" + url = ( + f"{self.BASE_URL}/resource/{resource}/readings?from=" + + current_date + + "T00:00:00&to=" + + current_date + + "T23:59:59&period=P1D&offset=-60&function=sum" + ) headers = {"applicationId": self.app_id, "token": self.token} try: @@ -102,7 +108,8 @@ def current_usage(self, resource: Dict[str, Any]) -> Dict[str, Any]: if response.status_code != 200: if response.json()["error"] == "incorrect elements -from in the future": _LOGGER.info( - "Attempted to load data from the future - expected if the day has just changed") + "Attempted to load data from the future - expected if the day has just changed" + ) elif response.status_code == 401: raise InvalidAuth else: diff --git a/custom_components/hildebrandglow_dcc/sensor.py b/custom_components/hildebrandglow_dcc/sensor.py index b8061c9..5a4b654 100644 --- a/custom_components/hildebrandglow_dcc/sensor.py +++ b/custom_components/hildebrandglow_dcc/sensor.py @@ -39,6 +39,7 @@ async def async_setup_entry( except InvalidAuth: try: await Glow.handle_failed_auth(config, hass) + except InvalidAuth: return False