Skip to content

Commit

Permalink
Logout after testing credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Dec 18, 2024
1 parent 7acd9f8 commit a498311
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions custom_components/polestar_api/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ async def _test_credentials(
password=password,
client_session=get_async_client(self.hass),
)
await api_client.async_init()

if found_vins := api_client.get_available_vins():
_LOGGER.debug("Found %d VINs for %s", len(found_vins), username)
else:
_LOGGER.warning("No VINs found for %s", username)
raise NoCarsFoundException
try:
await api_client.async_init()

if vin and vin not in found_vins:
_LOGGER.warning("VIN %s not found for %s", vin, username)
raise VinNotFoundException
if found_vins := api_client.get_available_vins():
_LOGGER.debug("Found %d VINs for %s", len(found_vins), username)
else:
_LOGGER.warning("No VINs found for %s", username)
raise NoCarsFoundException

if vin and vin not in found_vins:
_LOGGER.warning("VIN %s not found for %s", vin, username)
raise VinNotFoundException
finally:
await api_client.async_logout()

0 comments on commit a498311

Please sign in to comment.