Skip to content

Commit

Permalink
Change Plex wake_lock_size priority (#115)
Browse files Browse the repository at this point in the history
* Rewrite plex priority to cover playback edge cases

While testing Plex, I found that `paused` only uses `'wake_lock_size': 1`. But playing (in my logging) triggered (very rarely) a `wake_lock_size` of `4`, `5`, and `7`. I'm sure there are others that I didn't log, so changing the order should catch any extra `wake_lock_size` states.

* Attempt to apply fix to code and add tests

* Idle state to standby fix

* Make Plex `media_session_state` use nested `if`

* Add dropped line filtering the app for Plex
  • Loading branch information
aav7fl authored and JeffLIrion committed Oct 21, 2019
1 parent 5c39196 commit f3254d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
8 changes: 7 additions & 1 deletion androidtv/androidtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ def update(self):

# Plex
elif current_app == constants.APP_PLEX:
state = audio_state
if media_session_state == 3:
if wake_lock_size == 1:
state = constants.STATE_PAUSED
else:
state = constants.STATE_PLAYING
else:
state = constants.STATE_STANDBY

# TVheadend
elif current_app == constants.APP_TVHEADEND:
Expand Down
4 changes: 2 additions & 2 deletions androidtv/basetv.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class BaseTV(object):
'com.ellation.vrv': ['audio_state'],
'com.hulu.plus': [{'playing': {'wake_lock_size' : 4}},
{'paused': {'wake_lock_size': 2}}],
'com.plexapp.android': [{'playing': {'media_session_state': 3, 'wake_lock_size': 3}},
{'paused': {'media_session_state': 3, 'wake_lock_size': 1}},
'com.plexapp.android': [{'paused': {'media_session_state': 3, 'wake_lock_size': 1}},
{'playing': {'media_session_state': 3}},
'standby']}
The keys are app IDs, and the values are lists of rules that are evaluated in order.
Expand Down
17 changes: 16 additions & 1 deletion tests/test_androidtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,22 @@ def test_state_detection(self):

# Plex
self.assertUpdate([True, True, constants.STATE_IDLE, 2, constants.APP_PLEX, 4, 'hmdi_arc', False, 30],
(constants.STATE_IDLE, constants.APP_PLEX, 'hmdi_arc', False, 0.5))
(constants.STATE_STANDBY, constants.APP_PLEX, 'hmdi_arc', False, 0.5))

self.assertUpdate([True, True, constants.STATE_IDLE, 3, constants.APP_PLEX, 3, 'hmdi_arc', False, 30],
(constants.STATE_PLAYING, constants.APP_PLEX, 'hmdi_arc', False, 0.5))

self.assertUpdate([True, True, constants.STATE_IDLE, 4, constants.APP_PLEX, 3, 'hmdi_arc', False, 30],
(constants.STATE_PLAYING, constants.APP_PLEX, 'hmdi_arc', False, 0.5))

self.assertUpdate([True, True, constants.STATE_IDLE, 5, constants.APP_PLEX, 3, 'hmdi_arc', False, 30],
(constants.STATE_PLAYING, constants.APP_PLEX, 'hmdi_arc', False, 0.5))

self.assertUpdate([True, True, constants.STATE_IDLE, 7, constants.APP_PLEX, 3, 'hmdi_arc', False, 30],
(constants.STATE_PLAYING, constants.APP_PLEX, 'hmdi_arc', False, 0.5))

self.assertUpdate([True, True, constants.STATE_IDLE, 1, constants.APP_PLEX, 3, 'hmdi_arc', False, 30],
(constants.STATE_PAUSED, constants.APP_PLEX, 'hmdi_arc', False, 0.5))

# TVheadend
self.assertUpdate([True, True, constants.STATE_IDLE, 5, constants.APP_TVHEADEND, 4, 'hmdi_arc', False, 30],
Expand Down

0 comments on commit f3254d0

Please sign in to comment.