Skip to content

Commit

Permalink
Merge pull request #47 from jumping2000/beta
Browse files Browse the repository at this point in the history
Added some fixes in Alexa Manager
  • Loading branch information
jumping2000 authored May 10, 2023
2 parents 9735cb9 + ce0f6c7 commit 6227cf2
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions apps/notifier/alexa_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,19 @@ def check_media_player(self, media_player: list) -> list:
if "group." in mp:
mplist.extend(self.get_state(mp, attribute="entity_id", default=""))
elif "sensor." in mp:
mplist.append(self.get_state(mp))
state_string = self.get_state(mp)
state_list = self.str2list(str(state_string.lower()))
mplist.extend(state_list)
elif "media_player." in mp:
mplist.append(mp)
else:
self.log(f"Invalid entity ({mp})", level="WARNING")
if not mplist:
mplist = self.service2player
self.log(f"Not {media_player} found. Default {mplist}", level="WARNING")
self.lg(f"GET PLAYER: {mplist}")
return mplist
unique_players = list(set(mplist))
self.lg(f"GET PLAYER: {unique_players}")
return unique_players

def entity_from_name(self, name_list: list) -> dict:
"""Given a list of names, it takes the entity_id from the friendly_name.
Expand Down Expand Up @@ -595,6 +598,7 @@ def volume_auto_silent(self, media_player: list, defvol: float) -> None:
self.call_service(
"media_player/volume_set", entity_id=i, volume_level=defvol
)
# Force attribute volume level in Home assistant
self.set_state(i, attributes={"volume_level": defvol})
self.call_service("alexa_media/update_last_called", return_result=True)

Expand Down Expand Up @@ -634,8 +638,8 @@ def volume_set(self, media_player: list, volume: float) -> None:
)
# Not strictly necessary
for player in media_player:
# Force attribute volume level in Home assistant
self.set_state(player, attributes={"volume_level": volume})
self.lg(f"SET VOLUMES: {player} {volume}")

def set_debug_sensor(self, state: str, error: str) -> None:
"""Set, based on the error, the debug sensor of the app notifier."""
Expand All @@ -654,7 +658,7 @@ def worker(self):
data = self.queue.get()
self.lg(f"------ ALEXA WORKER QUEUE ------")
self.lg(f"WORKER: {type(data)} value {data}")
self.set_state(self.binary_speak, state="on", attributes = data)
self.set_state(self.binary_speak, state="on", attributes=data)
media_player = data[MEDIA_PLAYER]
if data[AUTO_VOLUMES]:
self.volume_auto_silent(media_player, data[DEFAULT_VOL])
Expand Down Expand Up @@ -726,16 +730,17 @@ def worker(self):
message=msg.strip(),
)

# Actionable Notificstion >>>
# Actionable Notification >>>
if data[EVENT_ID]:
last_player = media_player[-1]
self.call_service(
"media_player/play_media",
entity_id=media_player,
entity_id=last_player,
media_content_id=data[SKILL_ID],
media_content_type="skill",
)
duration += 10
self.lg(f"ADDED EXTRA TIME: +10: {duration}")
self.lg(f"ADDED EXTRA ANSWER TIME {duration} Last {last_player}")

time.sleep(duration)
self.volume_restore()
Expand Down

0 comments on commit 6227cf2

Please sign in to comment.