mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Logic fixes
This commit is contained in:
parent
5b25d9ccd6
commit
bc8c5766d4
@ -53,6 +53,7 @@ def config_from_file(filename, config=None):
|
|||||||
return json.loads(fdesc.read())
|
return json.loads(fdesc.read())
|
||||||
except IOError as error:
|
except IOError as error:
|
||||||
_LOGGER.error('Reading config file failed: %s', error)
|
_LOGGER.error('Reading config file failed: %s', error)
|
||||||
|
# This won't work yet
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
@ -62,8 +63,13 @@ def config_from_file(filename, config=None):
|
|||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
||||||
""" Sets up the plex platform. """
|
""" Sets up the plex platform. """
|
||||||
|
|
||||||
|
config = config_from_file(hass.config.path(PLEX_CONFIG_FILE))
|
||||||
|
if len(config):
|
||||||
|
# Setup a configured PlexServer
|
||||||
|
host, token = config.popitem()
|
||||||
|
token = token['token']
|
||||||
# Via discovery
|
# Via discovery
|
||||||
if discovery_info is not None:
|
elif discovery_info is not None:
|
||||||
# Parse discovery data
|
# Parse discovery data
|
||||||
host = urlparse(discovery_info[1]).netloc
|
host = urlparse(discovery_info[1]).netloc
|
||||||
_LOGGER.info('Discovered PLEX server: %s', host)
|
_LOGGER.info('Discovered PLEX server: %s', host)
|
||||||
@ -71,16 +77,8 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
if host in _CONFIGURING:
|
if host in _CONFIGURING:
|
||||||
return
|
return
|
||||||
token = None
|
token = None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Setup a configured PlexServer
|
return
|
||||||
config = config_from_file(hass.config.path(PLEX_CONFIG_FILE))
|
|
||||||
if len(config):
|
|
||||||
host, token = config.popitem()
|
|
||||||
token = token['token']
|
|
||||||
else:
|
|
||||||
# Empty config file?
|
|
||||||
return
|
|
||||||
|
|
||||||
setup_plexserver(host, token, hass, add_devices_callback)
|
setup_plexserver(host, token, hass, add_devices_callback)
|
||||||
|
|
||||||
@ -88,20 +86,18 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
def setup_plexserver(host, token, hass, add_devices_callback):
|
def setup_plexserver(host, token, hass, add_devices_callback):
|
||||||
''' Setup a plexserver based on host parameter'''
|
''' Setup a plexserver based on host parameter'''
|
||||||
import plexapi
|
import plexapi.server
|
||||||
|
import plexapi.exceptions
|
||||||
|
|
||||||
try:
|
try:
|
||||||
plexserver = plexapi.server.PlexServer('http://%s' % host, token)
|
plexserver = plexapi.server.PlexServer('http://%s' % host, token)
|
||||||
except (plexapi.exceptions.BadRequest,
|
except (plexapi.exceptions.BadRequest,
|
||||||
plexapi.exceptions.Unauthorized) as error:
|
plexapi.exceptions.Unauthorized,
|
||||||
|
plexapi.exceptions.NotFound) as error:
|
||||||
_LOGGER.info(error)
|
_LOGGER.info(error)
|
||||||
# No token or wrong token
|
# No token or wrong token
|
||||||
request_configuration(host, hass, add_devices_callback)
|
request_configuration(host, hass, add_devices_callback)
|
||||||
return
|
return
|
||||||
except plexapi.exceptions.NotFound:
|
|
||||||
# Host not found. Maybe it's off. Just log it and stop
|
|
||||||
_LOGGER.info(error)
|
|
||||||
return
|
|
||||||
|
|
||||||
# If we came here and configuring this host, mark as done
|
# If we came here and configuring this host, mark as done
|
||||||
if host in _CONFIGURING:
|
if host in _CONFIGURING:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user