Skip to content

Commit

Permalink
Add current_app_media_session_state() method (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Jan 14, 2022
1 parent 35b882f commit 957f5b3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
19 changes: 16 additions & 3 deletions androidtv/basetv/basetv_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ async def current_app(self):

return self._current_app(current_app_response)

async def current_app_media_session_state(self):
"""Get the current app and the state from the output of ``dumpsys media_session``.
Returns
-------
str, None
The current app, or ``None`` if it could not be determined
int, None
The state from the output of the ADB shell command ``dumpsys media_session``, or ``None`` if it could not be determined
"""
media_session_state_response = await self._adb.shell(constants.CMD_MEDIA_SESSION_STATE_FULL)

return self._current_app_media_session_state(media_session_state_response)

async def get_hdmi_input(self):
"""Get the HDMI input from the output of :py:const:`androidtv.constants.CMD_HDMI_INPUT`.
Expand Down Expand Up @@ -317,9 +332,7 @@ async def media_session_state(self):
The state from the output of the ADB shell command ``dumpsys media_session``, or ``None`` if it could not be determined
"""
media_session_state_response = await self._adb.shell(constants.CMD_MEDIA_SESSION_STATE_FULL)

_, media_session_state = self._current_app_media_session_state(media_session_state_response)
_, media_session_state = await self.current_app_media_session_state()

return media_session_state

Expand Down
19 changes: 16 additions & 3 deletions androidtv/basetv/basetv_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ def current_app(self):

return self._current_app(current_app_response)

def current_app_media_session_state(self):
"""Get the current app and the state from the output of ``dumpsys media_session``.
Returns
-------
str, None
The current app, or ``None`` if it could not be determined
int, None
The state from the output of the ADB shell command ``dumpsys media_session``, or ``None`` if it could not be determined
"""
media_session_state_response = self._adb.shell(constants.CMD_MEDIA_SESSION_STATE_FULL)

return self._current_app_media_session_state(media_session_state_response)

def get_hdmi_input(self):
"""Get the HDMI input from the output of :py:const:`androidtv.constants.CMD_HDMI_INPUT`.
Expand Down Expand Up @@ -317,9 +332,7 @@ def media_session_state(self):
The state from the output of the ADB shell command ``dumpsys media_session``, or ``None`` if it could not be determined
"""
media_session_state_response = self._adb.shell(constants.CMD_MEDIA_SESSION_STATE_FULL)

_, media_session_state = self._current_app_media_session_state(media_session_state_response)
_, media_session_state = self.current_app_media_session_state()

return media_session_state

Expand Down

0 comments on commit 957f5b3

Please sign in to comment.