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

Fix SharkIQ token expiration #89357

7 changes: 6 additions & 1 deletion homeassistant/components/sharkiq/update_coordinator.py
Expand Up @@ -60,6 +60,9 @@ async def _async_update_vacuum(sharkiq: SharkIqVacuum) -> None:
async def _async_update_data(self) -> bool:
"""Update data device by device."""
try:
if self.ayla_api.token_expiring_soon:
await self.ayla_api.async_refresh_auth()

all_vacuums = await self.ayla_api.async_list_devices()
self._online_dsns = {
v["dsn"]
Expand All @@ -76,9 +79,11 @@ async def _async_update_data(self) -> bool:
SharkIqAuthExpiringError,
) as err:
LOGGER.debug("Bad auth state. Attempting re-auth", exc_info=err)
await self.ayla_api.async_sign_in()
raise ConfigEntryAuthFailed from err
funkybunch marked this conversation as resolved.
Show resolved Hide resolved
except Exception as err:
LOGGER.exception("Unexpected error updating SharkIQ")
LOGGER.exception("Unexpected error updating SharkIQ. Attempting re-auth")
await self.ayla_api.async_sign_in()
raise UpdateFailed(err) from err

return True
3 changes: 3 additions & 0 deletions tests/components/sharkiq/test_vacuum.py
Expand Up @@ -75,6 +75,9 @@ class MockAyla(AylaApi):
async def async_sign_in(self):
"""Instead of signing in, just return."""

async def async_refresh_auth(self):
"""Instead of refreshing auth, just return."""

async def async_list_devices(self) -> list[dict]:
"""Return the device list."""
return [SHARK_DEVICE_DICT]
Expand Down