From 0157ebeeef3c36dd23cc14b02347e00fe4ab2106 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Sun, 9 Feb 2020 10:55:44 -0800 Subject: [PATCH 1/7] fix: load found devices when load delay required fixes #552 --- custom_components/alexa_media/sensor.py | 8 ++++++++ custom_components/alexa_media/switch.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/custom_components/alexa_media/sensor.py b/custom_components/alexa_media/sensor.py index 491dae6e..f9c525e5 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"] From 1dc1e773bf407201eb523137501545f1fb532429 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Mon, 17 Feb 2020 21:41:04 -0800 Subject: [PATCH 2/7] fix: allow passing of kwargs for async_send_tts --- custom_components/alexa_media/media_player.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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): From a55d3099d2c4606992e41b2ee546994d561a1c5b Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Mon, 17 Feb 2020 21:42:12 -0800 Subject: [PATCH 3/7] perf: change convert to sync --- custom_components/alexa_media/notify.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/custom_components/alexa_media/notify.py b/custom_components/alexa_media/notify.py index d802f9e6..e098afeb 100644 --- a/custom_components/alexa_media/notify.py +++ b/custom_components/alexa_media/notify.py @@ -65,7 +65,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 +149,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) 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)), @@ -191,9 +188,7 @@ async def async_send_message(self, message="", **kwargs): ) 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) From 9218756f6e0c553cdb11ce4cbfd27addeef02005 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Mon, 17 Feb 2020 21:42:50 -0800 Subject: [PATCH 4/7] perf: use asyncio.gather instead of for loop --- custom_components/alexa_media/notify.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/custom_components/alexa_media/notify.py b/custom_components/alexa_media/notify.py index e098afeb..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 ( @@ -160,7 +161,7 @@ async def async_send_message(self, message="", **kwargs): _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 = self.convert(entities, type_="serialnumbers", filter_matches=True) _LOGGER.debug( @@ -180,15 +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 = 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) From 48cfc2c947cbea25f7534b1e3a80c79f12be77f9 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Mon, 17 Feb 2020 22:59:27 -0800 Subject: [PATCH 5/7] fix: ignore PUSH_CONTENT_FOCUS_CHANGE closes #536 --- custom_components/alexa_media/__init__.py | 1 + 1 file changed, 1 insertion(+) 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: From d7155bba404577c4cbfa210e32412059f1850193 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Mon, 17 Feb 2020 23:18:44 -0800 Subject: [PATCH 6/7] fix: bump alexapy to 1.5.0 --- custom_components/alexa_media/manifest.json | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 From f6768283bfc6ce3243b88e9a584ec350b4e87a1b Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Mon, 17 Feb 2020 23:21:51 -0800 Subject: [PATCH 7/7] docs: simplify readme --- README.md | 54 ------------------------------------------------------ 1 file changed, 54 deletions(-) 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)