Skip to content

Commit 4282211

Browse files
authored
Merge pull request #237 from keatontaylor/dev
Update to 1.3.1
2 parents c59d7c9 + b3852da commit 4282211

File tree

5 files changed

+69
-25
lines changed

5 files changed

+69
-25
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ Please see the [wiki.](https://github.com/keatontaylor/alexa_media_player/wiki/I
2323
We can basically do anything a Alexa [Routine](https://www.amazon.com/gp/help/customer/display.html?nodeId=G202200080) can do. You'll have to [discover specifics](https://github.com/keatontaylor/alexa_media_player/wiki/Sequence-Discovery), but here are some examples (and please help add them below!).
2424
To play music using the `media_player.play_media` service, you have to define the media_content_type appropriately. Search the [forum](https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639/2055) for other examples.
2525

26-
## Text-to-Speech
27-
For version 1.2.0 and above, can be provided via the [Notification Component](https://github.com/keatontaylor/alexa_media_player/wiki/Notification-Component) using `TTS` or `Announce`.
28-
29-
**The Media_Player UI will not work!**
26+
## Notification service (versions >= 1.2.0)
27+
Please see [Notification Component](https://github.com/keatontaylor/alexa_media_player/wiki/Notification-Component) for TTS, announcements, or mobile push.
28+
**Please note we do not support the the Media Player UI for TTS!**
3029

3130
## Online status of devices
3231
Additional attribute to tell you if the Alexa device is online (extremely useful if you want to send a TTS after one has come back online (such as one in a vehicle)
@@ -58,16 +57,18 @@ Supported sequences (may be region specific):
5857
Running Alexa automation routines is now supported. Routines are tasks you can trigger through the Alexa App.
5958
Please create them using the Alexa [app](https://www.amazon.com/gp/help/customer/display.html?nodeId=G202200080) and ensure they are **enabled**. This is now exposed through the media_player.play_media service when the `media_content_type` is set to `routine`
6059

61-
## Custom_updater (versions >= 1.1.0)
62-
We now support [custom_updater](https://github.com/custom-components/custom_updater).
60+
## HACS - Home Assistant Community Store (versions >= 1.3.0)
61+
We also support [HACS](https://custom-components.github.io/hacs/). **This cannot be used with custom_updater.**
62+
63+
In order to find Alexa Media Player, you first need to add the repository:
64+
1. Open HACS
65+
2. Go to Settings
66+
3. Enter `https://github.com/keatontaylor/alexa_media_player`in **ADD CUSTOM REPOSITORY**. Select type `integration`.
67+
68+
## Guard Mode (versions >= 1.3.0)
69+
Arm and disarm Alexa guard mode using an Alarm Control Panel. To arm, use `ARM_AWAY`. `ARM_HOME` is the same as `DISARM`. Please ensure you've enabled through the [Alexa app](https://www.amazon.com/b?ie=UTF8&node=18021383011).
6370

64-
Add this to your configuration:
65-
```yaml
66-
custom_updater:
67-
component_urls:
68-
# Released build
69-
- https://raw.githubusercontent.com/keatontaylor/alexa_media_player/master/custom_components.json
70-
```
71+
We do not support any Guard notifications at the moment.
7172

7273
## Notification service (versions >= 1.2.0)
7374
Please see [Notification Component](https://github.com/keatontaylor/alexa_media_player/wiki/Notification-Component).

custom_components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"alexa_media": {
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"local_location": "/custom_components/alexa_media/__init__.py",
55
"remote_location": "https://raw.githubusercontent.com/keatontaylor/alexa_media_player/master/custom_components/alexa_media/__init__.py",
66
"visit_repo": "https://github.com/keatontaylor/alexa_media_player",

custom_components/alexa_media/alarm_control_panel.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from homeassistant.components.alarm_control_panel import AlarmControlPanel
1515
from homeassistant.const import (STATE_ALARM_ARMED_AWAY,
1616
STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED)
17+
from homeassistant.exceptions import HomeAssistantError
1718

1819
from . import DATA_ALEXAMEDIA
1920
from . import DOMAIN as ALEXA_DOMAIN
@@ -33,14 +34,30 @@ def setup_platform(hass, config, add_devices_callback,
3334
alexa_client = AlexaAlarmControlPanel(account_dict['login_obj'],
3435
hass) \
3536
# type: AlexaAlarmControlPanel
37+
if not (alexa_client and alexa_client.unique_id):
38+
_LOGGER.debug("%s: Skipping creation of uninitialized device: %s",
39+
account,
40+
alexa_client)
41+
continue
3642
devices.append(alexa_client)
3743
(hass.data[DATA_ALEXAMEDIA]
3844
['accounts']
3945
[account]
4046
['entities']
4147
['alarm_control_panel']) = alexa_client
42-
_LOGGER.debug("Adding %s", devices)
43-
add_devices_callback(devices, True)
48+
if devices:
49+
_LOGGER.debug("Adding %s", devices)
50+
try:
51+
add_devices_callback(devices, True)
52+
except HomeAssistantError as exception_:
53+
message = exception_.message # type: str
54+
if message.startswith("Entity id already exists"):
55+
_LOGGER.debug("Device already added: %s",
56+
message)
57+
else:
58+
_LOGGER.debug("Unable to add devices: %s : %s",
59+
devices,
60+
message)
4461
return True
4562

4663

@@ -67,20 +84,27 @@ def __init__(self, login, hass):
6784
self._attrs = {}
6885

6986
data = self.alexa_api.get_guard_details(self._login)
70-
guard_dict = (data['locationDetails']
71-
['locationDetails']['Default_Location']
72-
['amazonBridgeDetails']['amazonBridgeDetails']
73-
['LambdaBridge_AAA/OnGuardSmartHomeBridgeService']
74-
['applianceDetails']['applianceDetails'])
87+
try:
88+
guard_dict = (data['locationDetails']
89+
['locationDetails']['Default_Location']
90+
['amazonBridgeDetails']['amazonBridgeDetails']
91+
['LambdaBridge_AAA/OnGuardSmartHomeBridgeService']
92+
['applianceDetails']['applianceDetails'])
93+
except KeyError:
94+
guard_dict = {}
7595
for key, value in guard_dict.items():
7696
if value['modelName'] == "REDROCK_GUARD_PANEL":
7797
self._appliance_id = value['applianceId']
7898
self._guard_entity_id = value['entityId']
7999
self._friendly_name += " " + self._appliance_id[-5:]
80-
_LOGGER.debug("Discovered Alexa Guard %s: %s %s",
100+
_LOGGER.debug("%s: Discovered %s: %s %s",
101+
self.account,
81102
self._friendly_name,
82103
self._appliance_id,
83104
self._guard_entity_id)
105+
if not self._appliance_id:
106+
_LOGGER.debug("%s: No Alexa Guard entity found", self.account)
107+
return None
84108
# Register event handler on bus
85109
hass.bus.listen(('{}_{}'.format(ALEXA_DOMAIN,
86110
hide_email(login.email)))[0:32],
@@ -103,7 +127,8 @@ def refresh(self):
103127
state_json = self.alexa_api.get_guard_state(self._login,
104128
self._appliance_id)
105129
# _LOGGER.debug("%s: state_json %s", self.account, state_json)
106-
if state_json['deviceStates']:
130+
if (state_json and 'deviceStates' in state_json
131+
and state_json['deviceStates']):
107132
cap = state_json['deviceStates'][0]['capabilityStates']
108133
# _LOGGER.debug("%s: cap %s", self.account, cap)
109134
for item_json in cap:
@@ -116,7 +141,8 @@ def refresh(self):
116141
_LOGGER.debug("%s: Error refreshing alarm_control_panel %s: %s",
117142
self.account,
118143
self.name,
119-
json.dumps(state_json['errors']))
144+
json.dumps(state_json['errors']) if state_json
145+
else None)
120146
if state is None:
121147
return
122148
if state == "ARMED_AWAY":

custom_components/alexa_media/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010
from datetime import timedelta
1111

12-
__version__ = '1.3.0'
12+
__version__ = '1.3.1'
1313
PROJECT_URL = "https://github.com/keatontaylor/alexa_media_player/"
1414
ISSUE_URL = "{}issues".format(PROJECT_URL)
1515

info.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[Alexa Media Player Custom Component](https://github.com/keatontaylor/alexa_media_player) for homeassistant
2+
3+
This is a custom component to allow control of Amazon Alexa devices in [Homeassistant](https://home-assistant.io) using the unofficial Alexa API. Please note this mimics the Alexa app but Amazon may cut off access at anytime.
4+
5+
## Highlights of what alexa_media can do
6+
7+
- Control Alexa devices as media players through HA
8+
- Send notifications including text-to-speak, mobile pushes, and announcements
9+
- Turn on or off Alexa Guard (region support required)
10+
11+
## Useful links
12+
13+
- [General documentation](https://github.com/keatontaylor/alexa_media_player/wiki)
14+
- [Installation and Configuration](https://github.com/keatontaylor/alexa_media_player/wiki/Installation-and-Configuration)
15+
- [FAQ](https://github.com/keatontaylor/alexa_media_player/wiki/FAQ)
16+
- [Repository](https://github.com/keatontaylor/alexa_media_player)
17+
- [Forum post](https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639)

0 commit comments

Comments
 (0)