Improve Alexa error handling (#24745)
This commit is contained in:
1 parent
8830054fad
commit
510d6d7874
8 files changed
+121
-9
No files matched your search
@@ -14,7 +14,10 @@ from homeassistant.components.http.data_validator import (
|
||||
RequestDataValidator)
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.components.websocket_api import const as ws_const
|
||||
from homeassistant.components.alexa import entities as alexa_entities
|
||||
from homeassistant.components.alexa import (
|
||||
entities as alexa_entities,
|
||||
errors as alexa_errors,
|
||||
)
|
||||
from homeassistant.components.google_assistant import helpers as google_helpers
|
||||
|
||||
from .const import (
|
||||
@@ -375,6 +378,24 @@ async def websocket_update_prefs(hass, connection, msg):
|
||||
changes = dict(msg)
|
||||
changes.pop('id')
|
||||
changes.pop('type')
|
||||
|
||||
# If we turn alexa linking on, validate that we can fetch access token
|
||||
if changes.get(PREF_ALEXA_REPORT_STATE):
|
||||
try:
|
||||
with async_timeout.timeout(10):
|
||||
await cloud.client.alexa_config.async_get_access_token()
|
||||
except asyncio.TimeoutError:
|
||||
connection.send_error(msg['id'], 'alexa_timeout',
|
||||
'Timeout validating Alexa access token.')
|
||||
return
|
||||
except alexa_errors.NoTokenAvailable:
|
||||
connection.send_error(
|
||||
msg['id'], 'alexa_relink',
|
||||
'Please go to the Alexa app and re-link the Home Assistant '
|
||||
'skill and then try to enable state reporting.'
|
||||
)
|
||||
return
|
||||
|
||||
await cloud.client.prefs.async_update(**changes)
|
||||
|
||||
connection.send_message(websocket_api.result_message(msg['id']))
|
||||
@@ -575,7 +596,15 @@ async def alexa_sync(hass, connection, msg):
|
||||
cloud = hass.data[DOMAIN]
|
||||
|
||||
with async_timeout.timeout(10):
|
||||
success = await cloud.client.alexa_config.async_sync_entities()
|
||||
try:
|
||||
success = await cloud.client.alexa_config.async_sync_entities()
|
||||
except alexa_errors.NoTokenAvailable:
|
||||
connection.send_error(
|
||||
msg['id'], 'alexa_relink',
|
||||
'Please go to the Alexa app and re-link the Home Assistant '
|
||||
'skill.'
|
||||
)
|
||||
return
|
||||
|
||||
if success:
|
||||
connection.send_result(msg['id'])
|
||||
|
||||
Reference in new issue
Block a user