Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'audio_state': constants.STATE_IDLE,
'wake_lock_size': 2,
'current_app': 'com.amazon.tv.launcher',
'media_session_state': None,
'audio_output_device': None,
'is_volume_muted': None,
'volume': None,
'running_apps': None}
GET_PROPERTIES_OUTPUT4 = """111Wake Locks: size=2
com.amazon.tv.launcher
state=PlaybackState {state=1, position=0, buffered position=0, speed=0.0, updated=65749, actions=240640, custom actions=[], active item id=-1, error=null}
"""
GET_PROPERTIES_DICT4 = {'screen_on': True,
'awake': True,
'audio_state': constants.STATE_PAUSED,
'wake_lock_size': 2,
'current_app': 'com.amazon.tv.launcher',
'media_session_state': 1,
'audio_output_device': None,
'is_volume_muted': None,
'volume': None,
'running_apps': None}
GET_PROPERTIES_DICT_NONE = {'screen_on': None,
'awake': None,
'audio_state': None,
'wake_lock_size': None,
'media_session_state': None,
'current_app': None,
'audio_output_device': None,
'is_volume_muted': None,
self.assertUpdate([True, True, constants.STATE_IDLE, 4, constants.APP_PLEX, 3, 'hmdi_arc', False, 30, None],
(constants.STATE_PLAYING, constants.APP_PLEX, [constants.APP_PLEX], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 5, constants.APP_PLEX, 3, 'hmdi_arc', False, 30, None],
(constants.STATE_PLAYING, constants.APP_PLEX, [constants.APP_PLEX], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 7, constants.APP_PLEX, 3, 'hmdi_arc', False, 30, None],
(constants.STATE_PLAYING, constants.APP_PLEX, [constants.APP_PLEX], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 1, constants.APP_PLEX, 3, 'hmdi_arc', False, 30, None],
(constants.STATE_PAUSED, constants.APP_PLEX, [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, None],
(constants.STATE_PAUSED, constants.APP_TVHEADEND, [constants.APP_TVHEADEND], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 6, constants.APP_TVHEADEND, 4, 'hmdi_arc', False, 30, None],
(constants.STATE_PLAYING, constants.APP_TVHEADEND, [constants.APP_TVHEADEND], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 1, constants.APP_TVHEADEND, 4, 'hmdi_arc', False, 30, None],
(constants.STATE_IDLE, constants.APP_TVHEADEND, [constants.APP_TVHEADEND], 'hmdi_arc', False, 0.5))
# VLC
self.assertUpdate([True, True, constants.STATE_IDLE, 6, constants.APP_VLC, 2, 'hmdi_arc', False, 30, None],
(constants.STATE_PAUSED, constants.APP_VLC, [constants.APP_VLC], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 6, constants.APP_VLC, 3, 'hmdi_arc', False, 30, None],
(constants.STATE_PLAYING, constants.APP_VLC, [constants.APP_VLC], 'hmdi_arc', False, 0.5))
self.assertUpdate([True, True, constants.STATE_IDLE, 6, constants.APP_VLC, 4, 'hmdi_arc', False, 30, None],
(constants.STATE_IDLE, constants.APP_VLC, [constants.APP_VLC], 'hmdi_arc', False, 0.5))
# =========================================================================== #
# #
# media_player.py #
# #
# =========================================================================== #
# Translate from `AndroidTV` / `FireTV` reported state to HA state.
ANDROIDTV_STATES = {
"off": STATE_OFF,
"idle": STATE_IDLE,
"standby": STATE_STANDBY,
"playing": STATE_PLAYING,
"paused": STATE_PAUSED,
}
def adb_decorator(override_available=False):
"""Wrap ADB methods and catch exceptions.
Allows for overriding the available status of the ADB connection via the
`override_available` parameter.
"""
def _adb_decorator(func):
"""Wrap the provided ADB method and catch exceptions."""
@functools.wraps(func)
def _adb_exception_catcher(self, *args, **kwargs):
"""Call an ADB-related method and catch exceptions."""
if not self.available and not override_available:
# Sport 1
self.assertUpdate([True, True, 3, constants.APP_SPORT1, 3, [constants.APP_SPORT1]],
(constants.STATE_PLAYING, constants.APP_SPORT1, [constants.APP_SPORT1]))
self.assertUpdate([True, True, 2, constants.APP_SPORT1, 3, [constants.APP_SPORT1]],
(constants.STATE_PAUSED, constants.APP_SPORT1, [constants.APP_SPORT1]))
self.assertUpdate([True, True, 1, constants.APP_SPORT1, 3, [constants.APP_SPORT1]],
(constants.STATE_IDLE, constants.APP_SPORT1, [constants.APP_SPORT1]))
# Spotify
self.assertUpdate([True, True, 1, constants.APP_SPOTIFY, 3, [constants.APP_SPOTIFY]],
(constants.STATE_PLAYING, constants.APP_SPOTIFY, [constants.APP_SPOTIFY]))
self.assertUpdate([True, True, 1, constants.APP_SPOTIFY, 2, [constants.APP_SPOTIFY]],
(constants.STATE_PAUSED, constants.APP_SPOTIFY, [constants.APP_SPOTIFY]))
self.assertUpdate([True, True, 1, constants.APP_SPOTIFY, 1, [constants.APP_SPOTIFY]],
(constants.STATE_IDLE, constants.APP_SPOTIFY, [constants.APP_SPOTIFY]))
# Twitch
self.assertUpdate([True, True, 2, constants.APP_TWITCH, 3, [constants.APP_TWITCH]],
(constants.STATE_PAUSED, constants.APP_TWITCH, [constants.APP_TWITCH]))
self.assertUpdate([True, True, 1, constants.APP_TWITCH, 3, [constants.APP_TWITCH]],
(constants.STATE_PLAYING, constants.APP_TWITCH, [constants.APP_TWITCH]))
self.assertUpdate([True, True, 1, constants.APP_TWITCH, 4, [constants.APP_TWITCH]],
(constants.STATE_PLAYING, constants.APP_TWITCH, [constants.APP_TWITCH]))
self.assertUpdate([True, True, 1, constants.APP_TWITCH, 1, [constants.APP_TWITCH]],
(constants.STATE_IDLE, constants.APP_TWITCH, [constants.APP_TWITCH]))
"""
self.assertUpdate([False, None, -1, None, None, None],
(constants.STATE_OFF, None, None))
self.assertUpdate([True, False, -1, None, None, None],
(constants.STATE_STANDBY, None, None))
self.assertUpdate([True, True, 1, "com.amazon.tv.launcher", None, None],
(constants.STATE_IDLE, "com.amazon.tv.launcher", ["com.amazon.tv.launcher"]))
# Amazon Video
self.assertUpdate([True, True, 1, constants.APP_AMAZON_VIDEO, 3, [constants.APP_AMAZON_VIDEO]],
(constants.STATE_PLAYING, constants.APP_AMAZON_VIDEO, [constants.APP_AMAZON_VIDEO]))
self.assertUpdate([True, True, 1, constants.APP_AMAZON_VIDEO, 2, [constants.APP_AMAZON_VIDEO]],
(constants.STATE_PAUSED, constants.APP_AMAZON_VIDEO, [constants.APP_AMAZON_VIDEO]))
self.assertUpdate([True, True, 1, constants.APP_AMAZON_VIDEO, 1, [constants.APP_AMAZON_VIDEO]],
(constants.STATE_IDLE, constants.APP_AMAZON_VIDEO, [constants.APP_AMAZON_VIDEO]))
# Amazon Video with custom state detection rules
self.ftv._state_detection_rules = {constants.APP_AMAZON_VIDEO: ['media_session_state']}
self.assertUpdate([True, True, 2, constants.APP_AMAZON_VIDEO, 2, [constants.APP_AMAZON_VIDEO]],
(constants.STATE_PAUSED, constants.APP_AMAZON_VIDEO, [constants.APP_AMAZON_VIDEO]))
self.assertUpdate([True, True, 5, constants.APP_AMAZON_VIDEO, 3, [constants.APP_AMAZON_VIDEO]],
(constants.STATE_PLAYING, constants.APP_AMAZON_VIDEO, [constants.APP_AMAZON_VIDEO]))
self.assertUpdate([True, True, 5, constants.APP_AMAZON_VIDEO, 1, [constants.APP_AMAZON_VIDEO]],
(constants.STATE_IDLE, constants.APP_AMAZON_VIDEO, [constants.APP_AMAZON_VIDEO]))
state = audio_state
# Netflix
elif current_app == constants.APP_NETFLIX:
if media_session_state == 2:
state = constants.STATE_PAUSED
elif media_session_state == 3:
state = constants.STATE_PLAYING
else:
state = constants.STATE_IDLE
# Plex
elif current_app == constants.APP_PLEX:
if media_session_state == 3:
if wake_lock_size == 1:
state = constants.STATE_PAUSED
else:
state = constants.STATE_PLAYING
else:
state = constants.STATE_IDLE
# TVheadend
elif current_app == constants.APP_TVHEADEND:
if wake_lock_size == 5:
state = constants.STATE_PAUSED
elif wake_lock_size == 6:
state = constants.STATE_PLAYING
else:
state = constants.STATE_IDLE
# VLC
elif current_app == constants.APP_VLC:
else:
state = constants.STATE_IDLE
# Sport 1
elif current_app == constants.APP_SPORT1:
if wake_lock_size == 2:
state = constants.STATE_PAUSED
elif wake_lock_size == 3:
state = constants.STATE_PLAYING
else:
state = constants.STATE_IDLE
# Spotify
elif current_app == constants.APP_SPOTIFY:
if media_session_state == 2:
state = constants.STATE_PAUSED
elif media_session_state == 3:
state = constants.STATE_PLAYING
else:
state = constants.STATE_IDLE
# Twitch
elif current_app == constants.APP_TWITCH:
if wake_lock_size == 2:
state = constants.STATE_PAUSED
elif media_session_state == 3:
state = constants.STATE_PLAYING
elif media_session_state == 4:
state = constants.STATE_PLAYING
else:
state = constants.STATE_IDLE