Skip to content

WIP Plex purge unavailable clients#12823

Closed
ryanm101 wants to merge 7 commits intohome-assistant:devfrom
ryanm101:plex_purge
Closed

WIP Plex purge unavailable clients#12823
ryanm101 wants to merge 7 commits intohome-assistant:devfrom
ryanm101:plex_purge

Conversation

@ryanm101
Copy link
Copy Markdown
Contributor

@ryanm101 ryanm101 commented Mar 1, 2018

Fully Fixes: #10074

Adds two new cfg options:
CONF_PURGE_UNAVAILABLE_CLIENTS = 'purge_unavailable_clients' (bool default TRUE)
CONF_CLIENT_PURGE_INTERVAL = 'client_purge_interval' (INT default 0)

These options need to be added to docs

This keeps previous expected behaviour of removing unavailable clients immediately but allows users that to fine tune that behaviour and can also be disabled if required.

supersedes: #12811


@property
def unavailable_time(self):
"""Returns the timedelta showing how long client has been unavailable"""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

self._media_image_url = thumb_url

def set_availability(self, available):
"""Sets the device as available/unavailable and notes the time it was set unavailable"""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (96 > 79 characters)

print("************************Adding")
add_devices_callback(new_plex_clients)

# Figure out if device is unavailable and if it should be removed or not
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

cv.boolean,
vol.Optional(CONF_PURGE_UNAVAILABLE_CLIENTS, default=True):
cv.boolean,
vol.Optional(CONF_CLIENT_PURGE_INTERVAL, default=0):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use cv.time_period. That will return in a timedelta. Then use value.total_seconds() to get back to seconds.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and use vol.All(cv.time_period, cv.positive_timedelta)) to make sure it's a positive duration.

if config.get(CONF_PURGE_UNAVAILABLE_CLIENTS)\
and cclient.unavailable_time is not None \
and cclient.marked_for_purge is not True \
and cclient.unavailable_time.seconds > config_purge_int:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If unavailable_time is a timedelta, use total_seconds()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, but what is the benefit of doing it that way? or is it purely stylistic to keep with the project norms?

CONF_USE_CUSTOM_ENTITY_IDS = 'use_custom_entity_ids'
CONF_SHOW_ALL_CONTROLS = 'show_all_controls'
CONF_PURGE_UNAVAILABLE_CLIENTS = 'purge_unavailable_clients'
CONF_CLIENT_PURGE_INTERVAL = 'client_purge_interval'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Do we call them "clients" anywhere else? I think "player" is a better term. Client is code, player is user-facing. :) But if there's already precedent here then just do what's consistent.
  2. I would remove the word purge here. Purge sounds like a retroactive destruction, removing all history of a thing. I suggest a softer word like "remove"

@ryanm101 ryanm101 changed the title Plex purge unavailable clients WIP Plex purge unavailable clients Mar 2, 2018
@ryanm101 ryanm101 closed this Mar 12, 2018
@ryanm101 ryanm101 deleted the plex_purge branch March 25, 2018 19:51
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants