From cb3a8fb90eb116edcd5be3c270c8041a8633bd23 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Mon, 23 Sep 2019 00:17:31 -0700 Subject: [PATCH] fix(update_devices): prompt for login on disconnect --- custom_components/alexa_media/__init__.py | 27 +++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/custom_components/alexa_media/__init__.py b/custom_components/alexa_media/__init__.py index cf491af7..bfe600a1 100644 --- a/custom_components/alexa_media/__init__.py +++ b/custom_components/alexa_media/__init__.py @@ -345,18 +345,21 @@ async def update_devices(login_obj): ['accounts'][email]['new_devices'])): return hass.data[DATA_ALEXAMEDIA]['accounts'][email]['new_devices'] = False - auth_info = await AlexaAPI.get_authentication(login_obj) - devices = await AlexaAPI.get_devices(login_obj) - bluetooth = await AlexaAPI.get_bluetooth(login_obj) - preferences = await AlexaAPI.get_device_preferences(login_obj) - dnd = await AlexaAPI.get_dnd_state(login_obj) - _LOGGER.debug("%s: Found %s devices, %s bluetooth", - hide_email(email), - len(devices) if devices is not None else '', - len(bluetooth) if bluetooth is not None else '') - if ((devices is None or bluetooth is None) - and not (hass.data[DATA_ALEXAMEDIA] - ['accounts'][email]['configurator'])): + try: + auth_info = await AlexaAPI.get_authentication(login_obj) + devices = await AlexaAPI.get_devices(login_obj) + bluetooth = await AlexaAPI.get_bluetooth(login_obj) + preferences = await AlexaAPI.get_device_preferences(login_obj) + dnd = await AlexaAPI.get_dnd_state(login_obj) + _LOGGER.debug("%s: Found %s devices, %s bluetooth", + hide_email(email), + len(devices) if devices is not None else '', + len(bluetooth) if bluetooth is not None else '') + if ((devices is None or bluetooth is None) + and not (hass.data[DATA_ALEXAMEDIA] + ['accounts'][email]['configurator'])): + raise RuntimeError() + except RuntimeError: _LOGGER.debug("%s: Alexa API disconnected; attempting to relogin", hide_email(email)) await login_obj.login()