Order imports (#16515)
This commit is contained in:
1 parent
d6d4ff6888
commit
0d7ee9b93b
63 files changed
+629
-697
No files matched your search
@@ -4,17 +4,16 @@ Support to interface with the Plex API.
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/media_player.plex/
|
||||
"""
|
||||
from datetime import timedelta
|
||||
import json
|
||||
import logging
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
import requests
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import util
|
||||
from homeassistant.components.media_player import (
|
||||
MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_MOVIE, PLATFORM_SCHEMA,
|
||||
MEDIA_TYPE_MOVIE, MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, PLATFORM_SCHEMA,
|
||||
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PLAY, SUPPORT_PREVIOUS_TRACK,
|
||||
SUPPORT_STOP, SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
|
||||
MediaPlayerDevice)
|
||||
@@ -22,9 +21,8 @@ from homeassistant.const import (
|
||||
DEVICE_DEFAULT_NAME, STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING)
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.event import track_utc_time_change
|
||||
from homeassistant.util.json import load_json, save_json
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from homeassistant.util.json import load_json, save_json
|
||||
|
||||
REQUIREMENTS = ['plexapi==3.0.6']
|
||||
|
||||
@@ -35,6 +33,7 @@ MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
|
||||
|
||||
PLEX_CONFIG_FILE = 'plex.conf'
|
||||
PLEX_DATA = 'plex'
|
||||
|
||||
CONF_INCLUDE_NON_CLIENTS = 'include_non_clients'
|
||||
CONF_USE_EPISODE_ART = 'use_episode_art'
|
||||
@@ -44,20 +43,14 @@ CONF_REMOVE_UNAVAILABLE_CLIENTS = 'remove_unavailable_clients'
|
||||
CONF_CLIENT_REMOVE_INTERVAL = 'client_remove_interval'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Optional(CONF_INCLUDE_NON_CLIENTS, default=False):
|
||||
cv.boolean,
|
||||
vol.Optional(CONF_USE_EPISODE_ART, default=False):
|
||||
cv.boolean,
|
||||
vol.Optional(CONF_USE_CUSTOM_ENTITY_IDS, default=False):
|
||||
cv.boolean,
|
||||
vol.Optional(CONF_REMOVE_UNAVAILABLE_CLIENTS, default=True):
|
||||
cv.boolean,
|
||||
vol.Optional(CONF_INCLUDE_NON_CLIENTS, default=False): cv.boolean,
|
||||
vol.Optional(CONF_USE_EPISODE_ART, default=False): cv.boolean,
|
||||
vol.Optional(CONF_USE_CUSTOM_ENTITY_IDS, default=False): cv.boolean,
|
||||
vol.Optional(CONF_REMOVE_UNAVAILABLE_CLIENTS, default=True): cv.boolean,
|
||||
vol.Optional(CONF_CLIENT_REMOVE_INTERVAL, default=timedelta(seconds=600)):
|
||||
vol.All(cv.time_period, cv.positive_timedelta),
|
||||
})
|
||||
|
||||
PLEX_DATA = "plex"
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities_callback, discovery_info=None):
|
||||
"""Set up the Plex platform."""
|
||||
@@ -157,8 +150,8 @@ def setup_plexserver(
|
||||
_LOGGER.exception("Error listing plex devices")
|
||||
return
|
||||
except requests.exceptions.RequestException as ex:
|
||||
_LOGGER.error("Could not connect to plex server at http://%s (%s)",
|
||||
host, ex)
|
||||
_LOGGER.error(
|
||||
"Could not connect to plex server at http://%s (%s)", host, ex)
|
||||
return
|
||||
|
||||
new_plex_clients = []
|
||||
@@ -171,9 +164,9 @@ def setup_plexserver(
|
||||
available_client_ids.append(device.machineIdentifier)
|
||||
|
||||
if device.machineIdentifier not in plex_clients:
|
||||
new_client = PlexClient(config, device, None,
|
||||
plex_sessions, update_devices,
|
||||
update_sessions)
|
||||
new_client = PlexClient(
|
||||
config, device, None, plex_sessions, update_devices,
|
||||
update_sessions)
|
||||
plex_clients[device.machineIdentifier] = new_client
|
||||
new_plex_clients.append(new_client)
|
||||
else:
|
||||
@@ -184,9 +177,9 @@ def setup_plexserver(
|
||||
for machine_identifier, session in plex_sessions.items():
|
||||
if (machine_identifier not in plex_clients
|
||||
and machine_identifier is not None):
|
||||
new_client = PlexClient(config, None, session,
|
||||
plex_sessions, update_devices,
|
||||
update_sessions)
|
||||
new_client = PlexClient(
|
||||
config, None, session, plex_sessions, update_devices,
|
||||
update_sessions)
|
||||
plex_clients[machine_identifier] = new_client
|
||||
new_plex_clients.append(new_client)
|
||||
else:
|
||||
@@ -225,8 +218,8 @@ def setup_plexserver(
|
||||
_LOGGER.exception("Error listing plex sessions")
|
||||
return
|
||||
except requests.exceptions.RequestException as ex:
|
||||
_LOGGER.error("Could not connect to plex server at http://%s (%s)",
|
||||
host, ex)
|
||||
_LOGGER.error(
|
||||
"Could not connect to plex server at http://%s (%s)", host, ex)
|
||||
return
|
||||
|
||||
plex_sessions.clear()
|
||||
|
||||
Reference in new issue
Block a user