diff --git a/homeassistant/components/media_player/plex.py b/homeassistant/components/media_player/plex.py index a63bf8525edb9632646918e3732be01d2ea55fc1..caa81424377cf4812da102cc23c2cbda9886c0d7 100644 --- a/homeassistant/components/media_player/plex.py +++ b/homeassistant/components/media_player/plex.py @@ -154,11 +154,14 @@ def setup_plexserver( return new_plex_clients = [] + available_client_ids = [] for device in devices: # For now, let's allow all deviceClass types if device.deviceClass in ['badClient']: continue + available_client_ids.append(device.machineIdentifier) + if device.machineIdentifier not in plex_clients: new_client = PlexClient(config, device, None, plex_sessions, update_devices, @@ -186,6 +189,9 @@ def setup_plexserver( if client.session is None: client.force_idle() + client.set_availability(client.machine_identifier + in available_client_ids) + if new_plex_clients: add_devices_callback(new_plex_clients) @@ -259,6 +265,7 @@ class PlexClient(MediaPlayerDevice): """Initialize the Plex device.""" self._app_name = '' self._device = None + self._available = False self._device_protocol_capabilities = None self._is_player_active = False self._is_player_available = False @@ -407,6 +414,12 @@ class PlexClient(MediaPlayerDevice): self._media_image_url = thumb_url + def set_availability(self, available): + """Set the device as available/unavailable noting time.""" + if not available: + self._clear_media_details() + self._available = available + def _set_player_state(self): if self._player_state == 'playing': self._is_player_active = True @@ -468,6 +481,11 @@ class PlexClient(MediaPlayerDevice): """Return the id of this plex client.""" return self.machine_identifier + @property + def available(self): + """Return the availability of the client.""" + return self._available + @property def name(self): """Return the name of the device."""