mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Plex mark devices unavailable if they 'vanish' and clear media (#12811)
* Marks Devices unavailable if they 'vanish' and clears media * Fixed PEP8 complaint * Fixed Linting * Lint Fix * Fix redine of id * More lint fixes * Removed redundant loop for setting availability of client Renamed '_is_device_available' to '_available' Renamed 'available_ids' to 'available_client_ids' * removed whitespace per houndCI
This commit is contained in:
parent
ca5f470956
commit
ecaf0189cc
@ -154,11 +154,14 @@ def setup_plexserver(
|
|||||||
return
|
return
|
||||||
|
|
||||||
new_plex_clients = []
|
new_plex_clients = []
|
||||||
|
available_client_ids = []
|
||||||
for device in devices:
|
for device in devices:
|
||||||
# For now, let's allow all deviceClass types
|
# For now, let's allow all deviceClass types
|
||||||
if device.deviceClass in ['badClient']:
|
if device.deviceClass in ['badClient']:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
available_client_ids.append(device.machineIdentifier)
|
||||||
|
|
||||||
if device.machineIdentifier not in plex_clients:
|
if device.machineIdentifier not in plex_clients:
|
||||||
new_client = PlexClient(config, device, None,
|
new_client = PlexClient(config, device, None,
|
||||||
plex_sessions, update_devices,
|
plex_sessions, update_devices,
|
||||||
@ -186,6 +189,9 @@ def setup_plexserver(
|
|||||||
if client.session is None:
|
if client.session is None:
|
||||||
client.force_idle()
|
client.force_idle()
|
||||||
|
|
||||||
|
client.set_availability(client.machine_identifier
|
||||||
|
in available_client_ids)
|
||||||
|
|
||||||
if new_plex_clients:
|
if new_plex_clients:
|
||||||
add_devices_callback(new_plex_clients)
|
add_devices_callback(new_plex_clients)
|
||||||
|
|
||||||
@ -259,6 +265,7 @@ class PlexClient(MediaPlayerDevice):
|
|||||||
"""Initialize the Plex device."""
|
"""Initialize the Plex device."""
|
||||||
self._app_name = ''
|
self._app_name = ''
|
||||||
self._device = None
|
self._device = None
|
||||||
|
self._available = False
|
||||||
self._device_protocol_capabilities = None
|
self._device_protocol_capabilities = None
|
||||||
self._is_player_active = False
|
self._is_player_active = False
|
||||||
self._is_player_available = False
|
self._is_player_available = False
|
||||||
@ -407,6 +414,12 @@ class PlexClient(MediaPlayerDevice):
|
|||||||
|
|
||||||
self._media_image_url = thumb_url
|
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):
|
def _set_player_state(self):
|
||||||
if self._player_state == 'playing':
|
if self._player_state == 'playing':
|
||||||
self._is_player_active = True
|
self._is_player_active = True
|
||||||
@ -468,6 +481,11 @@ class PlexClient(MediaPlayerDevice):
|
|||||||
"""Return the id of this plex client."""
|
"""Return the id of this plex client."""
|
||||||
return self.machine_identifier
|
return self.machine_identifier
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self):
|
||||||
|
"""Return the availability of the client."""
|
||||||
|
return self._available
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user