Skip to content

Commit

Permalink
perf: change convert to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Feb 18, 2020
1 parent 1dc1e77 commit a55d309
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions custom_components/alexa_media/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)),
Expand All @@ -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)

0 comments on commit a55d309

Please sign in to comment.