mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Catch uncaught Alexa error (#24785)
This commit is contained in:
parent
71346760d0
commit
c87d6e4720
@ -23,7 +23,7 @@ from homeassistant.components.google_assistant import helpers as google_helpers
|
|||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN, REQUEST_TIMEOUT, PREF_ENABLE_ALEXA, PREF_ENABLE_GOOGLE,
|
DOMAIN, REQUEST_TIMEOUT, PREF_ENABLE_ALEXA, PREF_ENABLE_GOOGLE,
|
||||||
PREF_GOOGLE_SECURE_DEVICES_PIN, InvalidTrustedNetworks,
|
PREF_GOOGLE_SECURE_DEVICES_PIN, InvalidTrustedNetworks,
|
||||||
InvalidTrustedProxies, PREF_ALEXA_REPORT_STATE)
|
InvalidTrustedProxies, PREF_ALEXA_REPORT_STATE, RequireRelink)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ async def websocket_update_prefs(hass, connection, msg):
|
|||||||
connection.send_error(msg['id'], 'alexa_timeout',
|
connection.send_error(msg['id'], 'alexa_timeout',
|
||||||
'Timeout validating Alexa access token.')
|
'Timeout validating Alexa access token.')
|
||||||
return
|
return
|
||||||
except alexa_errors.NoTokenAvailable:
|
except (alexa_errors.NoTokenAvailable, RequireRelink):
|
||||||
connection.send_error(
|
connection.send_error(
|
||||||
msg['id'], 'alexa_relink',
|
msg['id'], 'alexa_relink',
|
||||||
'Please go to the Alexa app and re-link the Home Assistant '
|
'Please go to the Alexa app and re-link the Home Assistant '
|
||||||
|
@ -12,7 +12,7 @@ from homeassistant.core import State
|
|||||||
from homeassistant.auth.providers import trusted_networks as tn_auth
|
from homeassistant.auth.providers import trusted_networks as tn_auth
|
||||||
from homeassistant.components.cloud.const import (
|
from homeassistant.components.cloud.const import (
|
||||||
PREF_ENABLE_GOOGLE, PREF_ENABLE_ALEXA, PREF_GOOGLE_SECURE_DEVICES_PIN,
|
PREF_ENABLE_GOOGLE, PREF_ENABLE_ALEXA, PREF_GOOGLE_SECURE_DEVICES_PIN,
|
||||||
DOMAIN)
|
DOMAIN, RequireRelink)
|
||||||
from homeassistant.components.google_assistant.helpers import (
|
from homeassistant.components.google_assistant.helpers import (
|
||||||
GoogleEntity)
|
GoogleEntity)
|
||||||
from homeassistant.components.alexa.entities import LightCapabilities
|
from homeassistant.components.alexa.entities import LightCapabilities
|
||||||
@ -527,6 +527,44 @@ async def test_websocket_update_preferences(hass, hass_ws_client,
|
|||||||
assert setup_api[PREF_GOOGLE_SECURE_DEVICES_PIN] == '1234'
|
assert setup_api[PREF_GOOGLE_SECURE_DEVICES_PIN] == '1234'
|
||||||
|
|
||||||
|
|
||||||
|
async def test_websocket_update_preferences_require_relink(
|
||||||
|
hass, hass_ws_client, aioclient_mock, setup_api, mock_cloud_login):
|
||||||
|
"""Test updating preference requires relink."""
|
||||||
|
client = await hass_ws_client(hass)
|
||||||
|
|
||||||
|
with patch('homeassistant.components.cloud.alexa_config.AlexaConfig'
|
||||||
|
'.async_get_access_token',
|
||||||
|
side_effect=RequireRelink):
|
||||||
|
await client.send_json({
|
||||||
|
'id': 5,
|
||||||
|
'type': 'cloud/update_prefs',
|
||||||
|
'alexa_report_state': True,
|
||||||
|
})
|
||||||
|
response = await client.receive_json()
|
||||||
|
|
||||||
|
assert not response['success']
|
||||||
|
assert response['error']['code'] == 'alexa_relink'
|
||||||
|
|
||||||
|
|
||||||
|
async def test_websocket_update_preferences_no_token(
|
||||||
|
hass, hass_ws_client, aioclient_mock, setup_api, mock_cloud_login):
|
||||||
|
"""Test updating preference no token available."""
|
||||||
|
client = await hass_ws_client(hass)
|
||||||
|
|
||||||
|
with patch('homeassistant.components.cloud.alexa_config.AlexaConfig'
|
||||||
|
'.async_get_access_token',
|
||||||
|
side_effect=alexa_errors.NoTokenAvailable):
|
||||||
|
await client.send_json({
|
||||||
|
'id': 5,
|
||||||
|
'type': 'cloud/update_prefs',
|
||||||
|
'alexa_report_state': True,
|
||||||
|
})
|
||||||
|
response = await client.receive_json()
|
||||||
|
|
||||||
|
assert not response['success']
|
||||||
|
assert response['error']['code'] == 'alexa_relink'
|
||||||
|
|
||||||
|
|
||||||
async def test_enabling_webhook(hass, hass_ws_client, setup_api,
|
async def test_enabling_webhook(hass, hass_ws_client, setup_api,
|
||||||
mock_cloud_login):
|
mock_cloud_login):
|
||||||
"""Test we call right code to enable webhooks."""
|
"""Test we call right code to enable webhooks."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user