diff --git a/README.md b/README.md index 9472a80c..b28d3268 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/custom_components/alexa_media/__init__.py b/custom_components/alexa_media/__init__.py index 3224544f..196c16b2 100644 --- a/custom_components/alexa_media/__init__.py +++ b/custom_components/alexa_media/__init__.py @@ -892,6 +892,7 @@ async def ws_handler(message_obj): elif command in [ "PUSH_DELETE_DOPPLER_ACTIVITIES", # delete Alexa history "PUSH_LIST_ITEM_CHANGE", # update shopping list + "PUSH_CONTENT_FOCUS_CHANGE", # likely prime related refocus ]: pass else: diff --git a/custom_components/alexa_media/manifest.json b/custom_components/alexa_media/manifest.json index 4ed3b3f8..955dac3b 100644 --- a/custom_components/alexa_media/manifest.json +++ b/custom_components/alexa_media/manifest.json @@ -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" -} +} \ No newline at end of file diff --git a/custom_components/alexa_media/media_player.py b/custom_components/alexa_media/media_player.py index 66530937..357d2163 100644 --- a/custom_components/alexa_media/media_player.py +++ b/custom_components/alexa_media/media_player.py @@ -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): diff --git a/custom_components/alexa_media/notify.py b/custom_components/alexa_media/notify.py index d802f9e6..6925ffd4 100644 --- a/custom_components/alexa_media/notify.py +++ b/custom_components/alexa_media/notify.py @@ -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 ( @@ -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 @@ -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)), @@ -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) diff --git a/custom_components/alexa_media/sensor.py b/custom_components/alexa_media/sensor.py index 00536ff2..c38ccd8a 100644 --- a/custom_components/alexa_media/sensor.py +++ b/custom_components/alexa_media/sensor.py @@ -69,6 +69,14 @@ async def async_setup_platform(hass, config, add_devices_callback, discovery_inf hide_email(account), hide_serial(key), ) + if devices: + await add_devices( + hide_email(account), + devices, + add_devices_callback, + include_filter, + exclude_filter, + ) return False if key not in (account_dict["entities"]["sensor"]): (account_dict["entities"]["sensor"][key]) = {} diff --git a/custom_components/alexa_media/switch.py b/custom_components/alexa_media/switch.py index c749a483..37b3023a 100644 --- a/custom_components/alexa_media/switch.py +++ b/custom_components/alexa_media/switch.py @@ -50,6 +50,14 @@ async def async_setup_platform(hass, config, add_devices_callback, discovery_inf hide_email(account), hide_serial(key), ) + if devices: + await add_devices( + hide_email(account), + devices, + add_devices_callback, + include_filter, + exclude_filter, + ) return False if key not in ( hass.data[DATA_ALEXAMEDIA]["accounts"][account]["entities"]["switch"]