Skip to content

Commit

Permalink
add on_deck
Browse files Browse the repository at this point in the history
  • Loading branch information
maykar committed Jun 17, 2020
1 parent 85b39b2 commit 2d0b00b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Read through these two resources before posting issues to GitHub or the forums.
| port | 32400 | yes | The port Plex is running on.
| ssl | false | no | Set to true if you use SSL to access Plex.
| max | 5 | no | Max number of items to show in sensor.
| on_deck | False | no | Set to true to show "on deck" items.
| download_images | true | no | Setting this to false will turn off downloading of images, but will require certain Plex settings to work. See below.
| img_dir | '/upcoming-media-card-images/plex/' | no | This option allows you to choose a custom directory to store images in if you enable download_images. Directory must start and end with a `/`.
| ssl_cert | false | no | If you provide your own SSL certificate in Plex's network settings set this to true.
Expand Down
8 changes: 7 additions & 1 deletion custom_components/plex_recently_added/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async def request(url, self, content=False, ssl=False):
CONF_IMG_CACHE = 'img_dir'
CONF_SECTION_TYPES = 'section_types'
CONF_RESOLUTION = 'image_resolution'
CONF_ON_DECK = 'on_deck'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
Expand All @@ -58,6 +59,7 @@ async def request(url, self, content=False, ssl=False):
vol.Optional(CONF_MAX, default=5): cv.string,
vol.Optional(CONF_SERVER): cv.string,
vol.Optional(CONF_DL_IMAGES, default=True): cv.boolean,
vol.Optional(CONF_ON_DECK, default=False): cv.boolean,
vol.Optional(CONF_HOST, default='localhost'): cv.string,
vol.Optional(CONF_PORT, default=32400): cv.port,
vol.Optional(CONF_SECTION_TYPES,
Expand Down Expand Up @@ -92,6 +94,7 @@ def __init__(self, hass, conf, name):
self.server_name = conf.get(CONF_SERVER)
self.max_items = int(conf.get(CONF_MAX))
self.dl_images = conf.get(CONF_DL_IMAGES)
self.on_deck = conf.get(CONF_ON_DECK)
self.sections = conf.get(CONF_SECTION_TYPES)
self.resolution = conf.get(CONF_RESOLUTION)
if self.server_name:
Expand Down Expand Up @@ -224,6 +227,8 @@ async def async_update(self):
all_libraries = url_base + '/all'
recently_added = (url_base + '/{0}/recentlyAdded?X-Plex-Container-'
'Start=0&X-Plex-Container-Size={1}')
on_deck = (url_base + '/{0}/onDeck?X-Plex-Container-'
'Start=0&X-Plex-Container-Size={1}')

"""Find the ID of all libraries in Plex."""
sections = []
Expand All @@ -241,7 +246,8 @@ async def async_update(self):
self._state = 'Online'
"""Get JSON for each library, combine and sort."""
for library in sections:
sub_sec = await request(recently_added.format(
recent_or_deck = on_deck if self.on_deck else recently_added
sub_sec = await request(recent_or_deck.format(
library, self.max_items * 2), self)
sub_sec = json.loads(sub_sec)
try:
Expand Down

0 comments on commit 2d0b00b

Please sign in to comment.