Skip to content

Commit

Permalink
Merge pull request #564 from alandtse/#551
Browse files Browse the repository at this point in the history
fix: allow tts requests to be sent in parallel
  • Loading branch information
alandtse authored Feb 18, 2020
2 parents 3f585d2 + f676828 commit 135b04f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 77 deletions.
54 changes: 0 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,6 @@ Allows for control of Amazon Echo products as home assistant media devices with
# Installation and Configuration
Please see the [wiki.](https://github.com/custom-components/alexa_media_player/wiki/Installation-and-Configuration)

# Notable Additional Features
## Play Music
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/custom-components/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.

## Notification service (versions >= 1.2.0)
Please see [Notification Component](https://github.com/custom-components/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)

## Last called device (versions >= 0.10.0)
Each device will report whether it is the `last_called` or not. This allows us to identify the device that was called according to the Alexa Activities API.

## Sequence commands (versions >= 1.0.0)
Alexa accepts certain pre-defined sequences and this is what provides TTS and play_media. This is now exposed through the `media_player.play_media service` when the `media_content_type` is set to `sequence`

Supported sequences (may be region specific):
* Alexa.Weather.Play
* Alexa.Traffic.Play
* Alexa.FlashBriefing.Play
* Alexa.GoodMorning.Play
* Alexa.GoodNight.Play
* Alexa.SingASong.Play
* Alexa.TellStory.Play
* Alexa.FunFact.Play
* Alexa.Joke.Play
* Alexa.Music.PlaySearchPhrase
* Alexa.Calendar.PlayTomorrow
* Alexa.Calendar.PlayToday
* Alexa.Calendar.PlayNext
* Alexa.CleanUp.Play
* Alexa.ImHome.Play

## Automation routines (versions >= 1.0.0)
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`

## 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/custom-components/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).

We do not support any Guard notifications at the moment.

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

# Further Documentation
Please see the [wiki](https://github.com/custom-components/alexa_media_player/wiki)
Expand Down
11 changes: 8 additions & 3 deletions custom_components/alexa_media/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"config_flow": true,
"documentation": "https://github.com/custom-components/alexa_media_player/wiki",
"dependencies": [],
"codeowners": ["@keatontaylor", "@alandtse"],
"requirements": ["alexapy==1.4.2"],
"codeowners": [
"keatontaylor",
"alandtse"
],
"requirements": [
"alexapy==1.5.0"
],
"homeassistant": "0.96.0"
}
}
4 changes: 2 additions & 2 deletions custom_components/alexa_media/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,12 +997,12 @@ async def async_media_previous_track(self):
await self.async_update()

@_catch_login_errors
async def async_send_tts(self, message):
async def async_send_tts(self, message, **kwargs):
"""Send TTS to Device.
NOTE: Does not work on WHA Groups.
"""
await self.alexa_api.send_tts(message, customer_id=self._customer_id)
await self.alexa_api.send_tts(message, customer_id=self._customer_id, **kwargs)

@_catch_login_errors
async def async_send_announcement(self, message, **kwargs):
Expand Down
35 changes: 17 additions & 18 deletions custom_components/alexa_media/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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 asyncio
import logging

from homeassistant.components.notify import (
Expand Down Expand Up @@ -65,7 +66,7 @@ def __init__(self, hass):
"""Initialize the service."""
self.hass = hass

async def convert(self, names, type_="entities", filter_matches=False):
def convert(self, names, type_="entities", filter_matches=False):
"""Return a list of converted Alexa devices based on names.
Names may be matched either by serialNumber, accountName, or
Expand Down Expand Up @@ -149,23 +150,20 @@ async def async_send_message(self, message="", **kwargs):
data = kwargs.get(ATTR_DATA)
if isinstance(targets, str):
targets = [targets]
entities = await self.convert(targets, type_="entities")
entities = self.convert(targets, type_="entities")
try:
entities.extend(self.hass.components.group.expand_entity_ids(entities))
except ValueError:
_LOGGER.debug("Invalid Home Assistant entity in %s", entities)
tasks = []
if data["type"] == "tts":
targets = await self.convert(
entities, type_="entities", filter_matches=True
)
targets = self.convert(entities, type_="entities", filter_matches=True)
_LOGGER.debug("TTS entities: %s", targets)
for alexa in targets:
_LOGGER.debug("TTS by %s : %s", alexa, message)
await alexa.async_send_tts(message)
tasks.append(alexa.async_send_tts(message))
elif data["type"] == "announce":
targets = await self.convert(
entities, type_="serialnumbers", filter_matches=True
)
targets = self.convert(entities, type_="serialnumbers", filter_matches=True)
_LOGGER.debug(
"Announce targets: %s entities: %s",
list(map(hide_serial, targets)),
Expand All @@ -183,17 +181,18 @@ async def async_send_message(self, message="", **kwargs):
list(map(hide_serial, targets)),
message,
)
await alexa.async_send_announcement(
message,
targets=targets,
title=title,
method=(data["method"] if "method" in data else "all"),
tasks.append(
alexa.async_send_announcement(
message,
targets=targets,
title=title,
method=(data["method"] if "method" in data else "all"),
)
)
break
elif data["type"] == "push":
targets = await self.convert(
entities, type_="entities", filter_matches=True
)
targets = self.convert(entities, type_="entities", filter_matches=True)
for alexa in targets:
_LOGGER.debug("Push by %s : %s %s", alexa, title, message)
await alexa.async_send_mobilepush(message, title=title)
tasks.append(alexa.async_send_mobilepush(message, title=title))
await asyncio.gather(*tasks)

0 comments on commit 135b04f

Please sign in to comment.