Check token scope earlier in Husqvarna Automower (#132289)

This commit is contained in:
Thomas55555 2024-12-04 19:50:15 +01:00 committed by GitHub
parent 2977cf227e
commit e55d8b2d2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 9 deletions

View File

@ -62,6 +62,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: AutomowerConfigEntry) ->
raise ConfigEntryAuthFailed from err
raise ConfigEntryNotReady from err
if "amc:api" not in entry.data["token"]["scope"]:
# We raise ConfigEntryAuthFailed here because the websocket can't be used
# without the scope. So only polling would be possible.
raise ConfigEntryAuthFailed
coordinator = AutomowerDataUpdateCoordinator(hass, automower_api, entry)
await coordinator.async_config_entry_first_refresh()
available_devices = list(coordinator.data)
@ -74,11 +79,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: AutomowerConfigEntry) ->
"websocket_task",
)
if "amc:api" not in entry.data["token"]["scope"]:
# We raise ConfigEntryAuthFailed here because the websocket can't be used
# without the scope. So only polling would be possible.
raise ConfigEntryAuthFailed
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True

View File

@ -5,10 +5,7 @@ rules:
unique-config-entry: done
config-flow-test-coverage: done
runtime-data: done
test-before-setup:
status: todo
comment: |
Raise ConfigEntryAuthFailed earlier, when "amc:api" is missing in the token scope.
test-before-setup: done
appropriate-polling: done
entity-unique-id: done
has-entity-name: done