Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 1.3.1 #237

Merged
merged 12 commits into from
Jun 30, 2019
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ Please see the [wiki.](https://github.com/keatontaylor/alexa_media_player/wiki/I
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!).
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.

## Text-to-Speech
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`.

**The Media_Player UI will not work!**
## Notification service (versions >= 1.2.0)
Please see [Notification Component](https://github.com/keatontaylor/alexa_media_player/wiki/Notification-Component) for TTS, announcements, or mobile push.
**Please note we do not support the the Media Player UI for TTS!**

## Online status of devices
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)
Expand Down Expand Up @@ -58,16 +57,18 @@ Supported sequences (may be region specific):
Running Alexa automation routines is now supported. Routines are tasks you can trigger through the Alexa App.
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`

## Custom_updater (versions >= 1.1.0)
We now support [custom_updater](https://github.com/custom-components/custom_updater).
## HACS - Home Assistant Community Store (versions >= 1.3.0)
We also support [HACS](https://custom-components.github.io/hacs/). **This cannot be used with custom_updater.**

In order to find Alexa Media Player, you first need to add the repository:
1. Open HACS
2. Go to Settings
3. Enter `https://github.com/keatontaylor/alexa_media_player`in **ADD CUSTOM REPOSITORY**. Select type `integration`.

## Guard Mode (versions >= 1.3.0)
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).

Add this to your configuration:
```yaml
custom_updater:
component_urls:
# Released build
- https://raw.githubusercontent.com/keatontaylor/alexa_media_player/master/custom_components.json
```
We do not support any Guard notifications at the moment.

## Notification service (versions >= 1.2.0)
Please see [Notification Component](https://github.com/keatontaylor/alexa_media_player/wiki/Notification-Component).
Expand Down
2 changes: 1 addition & 1 deletion custom_components.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"alexa_media": {
"version": "1.3.0",
"version": "1.3.1",
"local_location": "/custom_components/alexa_media/__init__.py",
"remote_location": "https://raw.githubusercontent.com/keatontaylor/alexa_media_player/master/custom_components/alexa_media/__init__.py",
"visit_repo": "https://github.com/keatontaylor/alexa_media_player",
Expand Down
46 changes: 36 additions & 10 deletions custom_components/alexa_media/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from homeassistant.components.alarm_control_panel import AlarmControlPanel
from homeassistant.const import (STATE_ALARM_ARMED_AWAY,
STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED)
from homeassistant.exceptions import HomeAssistantError

from . import DATA_ALEXAMEDIA
from . import DOMAIN as ALEXA_DOMAIN
Expand All @@ -33,14 +34,30 @@ def setup_platform(hass, config, add_devices_callback,
alexa_client = AlexaAlarmControlPanel(account_dict['login_obj'],
hass) \
# type: AlexaAlarmControlPanel
if not (alexa_client and alexa_client.unique_id):
_LOGGER.debug("%s: Skipping creation of uninitialized device: %s",
account,
alexa_client)
continue
devices.append(alexa_client)
(hass.data[DATA_ALEXAMEDIA]
['accounts']
[account]
['entities']
['alarm_control_panel']) = alexa_client
_LOGGER.debug("Adding %s", devices)
add_devices_callback(devices, True)
if devices:
_LOGGER.debug("Adding %s", devices)
try:
add_devices_callback(devices, True)
except HomeAssistantError as exception_:
message = exception_.message # type: str
if message.startswith("Entity id already exists"):
_LOGGER.debug("Device already added: %s",
message)
else:
_LOGGER.debug("Unable to add devices: %s : %s",
devices,
message)
return True


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

data = self.alexa_api.get_guard_details(self._login)
guard_dict = (data['locationDetails']
['locationDetails']['Default_Location']
['amazonBridgeDetails']['amazonBridgeDetails']
['LambdaBridge_AAA/OnGuardSmartHomeBridgeService']
['applianceDetails']['applianceDetails'])
try:
guard_dict = (data['locationDetails']
['locationDetails']['Default_Location']
['amazonBridgeDetails']['amazonBridgeDetails']
['LambdaBridge_AAA/OnGuardSmartHomeBridgeService']
['applianceDetails']['applianceDetails'])
except KeyError:
guard_dict = {}
for key, value in guard_dict.items():
if value['modelName'] == "REDROCK_GUARD_PANEL":
self._appliance_id = value['applianceId']
self._guard_entity_id = value['entityId']
self._friendly_name += " " + self._appliance_id[-5:]
_LOGGER.debug("Discovered Alexa Guard %s: %s %s",
_LOGGER.debug("%s: Discovered %s: %s %s",
self.account,
self._friendly_name,
self._appliance_id,
self._guard_entity_id)
if not self._appliance_id:
_LOGGER.debug("%s: No Alexa Guard entity found", self.account)
return None
# Register event handler on bus
hass.bus.listen(('{}_{}'.format(ALEXA_DOMAIN,
hide_email(login.email)))[0:32],
Expand All @@ -103,7 +127,8 @@ def refresh(self):
state_json = self.alexa_api.get_guard_state(self._login,
self._appliance_id)
# _LOGGER.debug("%s: state_json %s", self.account, state_json)
if state_json['deviceStates']:
if (state_json and 'deviceStates' in state_json
and state_json['deviceStates']):
cap = state_json['deviceStates'][0]['capabilityStates']
# _LOGGER.debug("%s: cap %s", self.account, cap)
for item_json in cap:
Expand All @@ -116,7 +141,8 @@ def refresh(self):
_LOGGER.debug("%s: Error refreshing alarm_control_panel %s: %s",
self.account,
self.name,
json.dumps(state_json['errors']))
json.dumps(state_json['errors']) if state_json
else None)
if state is None:
return
if state == "ARMED_AWAY":
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""
from datetime import timedelta

__version__ = '1.3.0'
__version__ = '1.3.1'
PROJECT_URL = "https://github.com/keatontaylor/alexa_media_player/"
ISSUE_URL = "{}issues".format(PROJECT_URL)

Expand Down
17 changes: 17 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Alexa Media Player Custom Component](https://github.com/keatontaylor/alexa_media_player) for homeassistant

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.

## Highlights of what alexa_media can do

- Control Alexa devices as media players through HA
- Send notifications including text-to-speak, mobile pushes, and announcements
- Turn on or off Alexa Guard (region support required)

## Useful links

- [General documentation](https://github.com/keatontaylor/alexa_media_player/wiki)
- [Installation and Configuration](https://github.com/keatontaylor/alexa_media_player/wiki/Installation-and-Configuration)
- [FAQ](https://github.com/keatontaylor/alexa_media_player/wiki/FAQ)
- [Repository](https://github.com/keatontaylor/alexa_media_player)
- [Forum post](https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639)