new attempt for PR

This commit is contained in:
Tom Duijf 2015-10-13 21:59:13 +00:00
parent 96181a555a
commit a236b87ccf

View File

@ -16,9 +16,7 @@ from homeassistant.const import (
STATE_IDLE, STATE_PLAYING, STATE_PAUSED, STATE_OFF, STATE_UNKNOWN) STATE_IDLE, STATE_PLAYING, STATE_PAUSED, STATE_OFF, STATE_UNKNOWN)
import homeassistant.util as util import homeassistant.util as util
REQUIREMENTS = ['https://github.com/adrienbrault/python-plexapi/archive/' REQUIREMENTS = ['plexapi==1.1.0']
'df2d0847e801d6d5cda920326d693cf75f304f1a.zip'
'#python-plexapi==1.0.2']
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1) MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
@ -45,24 +43,24 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
def update_devices(): def update_devices():
""" Updates the devices objects. """ """ Updates the devices objects. """
try: try:
devices = plexuser.devices() devices = plexserver.clients()
except BadRequest: except BadRequest:
_LOGGER.exception("Error listing plex devices") _LOGGER.exception("Error listing plex devices")
return return
new_plex_clients = [] new_plex_clients = []
for device in devices: for device in devices:
if (all(x not in ['client', 'player'] for x in device.provides) # For now, let's allow all deviceClass types
or 'PlexAPI' == device.product): if device.deviceClass in []:
continue continue
if device.clientIdentifier not in plex_clients: if device.machineIdentifier not in plex_clients:
new_client = PlexClient(device, plex_sessions, update_devices, new_client = PlexClient(device, plex_sessions, update_devices,
update_sessions) update_sessions)
plex_clients[device.clientIdentifier] = new_client plex_clients[device.machineIdentifier] = new_client
new_plex_clients.append(new_client) new_plex_clients.append(new_client)
else: else:
plex_clients[device.clientIdentifier].set_device(device) plex_clients[device.machineIdentifier].set_device(device)
if new_plex_clients: if new_plex_clients:
add_devices(new_plex_clients) add_devices(new_plex_clients)
@ -101,10 +99,10 @@ class PlexClient(MediaPlayerDevice):
@property @property
def session(self): def session(self):
""" Returns the session, if any. """ """ Returns the session, if any. """
if self.device.clientIdentifier not in self.plex_sessions: if self.device.machineIdentifier not in self.plex_sessions:
return None return None
return self.plex_sessions[self.device.clientIdentifier] return self.plex_sessions[self.device.machineIdentifier]
@property @property
def name(self): def name(self):
@ -120,7 +118,8 @@ class PlexClient(MediaPlayerDevice):
return STATE_PLAYING return STATE_PLAYING
elif state == 'paused': elif state == 'paused':
return STATE_PAUSED return STATE_PAUSED
elif self.device.isReachable: # This is nasty. Need ti find a way to determine alive
elif self.device:
return STATE_IDLE return STATE_IDLE
else: else:
return STATE_OFF return STATE_OFF
@ -196,16 +195,16 @@ class PlexClient(MediaPlayerDevice):
def media_play(self): def media_play(self):
""" media_play media player. """ """ media_play media player. """
self.device.play({'type': 'video'}) self.device.play()
def media_pause(self): def media_pause(self):
""" media_pause media player. """ """ media_pause media player. """
self.device.pause({'type': 'video'}) self.device.pause()
def media_next_track(self): def media_next_track(self):
""" Send next track command. """ """ Send next track command. """
self.device.skipNext({'type': 'video'}) self.device.skipNext()
def media_previous_track(self): def media_previous_track(self):
""" Send previous track command. """ """ Send previous track command. """
self.device.skipPrevious({'type': 'video'}) self.device.skipPrevious()