From e55d8b2d2b5db3b72899fd98b82f342bc1e11c4c Mon Sep 17 00:00:00 2001 From: Thomas55555 <59625598+Thomas55555@users.noreply.github.com> Date: Wed, 4 Dec 2024 19:50:15 +0100 Subject: [PATCH] Check token scope earlier in Husqvarna Automower (#132289) --- .../components/husqvarna_automower/__init__.py | 10 +++++----- .../components/husqvarna_automower/quality_scale.yaml | 5 +---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/husqvarna_automower/__init__.py b/homeassistant/components/husqvarna_automower/__init__.py index 822f81f5f75..3b08a766f1c 100644 --- a/homeassistant/components/husqvarna_automower/__init__.py +++ b/homeassistant/components/husqvarna_automower/__init__.py @@ -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 diff --git a/homeassistant/components/husqvarna_automower/quality_scale.yaml b/homeassistant/components/husqvarna_automower/quality_scale.yaml index 384d58b7ece..1b5accafe17 100644 --- a/homeassistant/components/husqvarna_automower/quality_scale.yaml +++ b/homeassistant/components/husqvarna_automower/quality_scale.yaml @@ -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