diff --git a/src/iaqualink/systems/exo/system.py b/src/iaqualink/systems/exo/system.py index d0db405..6511452 100644 --- a/src/iaqualink/systems/exo/system.py +++ b/src/iaqualink/systems/exo/system.py @@ -8,6 +8,7 @@ from iaqualink.exception import ( AqualinkServiceException, AqualinkSystemOfflineException, + AqualinkServiceUnauthorizedException ) from iaqualink.system import AqualinkSystem from iaqualink.systems.exo.device import ExoDevice @@ -40,7 +41,19 @@ def __repr__(self) -> str: async def send_devices_request(self, **kwargs: Any) -> httpx.Response: url = f"{EXO_DEVICES_URL}/{self.serial}/shadow" headers = {"Authorization": self.aqualink.id_token} - return await self.aqualink.send_request(url, headers=headers, **kwargs) + + try: + r = await self.aqualink.send_request(url, headers=headers, **kwargs) + return r + except AqualinkServiceUnauthorizedException: + try: + # token expired so refresh the token and try again + await self.aqualink.login() + headers = {"Authorization": self.aqualink.id_token} + r = await self.aqualink.send_request(url, headers=headers, **kwargs) + return r + except: + raise async def send_reported_state_request(self) -> httpx.Response: return await self.send_devices_request()