Skip to content

Commit

Permalink
Merge pull request #499 from custom-components/dev
Browse files Browse the repository at this point in the history
2.4.1
  • Loading branch information
alandtse authored Jan 2, 2020
2 parents e3142c8 + f13f502 commit 7649b1a
Show file tree
Hide file tree
Showing 11 changed files with 1,619 additions and 1,344 deletions.
1,126 changes: 615 additions & 511 deletions custom_components/alexa_media/__init__.py

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions custom_components/alexa_media/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
from homeassistant.const import STATE_ALARM_ARMED_AWAY, STATE_ALARM_DISARMED
from homeassistant.helpers.event import async_call_later

from . import CONF_EMAIL, CONF_EXCLUDE_DEVICES, CONF_INCLUDE_DEVICES, DATA_ALEXAMEDIA
from . import DOMAIN as ALEXA_DOMAIN
from . import MIN_TIME_BETWEEN_FORCED_SCANS, MIN_TIME_BETWEEN_SCANS, hide_email
from . import (
CONF_EMAIL,
CONF_EXCLUDE_DEVICES,
CONF_INCLUDE_DEVICES,
DATA_ALEXAMEDIA,
DOMAIN as ALEXA_DOMAIN,
MIN_TIME_BETWEEN_FORCED_SCANS,
MIN_TIME_BETWEEN_SCANS,
hide_email,
)
from .helpers import _catch_login_errors, add_devices, retry_async

_LOGGER = logging.getLogger(__name__)
Expand Down
52 changes: 29 additions & 23 deletions custom_components/alexa_media/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,31 @@
For more details about this platform, please refer to the documentation at
https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639
"""
import logging
from collections import OrderedDict
import logging
from typing import Text

import voluptuous as vol
from alexapy import AlexapyConnectionError
from homeassistant import config_entries
from homeassistant.const import (CONF_EMAIL, CONF_NAME, CONF_PASSWORD,
CONF_SCAN_INTERVAL, CONF_URL,
EVENT_HOMEASSISTANT_STOP)
from homeassistant.const import (
CONF_EMAIL,
CONF_NAME,
CONF_PASSWORD,
CONF_SCAN_INTERVAL,
CONF_URL,
EVENT_HOMEASSISTANT_STOP,
)
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv
import voluptuous as vol

from .const import (CONF_DEBUG, CONF_EXCLUDE_DEVICES, CONF_INCLUDE_DEVICES,
DATA_ALEXAMEDIA, DOMAIN)
from .const import (
CONF_DEBUG,
CONF_EXCLUDE_DEVICES,
CONF_INCLUDE_DEVICES,
DATA_ALEXAMEDIA,
DOMAIN,
)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -164,17 +174,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 and
user_input[CONF_INCLUDE_DEVICES] != ""
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 and
user_input[CONF_EXCLUDE_DEVICES] != ""
if CONF_EXCLUDE_DEVICES in user_input
and user_input[CONF_EXCLUDE_DEVICES] != ""
else []
)
else:
Expand Down Expand Up @@ -230,8 +240,7 @@ async def async_step_process(self, user_input=None):
try:
await self.login.login(data=user_input)
except AlexapyConnectionError:
return await self._show_form(
errors={"base": "connection_error"})
return await self._show_form(errors={"base": "connection_error"})
except BaseException as ex:
_LOGGER.warning("Unknown error: %s", ex)
return await self._show_form(errors={"base": "unknown_error"})
Expand Down Expand Up @@ -276,8 +285,7 @@ async def _test_login(self):
):
_LOGGER.debug("Creating config_flow to request 2FA")
message = "> {0}".format(
login.status["error_message"]
if "error_message" in login.status else ""
login.status["error_message"] if "error_message" in login.status else ""
)
return await self._show_form(
"twofactor",
Expand All @@ -294,8 +302,7 @@ async def _test_login(self):
and login.status["claimspicker_required"]
):
error_message = "> {0}".format(
login.status["error_message"]
if "error_message" in login.status else ""
login.status["error_message"] if "error_message" in login.status else ""
)
_LOGGER.debug("Creating config_flow to select verification method")
claimspicker_message = login.status["claimspicker_message"]
Expand All @@ -306,8 +313,9 @@ async def _test_login(self):
placeholders={
"email": login.email,
"url": login.url,
"message": "> {0}\n> {1}".format(claimspicker_message,
error_message),
"message": "> {0}\n> {1}".format(
claimspicker_message, error_message
),
},
)
elif (
Expand All @@ -316,8 +324,7 @@ async def _test_login(self):
):
_LOGGER.debug("Creating config_flow to select OTA method")
error_message = (
login.status["error_message"]
if "error_message" in login.status else ""
login.status["error_message"] if "error_message" in login.status else ""
)
authselect_message = login.status["authselect_message"]
return await self._show_form(
Expand All @@ -326,8 +333,7 @@ async def _test_login(self):
placeholders={
"email": login.email,
"url": login.url,
"message": "> {0}\n> {1}".format(authselect_message,
error_message),
"message": "> {0}\n> {1}".format(authselect_message, error_message),
},
)
elif (
Expand Down
34 changes: 15 additions & 19 deletions custom_components/alexa_media/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,26 @@
PROJECT_URL = "https://github.com/custom-components/alexa_media_player/"
ISSUE_URL = "{}issues".format(PROJECT_URL)

DOMAIN = 'alexa_media'
DATA_ALEXAMEDIA = 'alexa_media'
DOMAIN = "alexa_media"
DATA_ALEXAMEDIA = "alexa_media"

PLAY_SCAN_INTERVAL = 20
SCAN_INTERVAL = timedelta(seconds=60)
MIN_TIME_BETWEEN_SCANS = SCAN_INTERVAL
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)

ALEXA_COMPONENTS = [
'media_player',
'notify',
'alarm_control_panel',
'switch',
'sensor'
]
ALEXA_COMPONENTS = ["media_player", "notify", "alarm_control_panel", "switch", "sensor"]

CONF_ACCOUNTS = 'accounts'
CONF_DEBUG = 'debug'
CONF_INCLUDE_DEVICES = 'include_devices'
CONF_EXCLUDE_DEVICES = 'exclude_devices'
CONF_ACCOUNTS = "accounts"
CONF_DEBUG = "debug"
CONF_INCLUDE_DEVICES = "include_devices"
CONF_EXCLUDE_DEVICES = "exclude_devices"

SERVICE_CLEAR_HISTORY = 'clear_history'
SERVICE_UPDATE_LAST_CALLED = 'update_last_called'
ATTR_MESSAGE = 'message'
ATTR_EMAIL = 'email'
ATTR_NUM_ENTRIES = 'entries'
SERVICE_CLEAR_HISTORY = "clear_history"
SERVICE_UPDATE_LAST_CALLED = "update_last_called"
ATTR_MESSAGE = "message"
ATTR_EMAIL = "email"
ATTR_NUM_ENTRIES = "entries"
STARTUP = """
-------------------------------------------------------------------
{}
Expand All @@ -47,4 +41,6 @@
If you have any issues with this you need to open an issue here:
{}
-------------------------------------------------------------------
""".format(DOMAIN, __version__, ISSUE_URL)
""".format(
DOMAIN, __version__, ISSUE_URL
)
Loading

0 comments on commit 7649b1a

Please sign in to comment.