How to use the alexapy.AlexapyLoginError function in AlexaPy

To help you get started, we’ve selected a few AlexaPy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ikifar2012 / Home-AssistantConfig / custom_components / alexa_media / __init__.py View on Github external
(
                        devices,
                        bluetooth,
                        preferences,
                        dnd,
                        raw_notifications,
                    ) = await asyncio.gather(*tasks)
                _LOGGER.debug(
                    "%s: Found %s devices, %s bluetooth",
                    hide_email(email),
                    len(devices) if devices is not None else "",
                    len(bluetooth.get("bluetoothStates", []))
                    if bluetooth is not None
                    else "",
                )
        except (AlexapyLoginError, JSONDecodeError):
            _LOGGER.debug(
                "%s: Alexa API disconnected; attempting to relogin : status %s",
                hide_email(email),
                login_obj.status,
            )
            if login_obj.status:
                await login_obj.reset()
                await login_obj.login()
                await test_login_status(hass, config_entry, login_obj, setup_alexa)
            return
        except BaseException as err:
            raise UpdateFailed(f"Error communicating with API: {err}")

        await process_notifications(login_obj, raw_notifications)
        # Process last_called data to fire events
        await update_last_called(login_obj)
github eifinger / homeassistant-config / custom_components / alexa_media / __init__.py View on Github external
(
                        devices,
                        bluetooth,
                        preferences,
                        dnd,
                        raw_notifications,
                    ) = await asyncio.gather(*tasks)
                _LOGGER.debug(
                    "%s: Found %s devices, %s bluetooth",
                    hide_email(email),
                    len(devices) if devices is not None else "",
                    len(bluetooth.get("bluetoothStates", []))
                    if bluetooth is not None
                    else "",
                )
        except (AlexapyLoginError, JSONDecodeError):
            _LOGGER.debug(
                "%s: Alexa API disconnected; attempting to relogin : status %s",
                hide_email(email),
                login_obj.status,
            )
            if login_obj.status:
                await hass.bus.async_fire(
                    "alexa_media_player/relogin_required",
                    event_data={"email": hide_email(email), "url": login_obj.url},
                )
                await login_obj.reset()
                await login_obj.login()
                await test_login_status(hass, config_entry, login_obj, setup_alexa)
            return
        except BaseException as err:
            raise UpdateFailed(f"Error communicating with API: {err}")
github custom-components / alexa_media_player / custom_components / alexa_media / __init__.py View on Github external
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)
            raw_notifications = await AlexaAPI.get_notifications(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 AlexapyLoginError()
        except (AlexapyLoginError, RuntimeError):
            _LOGGER.debug("%s: Alexa API disconnected; attempting to relogin",
                          hide_email(email))
            await login_obj.login_with_cookie()
            await test_login_status(hass,
                                    config_entry, login_obj,
                                    setup_platform_callback)
            return

        new_alexa_clients = []  # list of newly discovered device names
        exclude_filter = []
        include_filter = []

        for device in devices:
            if include and device['accountName'] not in include:
                include_filter.append(device['accountName'])
                if 'appDeviceList' in device:
github eliseomartelli / ParentsHomeAutomation / homeassistant / custom_components / alexa_media / __init__.py View on Github external
(
                        devices,
                        bluetooth,
                        preferences,
                        dnd,
                        raw_notifications,
                    ) = await asyncio.gather(*tasks)
                _LOGGER.debug(
                    "%s: Found %s devices, %s bluetooth",
                    hide_email(email),
                    len(devices) if devices is not None else "",
                    len(bluetooth.get("bluetoothStates", []))
                    if bluetooth is not None
                    else "",
                )
        except (AlexapyLoginError, JSONDecodeError):
            _LOGGER.debug(
                "%s: Alexa API disconnected; attempting to relogin : status %s",
                hide_email(email),
                login_obj.status,
            )
            if login_obj.status:
                await hass.bus.async_fire(
                    "alexa_media_player/relogin_required",
                    event_data={"email": hide_email(email), "url": login_obj.url},
                )
                await login_obj.reset()
                await login_obj.login()
                await test_login_status(hass, config_entry, login_obj, setup_alexa)
            return
        except BaseException as err:
            raise UpdateFailed(f"Error communicating with API: {err}")
github eifinger / homeassistant-config / custom_components / alexa_media / helpers.py View on Github external
async def wrapper(*args, **kwargs) -> Any:
        instance = args[0]
        result = None
        if hasattr(instance, "check_login_changes"):
            instance.check_login_changes()
        try:
            result = await func(*args, **kwargs)
        except AlexapyLoginCloseRequested:
            _LOGGER.debug(
                "%s.%s: Ignoring attempt to access Alexa after HA shutdown",
                func.__module__[func.__module__.find(".") + 1 :],
                func.__name__,
            )
            return None
        except AlexapyLoginError as ex:
            _LOGGER.debug(
                "%s.%s: detected bad login: %s",
                func.__module__[func.__module__.find(".") + 1 :],
                func.__name__,
                EXCEPTION_TEMPLATE.format(type(ex).__name__, ex.args),
            )
            instance = args[0]
            if hasattr(instance, "_login"):
                login = instance._login
                email = login.email
                hass = instance.hass if instance.hass else None
                if hass and (
                    "configurator"
                    not in (hass.data[DATA_ALEXAMEDIA]["accounts"][email])
                    or not (
                        hass.data[DATA_ALEXAMEDIA]["accounts"][email]["configurator"]