Skip to content

Commit

Permalink
Merge pull request #385 from custom-components/dev
Browse files Browse the repository at this point in the history
2.2.1
  • Loading branch information
alandtse authored Sep 22, 2019
2 parents 0d470f1 + 7a27a20 commit 84dcdde
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 23 deletions.
54 changes: 54 additions & 0 deletions custom_components/alexa_media/.translations/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"config": {
"error": {
"identifier_exists": "L'Email per l'URL di Alexa è già stata registrata",
"invalid_credentials": "Credenziali non valide"
},
"step": {
"user": {
"data": {
"password": "Password",
"email": "Indirizzo email",
"url": "Regione del dominio Amazon (e.g., amazon.it)",
"include_devices": "Dispositivi da includere (separati da virgola)",
"exclude_devices": "Dispositivi da escludere (separati da virgola)",
"debug": "Debug avanzato",
"scan_interval": "Tempo in secondi fra le scansioni"
},
"description": "Prego inserisci le tue informazioni.",
"title": "Alexa Media Player - Configurazione"
},
"captcha": {
"data": {
"password": "Password",
"captcha": "Captcha"
},
"description": "**{email} - alexa.{url}**\n{message}\n {captcha_image}",
"title": "Alexa Media Player - Captcha"
},
"twofactor": {
"data": {
"securitycode": "Codice autenticazione a 2 fattori (2FA)"
},
"description": "**{email} - alexa.{url}**\nInserisci la password usa e getta (OTP).\n{message}",
"title": "Alexa Media Player - Autenticazione a Due Fattori"
},
"authselect": {
"data": {
"authselectoption": "Metodo password usa e getta (OTP)"
},
"description": "**{email} - alexa.{url}**\n{message}",
"title": "Alexa Media Player - Password Usa e Getta (One Time Password)"
},
"claimspicker": {
"data": {
"authselectoption": "Metodi di Verifica"
},
"description": "**{email} - alexa.{url}**\nPrego selezionare un metodo di verifica. (e.g., `sms` or `email`)\n{message}",
"title": "Alexa Media Player - Metodi di Verifica"
}

},
"title": "Alexa Media Player"
}
}
54 changes: 54 additions & 0 deletions custom_components/alexa_media/.translations/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"config": {
"error": {
"identifier_exists": "Dit e-mailadres is reeds geregistreerd",
"invalid_credentials": "Ongeldige inloggegevens"
},
"step": {
"user": {
"data": {
"password": "Paswoord",
"email": "E-mailadres",
"url": "Domeinnaam van Amazon regio (bv.amazon.co.uk)",
"include_devices": "Apparaten toevoegen (Scheiding: komma)",
"exclude_devices": "Apparaten uitsluiten (Scheiding: komma)",
"debug": "Geavanceerd debuggen",
"scan_interval": "Aantal seconden tussen scans"
},
"description": "Vul je gegevens in a.u.b.",
"title": "Alexa Media Player - Configuratie"
},
"captcha": {
"data": {
"password": "Paswoord",
"captcha": "Captcha"
},
"description": "**{email} - alexa.{url}**\n{message}\n {captcha_image}",
"title": "Alexa Media Player - Captcha"
},
"twofactor": {
"data": {
"securitycode": "Verificatiecode"
},
"description": "**{email} - alexa.{url}**\nGeef de verificatiecode in.\n{message}",
"title": "Alexa Media Player - Tweestapsverificatie"
},
"authselect": {
"data": {
"authselectoption": "Eenmalige Pincode"
},
"description": "**{email} - alexa.{url}**\n{message}",
"title": "Alexa Media Player - Eenmalige Pincode"
},
"claimspicker": {
"data": {
"authselectoption": "Verificatiemethode"
},
"description": "**{email} - alexa.{url}**\nSelecteer de verificatiemethode (bv.`sms` of `email`)\n{message}",
"title": "Alexa Media Player - Verificatiemethode"
}

},
"title": "Alexa Media Player"
}
}
54 changes: 54 additions & 0 deletions custom_components/alexa_media/.translations/pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"config": {
"error": {
"identifier_exists": "Adres email dla Alexy już jest zarejestrowany",
"invalid_credentials": "Nieprawidłowe dane logowania"
},
"step": {
"user": {
"data": {
"password": "Hasło",
"email": "Adres email",
"url": "Region/domena Amazon (np. amazon.co.uk)",
"include_devices": "Dodawane urządzenia (oddzielone przecinkami)",
"exclude_devices": "Wykluczone urządzenia (oddzielone przecinkami)",
"debug": "Zaawansowane debugowanie",
"scan_interval": "Interwał skanowania (sekundy)"
},
"description": "Wprowadź dane",
"title": "Alexa Media Player - konfiguracja"
},
"captcha": {
"data": {
"password": "Hasło",
"captcha": "Kod Captcha"
},
"description": "**{email} - alexa.{url}**\n{message}\n {captcha_image}",
"title": "Alexa Media Player - kod Captcha"
},
"twofactor": {
"data": {
"securitycode": "Kod uwierzytelniania dwuskładnikowego"
},
"description": "**{email} - alexa.{url}**\nWprowadź hasło jednorazowe (OTP).\n{message}",
"title": "Alexa Media Player - uwierzytelnianie dwuskładnikowe"
},
"authselect": {
"data": {
"authselectoption": "Metoda OTP"
},
"description": "**{email} - alexa.{url}**\n{message}",
"title": "Alexa Media Player - hasło jednorazowe"
},
"claimspicker": {
"data": {
"authselectoption": "Metoda weryfikacji"
},
"description": "**{email} - alexa.{url}**\nWybierz metodę weryfikacji. (np., `sms` lub `email`)\n{message}",
"title": "Alexa Media Player - metoda weryfikacji"
}

},
"title": "Alexa Media Player"
}
}
17 changes: 11 additions & 6 deletions custom_components/alexa_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import Optional, Text

import voluptuous as vol
from alexapy import WebsocketEchoClient
from homeassistant import util
from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.const import (CONF_EMAIL, CONF_NAME, CONF_PASSWORD,
Expand All @@ -22,14 +23,13 @@
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.service import verify_domain_control

from alexapy import WebsocketEchoClient

from .config_flow import configured_instances
from .const import (ALEXA_COMPONENTS, ATTR_EMAIL, CONF_ACCOUNTS, CONF_DEBUG,
CONF_EXCLUDE_DEVICES, CONF_INCLUDE_DEVICES,
DATA_ALEXAMEDIA, DOMAIN, MIN_TIME_BETWEEN_FORCED_SCANS,
MIN_TIME_BETWEEN_SCANS, SCAN_INTERVAL,
SERVICE_UPDATE_LAST_CALLED, STARTUP)
from .helpers import retry_async

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -143,7 +143,7 @@ async def async_setup(hass, config, discovery_info=None):
)
return True


@retry_async(limit=5, delay=5, catch_exceptions=True)
async def async_setup_entry(hass, config_entry):
"""Set up Alexa Media Player as config entry."""
async def close_alexa_media(event=None) -> None:
Expand All @@ -164,11 +164,14 @@ async def close_alexa_media(event=None) -> None:
email = account.get(CONF_EMAIL)
password = account.get(CONF_PASSWORD)
url = account.get(CONF_URL)
login = AlexaLogin(url, email, password, hass.config.path,
account.get(CONF_DEBUG))
if email not in hass.data[DATA_ALEXAMEDIA]['accounts']:
hass.data[DATA_ALEXAMEDIA]['accounts'][email] = {}
(hass.data[DATA_ALEXAMEDIA]['accounts'][email]['login_obj']) = login
if 'login_obj' in hass.data[DATA_ALEXAMEDIA]['accounts'][email]:
login = hass.data[DATA_ALEXAMEDIA]['accounts'][email]['login_obj']
else:
login = AlexaLogin(url, email, password, hass.config.path,
account.get(CONF_DEBUG))
(hass.data[DATA_ALEXAMEDIA]['accounts'][email]['login_obj']) = login
await login.login_with_cookie()
await test_login_status(hass, config_entry, login,
setup_platform_callback)
Expand Down Expand Up @@ -378,6 +381,7 @@ 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)
Expand Down Expand Up @@ -451,6 +455,7 @@ async def update_devices(login_obj):
_LOGGER.debug("DND %s found for %s",
device['dnd'],
hide_serial(device['serialNumber']))
device['auth_info'] = auth_info

(hass.data[DATA_ALEXAMEDIA]
['accounts']
Expand Down
6 changes: 4 additions & 2 deletions custom_components/alexa_media/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,17 @@ async def async_step_user(self, user_input=None):
if isinstance(user_input[CONF_INCLUDE_DEVICES], str):
self.config[CONF_INCLUDE_DEVICES] = (
user_input[CONF_INCLUDE_DEVICES].split(",")
if "CONF_INCLUDE_DEVICES" in user_input
if CONF_INCLUDE_DEVICES in user_input and
user_input[CONF_INCLUDE_DEVICES] != ""
else []
)
else:
self.config[CONF_INCLUDE_DEVICES] = user_input[CONF_INCLUDE_DEVICES]
if isinstance(user_input[CONF_EXCLUDE_DEVICES], str):
self.config[CONF_EXCLUDE_DEVICES] = (
user_input[CONF_EXCLUDE_DEVICES].split(",")
if "CONF_EXCLUDE_DEVICES" in user_input
if CONF_EXCLUDE_DEVICES in user_input and
user_input[CONF_EXCLUDE_DEVICES] != ""
else []
)
else:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/alexa_media/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

async def add_devices(account: Text,
devices: List[EntityComponent],
add_devices_callback: callable,
add_devices_callback: Callable,
include_filter: List[Text] = [],
exclude_filter: List[Text] = []) -> bool:
"""Add devices using add_devices_callback."""
Expand All @@ -36,7 +36,7 @@ async def add_devices(account: Text,
if devices:
_LOGGER.debug("%s: Adding %s", account, devices)
try:
add_devices_callback(devices, True)
add_devices_callback(devices, False)
return True
except HomeAssistantError as exception_:
message = exception_.message # type: str
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"documentation": "https://github.com/custom-components/alexa_media_player/wiki",
"dependencies": [],
"codeowners": ["@keatontaylor", "@alandtse"],
"requirements": ["alexapy==1.2.0"],
"requirements": ["alexapy==1.2.1"],
"homeassistant": "0.96.0"
}
25 changes: 14 additions & 11 deletions custom_components/alexa_media/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ def __init__(self, device, login):
self._last_update = 0

async def init(self, device):
from alexapy import AlexaAPI
self.auth = await AlexaAPI.get_authentication(self._login)
await self._set_authentication_details(self.auth)
await self.refresh(device)

async def async_added_to_hass(self):
Expand Down Expand Up @@ -308,14 +305,16 @@ async def refresh(self, device=None):
self._bluetooth_state = device['bluetooth_state']
self._locale = device['locale'] if 'locale' in device else 'en-US'
self._dnd = device['dnd'] if 'dnd' in device else None
if self._available is True:
await self._set_authentication_details(device['auth_info'])
session = None
if self._available:
_LOGGER.debug("%s: Refreshing %s", self.account, self.name)
self._source = await self._get_source()
self._source_list = await self._get_source_list()
if "PAIR_BT_SOURCE" in self._capabilities:
self._source = await self._get_source()
self._source_list = await self._get_source_list()
self._last_called = await self._get_last_called()
session = await self.alexa_api.get_state()
else:
session = None
if "MUSIC_SKILL" in self._capabilities:
session = await self.alexa_api.get_state()
await self._clear_media_details()
# update the session if it exists; not doing relogin here
if session is not None:
Expand Down Expand Up @@ -371,11 +370,15 @@ async def refresh(self, device=None):
if self._session['transport'] is not None:
self._shuffle = (self._session['transport']
['shuffle'] == "SELECTED"
if ('shuffle' in self._session['transport'])
if ('shuffle' in self._session['transport']
and self._session['transport']['shuffle']
!= 'DISABLED')
else None)
self._repeat = (self._session['transport']
['repeat'] == "SELECTED"
if ('repeat' in self._session['transport'])
if ('repeat' in self._session['transport']
and self._session['transport']['repeat']
!= 'DISABLED')
else None)

@property
Expand Down
29 changes: 28 additions & 1 deletion custom_components/alexa_media/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async def _set_switch(self, state, **kwargs):
@property
def is_on(self):
"""Return true if on."""
return getattr(self._client, self._switch_property)
return self.available and getattr(self._client, self._switch_property)

async def async_turn_on(self, **kwargs):
"""Turn on switch."""
Expand All @@ -203,6 +203,11 @@ async def async_turn_off(self, **kwargs):
"""Turn off switch."""
await self._set_switch(False, **kwargs)

@property
def available(self):
"""Return the availabilty of the switch."""
return getattr(self._client, self._switch_property) is not None

@property
def unique_id(self):
"""Return the unique ID."""
Expand Down Expand Up @@ -241,6 +246,15 @@ def device_info(self):
'via_device': (ALEXA_DOMAIN, self._client.unique_id),
}

@property
def icon(self):
"""Return the icon of the switch."""
return self._icon()

def _icon(self, on=None, off=None):
return on if self.is_on else off


class DNDSwitch(AlexaMediaSwitch):
"""Representation of a Alexa Media Do Not Disturb switch."""

Expand All @@ -254,6 +268,10 @@ def __init__(self, client, account):
account,
"do not disturb")

@property
def icon(self):
"""Return the icon of the switch."""
return super()._icon("mdi:do-not-disturb", "mdi:do-not-disturb-off")

class ShuffleSwitch(AlexaMediaSwitch):
"""Representation of a Alexa Media Shuffle switch."""
Expand All @@ -268,6 +286,10 @@ def __init__(self, client, account):
account,
"shuffle")

@property
def icon(self):
"""Return the icon of the switch."""
return super()._icon("mdi:shuffle", "mdi:shuffle-disabled")

class RepeatSwitch(AlexaMediaSwitch):
"""Representation of a Alexa Media Repeat switch."""
Expand All @@ -281,3 +303,8 @@ def __init__(self, client, account):
client.alexa_api.repeat,
account,
"repeat")

@property
def icon(self):
"""Return the icon of the switch."""
return super()._icon("mdi:repeat", "mdi:repeat-off")

0 comments on commit 84dcdde

Please sign in to comment.