2015-09-19 17:48:45 +00:00
|
|
|
"""
|
2016-03-08 09:34:33 +00:00
|
|
|
Support to interface with the Plex API.
|
2015-09-19 17:48:45 +00:00
|
|
|
|
2015-10-09 21:33:59 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
2015-11-09 12:12:18 +00:00
|
|
|
https://home-assistant.io/components/media_player.plex/
|
2015-09-19 17:48:45 +00:00
|
|
|
"""
|
2015-10-25 17:00:54 +00:00
|
|
|
import json
|
|
|
|
import logging
|
2016-02-19 05:27:50 +00:00
|
|
|
import os
|
2015-09-29 19:50:07 +00:00
|
|
|
from datetime import timedelta
|
2015-09-19 17:48:45 +00:00
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
import requests
|
|
|
|
import voluptuous as vol
|
2017-04-24 03:41:09 +00:00
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
from homeassistant import util
|
2015-09-19 17:48:45 +00:00
|
|
|
from homeassistant.components.media_player import (
|
2017-04-24 03:41:09 +00:00
|
|
|
MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_VIDEO, PLATFORM_SCHEMA,
|
|
|
|
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PLAY, SUPPORT_PREVIOUS_TRACK,
|
|
|
|
SUPPORT_STOP, SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET,
|
|
|
|
MediaPlayerDevice)
|
2015-09-19 17:48:45 +00:00
|
|
|
from homeassistant.const import (
|
2017-04-24 03:41:09 +00:00
|
|
|
DEVICE_DEFAULT_NAME, STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
from homeassistant.helpers import config_validation as cv
|
|
|
|
from homeassistant.helpers.event import track_utc_time_change
|
|
|
|
|
2017-10-25 09:42:13 +00:00
|
|
|
REQUIREMENTS = ['plexapi==3.0.3']
|
2017-04-24 03:41:09 +00:00
|
|
|
|
|
|
|
_CONFIGURING = {}
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2015-09-29 19:50:07 +00:00
|
|
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
|
|
|
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
|
2015-09-19 18:16:57 +00:00
|
|
|
|
2015-10-18 20:02:18 +00:00
|
|
|
PLEX_CONFIG_FILE = 'plex.conf'
|
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
CONF_INCLUDE_NON_CLIENTS = 'include_non_clients'
|
|
|
|
CONF_USE_EPISODE_ART = 'use_episode_art'
|
|
|
|
CONF_USE_CUSTOM_ENTITY_IDS = 'use_custom_entity_ids'
|
|
|
|
CONF_SHOW_ALL_CONTROLS = 'show_all_controls'
|
|
|
|
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
|
2015-10-25 17:00:54 +00:00
|
|
|
|
2015-10-25 10:45:15 +00:00
|
|
|
def config_from_file(filename, config=None):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Small configuration file management function."""
|
2015-10-25 10:45:15 +00:00
|
|
|
if config:
|
|
|
|
# We're writing configuration
|
|
|
|
try:
|
2015-10-25 17:00:54 +00:00
|
|
|
with open(filename, 'w') as fdesc:
|
|
|
|
fdesc.write(json.dumps(config))
|
|
|
|
except IOError as error:
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.error("Saving config file failed: %s", error)
|
2015-10-25 10:45:15 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
# We're reading config
|
|
|
|
if os.path.isfile(filename):
|
|
|
|
try:
|
2015-10-25 17:00:54 +00:00
|
|
|
with open(filename, 'r') as fdesc:
|
|
|
|
return json.loads(fdesc.read())
|
|
|
|
except IOError as error:
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.error("Reading config file failed: %s", error)
|
2015-10-25 17:54:48 +00:00
|
|
|
# This won't work yet
|
2015-10-25 10:45:15 +00:00
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return {}
|
2015-10-25 17:00:54 +00:00
|
|
|
|
2015-09-20 20:13:26 +00:00
|
|
|
|
2015-10-22 21:16:04 +00:00
|
|
|
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up the Plex platform."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# get config from plex.conf
|
|
|
|
file_config = config_from_file(hass.config.path(PLEX_CONFIG_FILE))
|
|
|
|
|
2017-04-24 03:41:09 +00:00
|
|
|
if file_config:
|
2015-10-25 17:54:48 +00:00
|
|
|
# Setup a configured PlexServer
|
2017-07-12 06:26:29 +00:00
|
|
|
host, host_config = file_config.popitem()
|
|
|
|
token = host_config['token']
|
|
|
|
try:
|
|
|
|
has_ssl = host_config['ssl']
|
|
|
|
except KeyError:
|
|
|
|
has_ssl = False
|
|
|
|
try:
|
|
|
|
verify_ssl = host_config['verify']
|
|
|
|
except KeyError:
|
|
|
|
verify_ssl = True
|
|
|
|
|
2015-10-25 10:45:15 +00:00
|
|
|
# Via discovery
|
2015-10-25 17:54:48 +00:00
|
|
|
elif discovery_info is not None:
|
2015-10-22 21:16:04 +00:00
|
|
|
# Parse discovery data
|
2017-04-12 03:10:02 +00:00
|
|
|
host = discovery_info.get('host')
|
2017-06-25 23:06:15 +00:00
|
|
|
port = discovery_info.get('port')
|
|
|
|
host = '%s:%s' % (host, port)
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.info("Discovered PLEX server: %s", host)
|
2015-10-18 20:02:18 +00:00
|
|
|
|
2015-10-25 10:45:15 +00:00
|
|
|
if host in _CONFIGURING:
|
|
|
|
return
|
|
|
|
token = None
|
2017-07-12 06:26:29 +00:00
|
|
|
has_ssl = False
|
|
|
|
verify_ssl = True
|
2015-10-25 10:45:15 +00:00
|
|
|
else:
|
2015-10-25 17:54:48 +00:00
|
|
|
return
|
2015-10-25 10:45:15 +00:00
|
|
|
|
2017-07-12 06:26:29 +00:00
|
|
|
setup_plexserver(
|
|
|
|
host, token, has_ssl, verify_ssl,
|
|
|
|
hass, config, add_devices_callback
|
|
|
|
)
|
2015-10-18 20:02:18 +00:00
|
|
|
|
|
|
|
|
2017-07-12 06:26:29 +00:00
|
|
|
def setup_plexserver(
|
|
|
|
host, token, has_ssl, verify_ssl, hass, config, add_devices_callback):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up a plexserver based on host parameter."""
|
2015-10-25 17:54:48 +00:00
|
|
|
import plexapi.server
|
|
|
|
import plexapi.exceptions
|
2015-09-29 19:50:07 +00:00
|
|
|
|
2017-07-12 06:26:29 +00:00
|
|
|
cert_session = None
|
|
|
|
http_prefix = 'https' if has_ssl else 'http'
|
|
|
|
if has_ssl and (verify_ssl is False):
|
|
|
|
_LOGGER.info("Ignoring SSL verification")
|
|
|
|
cert_session = requests.Session()
|
|
|
|
cert_session.verify = False
|
2015-10-22 21:16:04 +00:00
|
|
|
try:
|
2017-07-12 06:26:29 +00:00
|
|
|
plexserver = plexapi.server.PlexServer(
|
|
|
|
'%s://%s' % (http_prefix, host),
|
|
|
|
token, cert_session
|
|
|
|
)
|
2017-06-25 23:06:15 +00:00
|
|
|
_LOGGER.info("Discovery configuration done (no token needed)")
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized,
|
2015-10-25 17:54:48 +00:00
|
|
|
plexapi.exceptions.NotFound) as error:
|
2015-10-25 17:00:54 +00:00
|
|
|
_LOGGER.info(error)
|
2015-10-25 10:45:15 +00:00
|
|
|
# No token or wrong token
|
2017-05-02 16:18:47 +00:00
|
|
|
request_configuration(host, hass, config, add_devices_callback)
|
2015-10-22 21:16:04 +00:00
|
|
|
return
|
2015-10-18 20:02:18 +00:00
|
|
|
|
2015-10-25 10:45:15 +00:00
|
|
|
# If we came here and configuring this host, mark as done
|
|
|
|
if host in _CONFIGURING:
|
|
|
|
request_id = _CONFIGURING.pop(host)
|
2017-08-14 05:37:50 +00:00
|
|
|
configurator = hass.components.configurator
|
2015-10-25 10:45:15 +00:00
|
|
|
configurator.request_done(request_id)
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.info("Discovery configuration done")
|
2015-10-25 10:45:15 +00:00
|
|
|
|
|
|
|
# Save config
|
|
|
|
if not config_from_file(
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
hass.config.path(PLEX_CONFIG_FILE), {host: {
|
2017-07-12 06:26:29 +00:00
|
|
|
'token': token,
|
|
|
|
'ssl': has_ssl,
|
|
|
|
'verify': verify_ssl,
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
}}):
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.error("Failed to save configuration file")
|
2015-10-25 10:45:15 +00:00
|
|
|
|
2017-07-12 06:26:29 +00:00
|
|
|
_LOGGER.info('Connected to: %s://%s', http_prefix, host)
|
2015-10-18 20:02:18 +00:00
|
|
|
|
2015-09-29 19:50:07 +00:00
|
|
|
plex_clients = {}
|
|
|
|
plex_sessions = {}
|
2016-04-14 05:33:30 +00:00
|
|
|
track_utc_time_change(hass, lambda now: update_devices(), second=30)
|
2015-09-29 19:50:07 +00:00
|
|
|
|
|
|
|
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
|
|
|
def update_devices():
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Update the devices objects."""
|
2015-09-29 19:50:07 +00:00
|
|
|
try:
|
2015-10-13 21:59:13 +00:00
|
|
|
devices = plexserver.clients()
|
2015-10-25 10:45:15 +00:00
|
|
|
except plexapi.exceptions.BadRequest:
|
2017-05-02 16:18:47 +00:00
|
|
|
_LOGGER.exception("Error listing plex devices")
|
2016-07-05 17:50:43 +00:00
|
|
|
return
|
2017-07-13 15:01:12 +00:00
|
|
|
except requests.exceptions.RequestException as ex:
|
|
|
|
_LOGGER.error("Could not connect to plex server at http://%s (%s)",
|
|
|
|
host, ex)
|
2015-09-29 19:50:07 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
new_plex_clients = []
|
|
|
|
for device in devices:
|
2015-10-13 21:59:13 +00:00
|
|
|
# For now, let's allow all deviceClass types
|
2015-10-16 18:15:04 +00:00
|
|
|
if device.deviceClass in ['badClient']:
|
2015-09-29 19:50:07 +00:00
|
|
|
continue
|
|
|
|
|
2015-10-13 21:59:13 +00:00
|
|
|
if device.machineIdentifier not in plex_clients:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
new_client = PlexClient(config, device, None,
|
|
|
|
plex_sessions, update_devices,
|
2017-10-25 09:42:13 +00:00
|
|
|
update_sessions, plexserver)
|
2015-10-13 21:59:13 +00:00
|
|
|
plex_clients[device.machineIdentifier] = new_client
|
2015-09-29 19:50:07 +00:00
|
|
|
new_plex_clients.append(new_client)
|
|
|
|
else:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
plex_clients[device.machineIdentifier].refresh(device, None)
|
|
|
|
|
|
|
|
# add devices with a session and no client (ex. PlexConnect Apple TV's)
|
|
|
|
if config.get(CONF_INCLUDE_NON_CLIENTS):
|
|
|
|
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,
|
2017-10-25 09:42:13 +00:00
|
|
|
update_sessions, plexserver)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
plex_clients[machine_identifier] = new_client
|
|
|
|
new_plex_clients.append(new_client)
|
|
|
|
else:
|
|
|
|
plex_clients[machine_identifier].refresh(None, session)
|
|
|
|
|
|
|
|
for machine_identifier, client in plex_clients.items():
|
|
|
|
# force devices to idle that do not have a valid session
|
|
|
|
if client.session is None:
|
|
|
|
client.force_idle()
|
2015-09-29 19:50:07 +00:00
|
|
|
|
|
|
|
if new_plex_clients:
|
2015-10-25 10:45:15 +00:00
|
|
|
add_devices_callback(new_plex_clients)
|
2015-09-29 19:50:07 +00:00
|
|
|
|
|
|
|
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
|
|
|
|
def update_sessions():
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Update the sessions objects."""
|
2015-09-29 19:50:07 +00:00
|
|
|
try:
|
|
|
|
sessions = plexserver.sessions()
|
2015-10-25 10:45:15 +00:00
|
|
|
except plexapi.exceptions.BadRequest:
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.exception("Error listing plex sessions")
|
2015-09-29 19:50:07 +00:00
|
|
|
return
|
2017-07-13 15:01:12 +00:00
|
|
|
except requests.exceptions.RequestException as ex:
|
|
|
|
_LOGGER.error("Could not connect to plex server at http://%s (%s)",
|
|
|
|
host, ex)
|
|
|
|
return
|
2015-09-29 19:50:07 +00:00
|
|
|
|
|
|
|
plex_sessions.clear()
|
|
|
|
for session in sessions:
|
2017-10-25 09:42:13 +00:00
|
|
|
for player in session.players:
|
|
|
|
plex_sessions[player.machineIdentifier] = session
|
2015-09-29 19:50:07 +00:00
|
|
|
|
|
|
|
update_sessions()
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
update_devices()
|
2015-09-19 17:48:45 +00:00
|
|
|
|
2015-09-20 20:13:26 +00:00
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
def request_configuration(host, hass, config, add_devices_callback):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Request configuration steps from the user."""
|
2017-08-14 05:37:50 +00:00
|
|
|
configurator = hass.components.configurator
|
2015-10-20 16:59:22 +00:00
|
|
|
# We got an error if this method is called while we are configuring
|
|
|
|
if host in _CONFIGURING:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
configurator.notify_errors(_CONFIGURING[host],
|
|
|
|
'Failed to register, please try again.')
|
2015-10-20 16:59:22 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
def plex_configuration_callback(data):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Handle configuration changes."""
|
|
|
|
setup_plexserver(
|
2017-07-12 06:26:29 +00:00
|
|
|
host, data.get('token'),
|
|
|
|
cv.boolean(data.get('has_ssl')),
|
|
|
|
cv.boolean(data.get('do_not_verify')),
|
|
|
|
hass, config, add_devices_callback
|
|
|
|
)
|
2015-10-20 16:59:22 +00:00
|
|
|
|
|
|
|
_CONFIGURING[host] = configurator.request_config(
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
'Plex Media Server',
|
|
|
|
plex_configuration_callback,
|
2015-10-22 21:16:04 +00:00
|
|
|
description=('Enter the X-Plex-Token'),
|
2016-10-25 05:28:34 +00:00
|
|
|
entity_picture='/static/images/logo_plex_mediaserver.png',
|
2016-07-05 17:50:43 +00:00
|
|
|
submit_caption='Confirm',
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
fields=[{
|
|
|
|
'id': 'token',
|
|
|
|
'name': 'X-Plex-Token',
|
|
|
|
'type': ''
|
2017-07-12 06:26:29 +00:00
|
|
|
}, {
|
|
|
|
'id': 'has_ssl',
|
|
|
|
'name': 'Use SSL',
|
|
|
|
'type': ''
|
|
|
|
}, {
|
|
|
|
'id': 'do_not_verify_ssl',
|
|
|
|
'name': 'Do not verify SSL',
|
|
|
|
'type': ''
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
}])
|
2015-10-20 16:59:22 +00:00
|
|
|
|
|
|
|
|
2015-09-19 17:48:45 +00:00
|
|
|
class PlexClient(MediaPlayerDevice):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Representation of a Plex device."""
|
2015-09-19 17:48:45 +00:00
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
def __init__(self, config, device, session, plex_sessions,
|
2017-10-25 09:42:13 +00:00
|
|
|
update_devices, update_sessions, plex_server):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Initialize the Plex device."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._app_name = ''
|
2017-10-25 09:42:13 +00:00
|
|
|
self._server = plex_server
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._device = None
|
|
|
|
self._device_protocol_capabilities = None
|
|
|
|
self._is_player_active = False
|
|
|
|
self._is_player_available = False
|
2017-10-25 09:42:13 +00:00
|
|
|
self._player = None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._machine_identifier = None
|
|
|
|
self._make = ''
|
|
|
|
self._name = None
|
|
|
|
self._player_state = 'idle'
|
|
|
|
self._previous_volume_level = 1 # Used in fake muting
|
|
|
|
self._session = None
|
|
|
|
self._session_type = None
|
2017-04-01 02:36:37 +00:00
|
|
|
self._session_username = None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._state = STATE_IDLE
|
|
|
|
self._volume_level = 1 # since we can't retrieve remotely
|
|
|
|
self._volume_muted = False # since we can't retrieve remotely
|
|
|
|
self.config = config
|
2015-09-29 19:50:07 +00:00
|
|
|
self.plex_sessions = plex_sessions
|
|
|
|
self.update_devices = update_devices
|
|
|
|
self.update_sessions = update_sessions
|
|
|
|
|
2017-10-07 19:31:01 +00:00
|
|
|
self._clear_media()
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
self.refresh(device, session)
|
|
|
|
|
|
|
|
# Assign custom entity ID if desired
|
|
|
|
if self.config.get(CONF_USE_CUSTOM_ENTITY_IDS):
|
|
|
|
prefix = ''
|
|
|
|
# allow for namespace prefixing when using custom entity names
|
|
|
|
if config.get("entity_namespace"):
|
|
|
|
prefix = config.get("entity_namespace") + '_'
|
|
|
|
|
|
|
|
# rename the entity id
|
|
|
|
if self.machine_identifier:
|
|
|
|
self.entity_id = "%s.%s%s" % (
|
|
|
|
'media_player', prefix,
|
|
|
|
self.machine_identifier.lower().replace('-', '_'))
|
|
|
|
else:
|
|
|
|
if self.name:
|
|
|
|
self.entity_id = "%s.%s%s" % (
|
|
|
|
'media_player', prefix,
|
|
|
|
self.name.lower().replace('-', '_'))
|
|
|
|
|
2017-10-07 19:31:01 +00:00
|
|
|
def _clear_media(self):
|
|
|
|
"""Set all Media Items to None."""
|
|
|
|
# General
|
|
|
|
self._media_content_id = None
|
|
|
|
self._media_content_rating = None
|
|
|
|
self._media_content_type = None
|
|
|
|
self._media_duration = None
|
|
|
|
self._media_image_url = None
|
|
|
|
self._media_title = None
|
|
|
|
self._media_position = None
|
|
|
|
# Music
|
|
|
|
self._media_album_artist = None
|
|
|
|
self._media_album_name = None
|
|
|
|
self._media_artist = None
|
|
|
|
self._media_track = None
|
|
|
|
# TV Show
|
|
|
|
self._media_episode = None
|
|
|
|
self._media_season = None
|
|
|
|
self._media_series_title = None
|
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
def refresh(self, device, session):
|
|
|
|
"""Refresh key device data."""
|
|
|
|
# new data refresh
|
2017-10-07 19:31:01 +00:00
|
|
|
self._clear_media()
|
|
|
|
|
|
|
|
if session: # Not being triggered by Chrome or FireTablet Plex App
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._session = session
|
|
|
|
if device:
|
|
|
|
self._device = device
|
2017-10-25 09:42:13 +00:00
|
|
|
if "127.0.0.1" in self._device.url("/"):
|
|
|
|
self._device.proxyThroughServer()
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._session = None
|
2017-10-25 09:42:13 +00:00
|
|
|
self._machine_identifier = self._device.machineIdentifier
|
|
|
|
self._name = self._device.title or DEVICE_DEFAULT_NAME
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._device_protocol_capabilities = (
|
|
|
|
self._device.protocolCapabilities)
|
|
|
|
|
2017-10-25 09:42:13 +00:00
|
|
|
# set valid session, preferring device session
|
|
|
|
if self.plex_sessions.get(self._device.machineIdentifier, None):
|
|
|
|
self._session = self.plex_sessions.get(
|
|
|
|
self._device.machineIdentifier, None)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
if self._session:
|
2017-10-25 09:42:13 +00:00
|
|
|
if self._device.machineIdentifier is not None and \
|
|
|
|
self._session.players:
|
|
|
|
self._is_player_available = True
|
|
|
|
self._player = [p for p in self._session.players
|
|
|
|
if p.machineIdentifier ==
|
|
|
|
self._device.machineIdentifier][0]
|
|
|
|
self._name = self._player.title
|
|
|
|
self._player_state = self._player.state
|
|
|
|
self._session_username = self._session.usernames[0]
|
|
|
|
self._make = self._player.device
|
|
|
|
else:
|
|
|
|
self._is_player_available = False
|
|
|
|
self._media_position = self._session.viewOffset
|
|
|
|
self._media_content_id = self._session.ratingKey
|
|
|
|
self._media_content_rating = self._session.contentRating
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
if self._player_state == 'playing':
|
|
|
|
self._is_player_active = True
|
|
|
|
self._state = STATE_PLAYING
|
|
|
|
elif self._player_state == 'paused':
|
|
|
|
self._is_player_active = True
|
|
|
|
self._state = STATE_PAUSED
|
|
|
|
elif self.device:
|
|
|
|
self._is_player_active = False
|
|
|
|
self._state = STATE_IDLE
|
|
|
|
else:
|
|
|
|
self._is_player_active = False
|
|
|
|
self._state = STATE_OFF
|
|
|
|
|
|
|
|
if self._is_player_active and self._session is not None:
|
|
|
|
self._session_type = self._session.type
|
2017-10-25 09:42:13 +00:00
|
|
|
self._media_duration = self._session.duration
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
else:
|
|
|
|
self._session_type = None
|
|
|
|
|
|
|
|
# media type
|
|
|
|
if self._session_type == 'clip':
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.debug("Clip content type detected, compatibility may "
|
|
|
|
"vary: %s", self.entity_id)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._media_content_type = MEDIA_TYPE_TVSHOW
|
|
|
|
elif self._session_type == 'episode':
|
|
|
|
self._media_content_type = MEDIA_TYPE_TVSHOW
|
|
|
|
elif self._session_type == 'movie':
|
|
|
|
self._media_content_type = MEDIA_TYPE_VIDEO
|
|
|
|
elif self._session_type == 'track':
|
|
|
|
self._media_content_type = MEDIA_TYPE_MUSIC
|
|
|
|
|
|
|
|
# title (movie name, tv episode name, music song name)
|
2017-10-07 19:31:01 +00:00
|
|
|
if self._session and self._is_player_active:
|
2017-10-25 09:42:13 +00:00
|
|
|
self._media_title = self._session.title
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
# Movies
|
|
|
|
if (self.media_content_type == MEDIA_TYPE_VIDEO and
|
2017-10-25 09:42:13 +00:00
|
|
|
self._session.year is not None):
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._media_title += ' (' + str(self._session.year) + ')'
|
|
|
|
|
|
|
|
# TV Show
|
2017-10-07 19:31:01 +00:00
|
|
|
if self._media_content_type is MEDIA_TYPE_TVSHOW:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# season number (00)
|
2017-10-25 09:42:13 +00:00
|
|
|
if callable(self._session.seasons):
|
|
|
|
self._media_season = self._session.seasons()[0].index.zfill(2)
|
|
|
|
elif self._session.parentIndex is not None:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._media_season = self._session.parentIndex.zfill(2)
|
|
|
|
else:
|
|
|
|
self._media_season = None
|
|
|
|
# show name
|
2017-10-25 09:42:13 +00:00
|
|
|
self._media_series_title = self._session.grandparentTitle
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# episode number (00)
|
2017-10-25 09:42:13 +00:00
|
|
|
if self._session.index is not None:
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._media_episode = str(self._session.index).zfill(2)
|
|
|
|
|
|
|
|
# Music
|
2017-10-07 19:31:01 +00:00
|
|
|
if self._media_content_type == MEDIA_TYPE_MUSIC:
|
2017-10-25 09:42:13 +00:00
|
|
|
self._media_album_name = self._session.parentTitle
|
|
|
|
self._media_album_artist = self._session.grandparentTitle
|
|
|
|
self._media_track = self._session.index
|
|
|
|
self._media_artist = self._session.originalTitle
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# use album artist if track artist is missing
|
|
|
|
if self._media_artist is None:
|
2017-10-07 19:31:01 +00:00
|
|
|
_LOGGER.debug("Using album artist because track artist "
|
|
|
|
"was not found: %s", self.entity_id)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._media_artist = self._media_album_artist
|
|
|
|
|
|
|
|
# set app name to library name
|
|
|
|
if (self._session is not None
|
2017-10-25 09:42:13 +00:00
|
|
|
and self._session.section() is not None):
|
|
|
|
self._app_name = self._session.section().title
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
else:
|
|
|
|
self._app_name = ''
|
|
|
|
|
|
|
|
# media image url
|
|
|
|
if self._session is not None:
|
2017-10-25 09:42:13 +00:00
|
|
|
thumb_url = self._session.thumbUrl
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if (self.media_content_type is MEDIA_TYPE_TVSHOW
|
|
|
|
and not self.config.get(CONF_USE_EPISODE_ART)):
|
2017-10-25 09:42:13 +00:00
|
|
|
thumb_url = self._server.url(
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self._session.grandparentThumb)
|
|
|
|
|
|
|
|
if thumb_url is None:
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.debug("Using media art because media thumb "
|
|
|
|
"was not found: %s", self.entity_id)
|
2017-10-25 09:42:13 +00:00
|
|
|
thumb_url = self._server.url(self._session.art)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
self._media_image_url = thumb_url
|
|
|
|
|
|
|
|
def force_idle(self):
|
|
|
|
"""Force client to idle."""
|
|
|
|
self._state = STATE_IDLE
|
|
|
|
self._session = None
|
2017-10-07 19:31:01 +00:00
|
|
|
self._clear_media()
|
2015-09-29 19:50:07 +00:00
|
|
|
|
2015-10-25 10:45:15 +00:00
|
|
|
@property
|
|
|
|
def unique_id(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Return the id of this plex client."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return '{}.{}'.format(self.__class__, self.machine_identifier or
|
|
|
|
self.name)
|
2015-10-25 10:45:15 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Return the name of the device."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def machine_identifier(self):
|
|
|
|
"""Return the machine identifier of the device."""
|
|
|
|
return self._machine_identifier
|
|
|
|
|
|
|
|
@property
|
|
|
|
def app_name(self):
|
|
|
|
"""Return the library name of playing media."""
|
|
|
|
return self._app_name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device(self):
|
|
|
|
"""Return the device, if any."""
|
|
|
|
return self._device
|
2015-10-25 10:45:15 +00:00
|
|
|
|
2015-09-29 19:50:07 +00:00
|
|
|
@property
|
|
|
|
def session(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Return the session, if any."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._session
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Return the state of the device."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._state
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
def update(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Get the latest details."""
|
2015-09-29 19:50:07 +00:00
|
|
|
self.update_devices(no_throttle=True)
|
|
|
|
self.update_sessions(no_throttle=True)
|
2015-09-19 17:48:45 +00:00
|
|
|
|
2016-08-08 15:55:58 +00:00
|
|
|
@property
|
|
|
|
def _active_media_plexapi_type(self):
|
|
|
|
"""Get the active media type required by PlexAPI commands."""
|
|
|
|
if self.media_content_type is MEDIA_TYPE_MUSIC:
|
|
|
|
return 'music'
|
2017-07-06 06:30:01 +00:00
|
|
|
|
|
|
|
return 'video'
|
2016-08-08 15:55:58 +00:00
|
|
|
|
2015-09-19 17:48:45 +00:00
|
|
|
@property
|
|
|
|
def media_content_id(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the content ID of current playing media."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_content_id
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_content_type(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the content type of current playing media."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if self._session_type == 'clip':
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.debug("Clip content type detected, "
|
|
|
|
"compatibility may vary: %s", self.entity_id)
|
2015-09-21 14:44:24 +00:00
|
|
|
return MEDIA_TYPE_TVSHOW
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
elif self._session_type == 'episode':
|
|
|
|
return MEDIA_TYPE_TVSHOW
|
|
|
|
elif self._session_type == 'movie':
|
2015-09-21 14:44:24 +00:00
|
|
|
return MEDIA_TYPE_VIDEO
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
elif self._session_type == 'track':
|
2016-08-08 15:55:58 +00:00
|
|
|
return MEDIA_TYPE_MUSIC
|
2017-07-06 06:30:01 +00:00
|
|
|
|
|
|
|
return None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_artist(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the artist of current playing media, music track only."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_artist
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_album_name(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the album name of current playing media, music track only."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_album_name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_album_artist(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the album artist of current playing media, music only."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_album_artist
|
|
|
|
|
|
|
|
@property
|
|
|
|
def media_track(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the track number of current playing media, music only."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_track
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_duration(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the duration of current playing media in seconds."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_duration
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_image_url(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the image URL of current playing media."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_image_url
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_title(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the title of current playing media."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_title
|
2015-09-20 20:13:26 +00:00
|
|
|
|
2015-09-19 17:48:45 +00:00
|
|
|
@property
|
|
|
|
def media_season(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the season of current playing media (TV Show only)."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_season
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_series_title(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the title of the series of current playing media."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_series_title
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def media_episode(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the episode of current playing media (TV Show only)."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._media_episode
|
|
|
|
|
|
|
|
@property
|
|
|
|
def make(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Return the make of the device (ex. SHIELD Android TV)."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return self._make
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
@property
|
2017-02-08 04:42:45 +00:00
|
|
|
def supported_features(self):
|
|
|
|
"""Flag media player features that are supported."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if not self._is_player_active:
|
2017-03-17 00:46:47 +00:00
|
|
|
return None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
# force show all controls
|
|
|
|
if self.config.get(CONF_SHOW_ALL_CONTROLS):
|
2017-03-17 00:46:47 +00:00
|
|
|
return (SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK |
|
|
|
|
SUPPORT_NEXT_TRACK | SUPPORT_STOP |
|
|
|
|
SUPPORT_VOLUME_SET | SUPPORT_PLAY |
|
|
|
|
SUPPORT_TURN_OFF | SUPPORT_VOLUME_MUTE)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
|
|
|
# only show controls when we know what device is connecting
|
|
|
|
if not self._make:
|
2017-03-17 00:46:47 +00:00
|
|
|
return None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# no mute support
|
|
|
|
elif self.make.lower() == "shield android tv":
|
|
|
|
_LOGGER.debug(
|
2017-04-24 03:41:09 +00:00
|
|
|
"Shield Android TV client detected, disabling mute "
|
|
|
|
"controls: %s", self.entity_id)
|
2017-03-17 00:46:47 +00:00
|
|
|
return (SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK |
|
|
|
|
SUPPORT_NEXT_TRACK | SUPPORT_STOP |
|
|
|
|
SUPPORT_VOLUME_SET | SUPPORT_PLAY |
|
|
|
|
SUPPORT_TURN_OFF)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# Only supports play,pause,stop (and off which really is stop)
|
|
|
|
elif self.make.lower().startswith("tivo"):
|
|
|
|
_LOGGER.debug(
|
2017-04-24 03:41:09 +00:00
|
|
|
"Tivo client detected, only enabling pause, play, "
|
|
|
|
"stop, and off controls: %s", self.entity_id)
|
2017-03-17 00:46:47 +00:00
|
|
|
return (SUPPORT_PAUSE | SUPPORT_PLAY | SUPPORT_STOP |
|
|
|
|
SUPPORT_TURN_OFF)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
# Not all devices support playback functionality
|
|
|
|
# Playback includes volume, stop/play/pause, etc.
|
|
|
|
elif self.device and 'playback' in self._device_protocol_capabilities:
|
2017-03-17 00:46:47 +00:00
|
|
|
return (SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK |
|
|
|
|
SUPPORT_NEXT_TRACK | SUPPORT_STOP |
|
|
|
|
SUPPORT_VOLUME_SET | SUPPORT_PLAY |
|
|
|
|
SUPPORT_TURN_OFF | SUPPORT_VOLUME_MUTE)
|
2017-07-06 06:30:01 +00:00
|
|
|
|
|
|
|
return None
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2016-08-08 15:55:58 +00:00
|
|
|
def set_volume_level(self, volume):
|
|
|
|
"""Set volume level, range 0..1."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if self.device and 'playback' in self._device_protocol_capabilities:
|
|
|
|
self.device.setVolume(
|
|
|
|
int(volume * 100), self._active_media_plexapi_type)
|
|
|
|
self._volume_level = volume # store since we can't retrieve
|
|
|
|
|
|
|
|
@property
|
|
|
|
def volume_level(self):
|
|
|
|
"""Return the volume level of the client (0..1)."""
|
|
|
|
if (self._is_player_active and self.device and
|
|
|
|
'playback' in self._device_protocol_capabilities):
|
|
|
|
return self._volume_level
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_volume_muted(self):
|
|
|
|
"""Return boolean if volume is currently muted."""
|
|
|
|
if self._is_player_active and self.device:
|
|
|
|
return self._volume_muted
|
|
|
|
|
|
|
|
def mute_volume(self, mute):
|
|
|
|
"""Mute the volume.
|
|
|
|
|
|
|
|
Since we can't actually mute, we'll:
|
|
|
|
- On mute, store volume and set volume to 0
|
|
|
|
- On unmute, set volume to previously stored volume
|
|
|
|
"""
|
|
|
|
if not (self.device and
|
|
|
|
'playback' in self._device_protocol_capabilities):
|
|
|
|
return
|
|
|
|
|
|
|
|
self._volume_muted = mute
|
|
|
|
if mute:
|
|
|
|
self._previous_volume_level = self._volume_level
|
|
|
|
self.set_volume_level(0)
|
|
|
|
else:
|
|
|
|
self.set_volume_level(self._previous_volume_level)
|
2016-08-08 15:55:58 +00:00
|
|
|
|
2015-09-19 17:48:45 +00:00
|
|
|
def media_play(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Send play command."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if self.device and 'playback' in self._device_protocol_capabilities:
|
|
|
|
self.device.play(self._active_media_plexapi_type)
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
def media_pause(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Send pause command."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if self.device and 'playback' in self._device_protocol_capabilities:
|
|
|
|
self.device.pause(self._active_media_plexapi_type)
|
2016-08-08 15:55:58 +00:00
|
|
|
|
|
|
|
def media_stop(self):
|
|
|
|
"""Send stop command."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if self.device and 'playback' in self._device_protocol_capabilities:
|
|
|
|
self.device.stop(self._active_media_plexapi_type)
|
|
|
|
|
|
|
|
def turn_off(self):
|
|
|
|
"""Turn the client off."""
|
|
|
|
# Fake it since we can't turn the client off
|
|
|
|
self.media_stop()
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
def media_next_track(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Send next track command."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if self.device and 'playback' in self._device_protocol_capabilities:
|
|
|
|
self.device.skipNext(self._active_media_plexapi_type)
|
2015-09-19 17:48:45 +00:00
|
|
|
|
|
|
|
def media_previous_track(self):
|
2016-03-08 09:34:33 +00:00
|
|
|
"""Send previous track command."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if self.device and 'playback' in self._device_protocol_capabilities:
|
|
|
|
self.device.skipPrevious(self._active_media_plexapi_type)
|
|
|
|
|
|
|
|
# pylint: disable=W0613
|
|
|
|
def play_media(self, media_type, media_id, **kwargs):
|
|
|
|
"""Play a piece of media."""
|
|
|
|
if not (self.device and
|
|
|
|
'playback' in self._device_protocol_capabilities):
|
|
|
|
return
|
|
|
|
|
|
|
|
src = json.loads(media_id)
|
|
|
|
|
|
|
|
media = None
|
|
|
|
if media_type == 'MUSIC':
|
|
|
|
media = self.device.server.library.section(
|
|
|
|
src['library_name']).get(src['artist_name']).album(
|
|
|
|
src['album_name']).get(src['track_name'])
|
|
|
|
elif media_type == 'EPISODE':
|
2017-04-01 02:19:04 +00:00
|
|
|
media = self._get_tv_media(
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
src['library_name'], src['show_name'],
|
|
|
|
src['season_number'], src['episode_number'])
|
|
|
|
elif media_type == 'PLAYLIST':
|
|
|
|
media = self.device.server.playlist(src['playlist_name'])
|
|
|
|
elif media_type == 'VIDEO':
|
|
|
|
media = self.device.server.library.section(
|
|
|
|
src['library_name']).get(src['video_name'])
|
|
|
|
|
2017-04-05 02:33:52 +00:00
|
|
|
import plexapi.playlist
|
|
|
|
if (media and media_type == 'EPISODE' and
|
|
|
|
isinstance(media, plexapi.playlist.Playlist)):
|
|
|
|
# delete episode playlist after being loaded into a play queue
|
2017-04-01 02:19:04 +00:00
|
|
|
self._client_play_media(media=media, delete=True,
|
|
|
|
shuffle=src['shuffle'])
|
|
|
|
elif media:
|
|
|
|
self._client_play_media(media=media, shuffle=src['shuffle'])
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
|
2017-04-01 02:19:04 +00:00
|
|
|
def _get_tv_media(self, library_name, show_name, season_number,
|
|
|
|
episode_number):
|
|
|
|
"""Find TV media and return a Plex media object."""
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
target_season = None
|
|
|
|
target_episode = None
|
|
|
|
|
2017-04-01 02:19:04 +00:00
|
|
|
show = self.device.server.library.section(library_name).get(
|
|
|
|
show_name)
|
|
|
|
|
|
|
|
if not season_number:
|
2017-04-05 02:33:52 +00:00
|
|
|
playlist_name = "{} - {} Episodes".format(
|
|
|
|
self.entity_id, show_name)
|
2017-04-01 02:19:04 +00:00
|
|
|
return self.device.server.createPlaylist(
|
|
|
|
playlist_name, show.episodes())
|
|
|
|
|
|
|
|
for season in show.seasons():
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
if int(season.seasonNumber) == int(season_number):
|
|
|
|
target_season = season
|
|
|
|
break
|
|
|
|
|
|
|
|
if target_season is None:
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.error("Season not found: %s\\%s - S%sE%s", library_name,
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
show_name,
|
|
|
|
str(season_number).zfill(2),
|
|
|
|
str(episode_number).zfill(2))
|
|
|
|
else:
|
2017-04-01 02:19:04 +00:00
|
|
|
if not episode_number:
|
2017-04-05 02:33:52 +00:00
|
|
|
playlist_name = "{} - {} Season {} Episodes".format(
|
|
|
|
self.entity_id, show_name, str(season_number))
|
2017-04-01 02:19:04 +00:00
|
|
|
return self.device.server.createPlaylist(
|
|
|
|
playlist_name, target_season.episodes())
|
|
|
|
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
for episode in target_season.episodes():
|
|
|
|
if int(episode.index) == int(episode_number):
|
|
|
|
target_episode = episode
|
|
|
|
break
|
|
|
|
|
|
|
|
if target_episode is None:
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.error("Episode not found: %s\\%s - S%sE%s",
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
library_name, show_name,
|
|
|
|
str(season_number).zfill(2),
|
|
|
|
str(episode_number).zfill(2))
|
|
|
|
|
|
|
|
return target_episode
|
|
|
|
|
2017-04-01 02:19:04 +00:00
|
|
|
def _client_play_media(self, media, delete=False, **params):
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
"""Instruct Plex client to play a piece of media."""
|
|
|
|
if not (self.device and
|
|
|
|
'playback' in self._device_protocol_capabilities):
|
2017-04-24 03:41:09 +00:00
|
|
|
_LOGGER.error("Client cannot play media: %s", self.entity_id)
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
import plexapi.playqueue
|
2017-04-24 03:41:09 +00:00
|
|
|
playqueue = plexapi.playqueue.PlayQueue.create(
|
|
|
|
self.device.server, media, **params)
|
2017-04-01 02:19:04 +00:00
|
|
|
|
2017-04-24 03:41:09 +00:00
|
|
|
# Delete dynamic playlists used to build playqueue (ex. play tv season)
|
2017-04-05 02:33:52 +00:00
|
|
|
if delete:
|
|
|
|
media.delete()
|
|
|
|
|
2017-04-01 02:19:04 +00:00
|
|
|
server_url = self.device.server.baseurl.split(':')
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
self.device.sendCommand('playback/playMedia', **dict({
|
2017-04-24 03:41:09 +00:00
|
|
|
'machineIdentifier': self.device.server.machineIdentifier,
|
|
|
|
'address': server_url[1].strip('/'),
|
|
|
|
'port': server_url[-1],
|
|
|
|
'key': media.key,
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
'containerKey':
|
2017-04-24 03:41:09 +00:00
|
|
|
'/playQueues/{}?window=100&own=1'.format(
|
|
|
|
playqueue.playQueueID),
|
Support for non-clients, NVidia shield, dynamic grouping, extra metad… (#6054)
* Support for non-clients, NVidia shield, dynamic grouping, extra metadata, and more
* Fixed import orderdering, line lengths, and comment violations
* Local player check and season fixes
* Honor entity_namespace when using custom entity ids
* Semi compatibility with channels, force controls option added
* media_position_updated_at fix - only update when media is playing
* Fix: controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever
* Made PEP8 compliant
* Made PEP8 compliant
* Made PEP8 compliant, hopefully
* Better Tivo compatibility
* Added frozen detection and remediation
* PlayMedia EPISODE now supports season number and episode number (instead of episode index)
* Fix: Dynamic groups now exclude hidden devices
* Fix: Dynamic groups now exclude hidden devices
* Implemented arsaboo suggested formatting
* Implemented pylint command line suggested fixes
* Implemented Travis CI build suggested fixes
* Sorted Imports using Importanize
* Grouped request imports
* Removed dynamic groups, network calls from properties, and other cleanup
* Balloob recommendations and Plex Protocol Capabilities checks
* Remove deprecated disable-msg in favor of disable
* Removed position related items (seek, frozen detection, etc)
* Removed unused datetime
2017-03-16 16:09:46 +00:00
|
|
|
}, **params))
|
2017-04-01 02:19:04 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def device_state_attributes(self):
|
|
|
|
"""Return the scene state attributes."""
|
|
|
|
attr = {}
|
|
|
|
attr['media_content_rating'] = self._media_content_rating
|
|
|
|
attr['session_username'] = self._session_username
|
|
|
|
attr['media_library_name'] = self._app_name
|
|
|
|
|
|
|
|
return attr
|