Skip to content

Commit

Permalink
feat: add dropin notification support
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jul 15, 2020
1 parent f6fb04e commit 103be00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions custom_components/alexa_media/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,13 @@ async def async_send_mobilepush(self, message, **kwargs):
message, customer_id=self._customer_id, **kwargs
)

@_catch_login_errors
async def async_send_dropin_notification(self, message, **kwargs):
"""Send notification dropin to the media player's associated mobile devices."""
await self.alexa_api.send_dropin_notification(
message, customer_id=self._customer_id, **kwargs
)

@_catch_login_errors
async def async_play_media(self, media_type, media_id, enqueue=None, **kwargs):
# pylint: disable=unused-argument
Expand Down
19 changes: 18 additions & 1 deletion custom_components/alexa_media/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ async def async_send_message(self, message="", **kwargs):
entities, type_="entities", filter_matches=True
)
if alexa in targets and alexa.available:
_LOGGER.debug("Push by %s : %s %s", alexa, title, message)
_LOGGER.debug("Push by %s: %s %s", alexa, title, message)
tasks.append(
alexa.async_send_mobilepush(
message,
Expand All @@ -245,4 +245,21 @@ async def async_send_message(self, message="", **kwargs):
]["options"].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
)
)
elif data["type"] == "dropin_notification":
targets = self.convert(
entities, type_="entities", filter_matches=True
)
if alexa in targets and alexa.available:
_LOGGER.debug(
"Notification dropin by %s: %s %s", alexa, title, message
)
tasks.append(
alexa.async_send_dropin_notification(
message,
title=title,
queue_delay=self.hass.data[DATA_ALEXAMEDIA]["accounts"][
account
]["options"].get(CONF_QUEUE_DELAY, DEFAULT_QUEUE_DELAY),
)
)
await asyncio.gather(*tasks)

0 comments on commit 103be00

Please sign in to comment.