Skip to content

Commit

Permalink
feat(media_player): expose last_called time stamp
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jan 15, 2020
1 parent 64d214d commit 99cd21a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions custom_components/alexa_media/media_player.py
Expand Up @@ -157,6 +157,7 @@ def __init__(self, device, login):
self._playing_parent = None
# Last Device
self._last_called = None
self._last_called_timestamp = None
# Do not Disturb state
self._dnd = None
# Polling state
Expand Down Expand Up @@ -267,6 +268,9 @@ async def _refresh_if_no_audiopush(already_refreshed=False):
hide_serial(self.device_serial_number),
)
self._last_called = True
self._last_called_timestamp = event.data["last_called_change"][
"timestamp"
]
else:
self._last_called = False
if self.hass and self.async_schedule_update_ha_state:
Expand Down Expand Up @@ -432,6 +436,10 @@ async def refresh(self, device=None):
self._source = await self._get_source()
self._source_list = await self._get_source_list()
self._last_called = await self._get_last_called()
if self._last_called:
self._last_called_timestamp = self.hass.data[DATA_ALEXAMEDIA][
"accounts"
][self._login.email]["last_called"]["timestamp"]
if "MUSIC_SKILL" in self._capabilities:
parent_session = {}
if playing_parents:
Expand Down Expand Up @@ -1019,8 +1027,12 @@ async def async_play_media(self, media_type, media_id, enqueue=None, **kwargs):

@property
def device_state_attributes(self):
"""Return the scene state attributes."""
attr = {"available": self._available, "last_called": self._last_called}
"""Return the state attributes."""
attr = {
"available": self.available,
"last_called": self._last_called,
"last_called_timestamp": self._last_called_timestamp,
}
return attr

@property
Expand Down

0 comments on commit 99cd21a

Please sign in to comment.