Use shorthand attributes in Plex (#99769)

Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Joost Lekkerkerker 2023-09-07 13:55:16 +02:00 committed by GitHub
parent 8a4cd913b8
commit 40a3d97230
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 15 deletions

View file

@ -38,17 +38,13 @@ class PlexScanClientsButton(ButtonEntity):
self.server_id = server_id self.server_id = server_id
self._attr_name = f"Scan Clients ({server_name})" self._attr_name = f"Scan Clients ({server_name})"
self._attr_unique_id = f"plex-scan_clients-{self.server_id}" self._attr_unique_id = f"plex-scan_clients-{self.server_id}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, server_id)},
manufacturer="Plex",
)
async def async_press(self) -> None: async def async_press(self) -> None:
"""Press the button.""" """Press the button."""
async_dispatcher_send( async_dispatcher_send(
self.hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(self.server_id) self.hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(self.server_id)
) )
@property
def device_info(self) -> DeviceInfo:
"""Return a device description for device registry."""
return DeviceInfo(
identifiers={(DOMAIN, self.server_id)},
manufacturer="Plex",
)

View file

@ -117,6 +117,10 @@ def _async_add_entities(hass, registry, async_add_entities, server_id, new_entit
class PlexMediaPlayer(MediaPlayerEntity): class PlexMediaPlayer(MediaPlayerEntity):
"""Representation of a Plex device.""" """Representation of a Plex device."""
_attr_available = False
_attr_should_poll = False
_attr_state = MediaPlayerState.IDLE
def __init__(self, plex_server, device, player_source, session=None): def __init__(self, plex_server, device, player_source, session=None):
"""Initialize the Plex device.""" """Initialize the Plex device."""
self.plex_server = plex_server self.plex_server = plex_server
@ -136,9 +140,6 @@ class PlexMediaPlayer(MediaPlayerEntity):
self._volume_level = 1 # since we can't retrieve remotely self._volume_level = 1 # since we can't retrieve remotely
self._volume_muted = False # since we can't retrieve remotely self._volume_muted = False # since we can't retrieve remotely
self._attr_available = False
self._attr_should_poll = False
self._attr_state = MediaPlayerState.IDLE
self._attr_unique_id = ( self._attr_unique_id = (
f"{self.plex_server.machine_identifier}:{self.machine_identifier}" f"{self.plex_server.machine_identifier}:{self.machine_identifier}"
) )

View file

@ -129,6 +129,11 @@ class PlexSensor(SensorEntity):
class PlexLibrarySectionSensor(SensorEntity): class PlexLibrarySectionSensor(SensorEntity):
"""Representation of a Plex library section sensor.""" """Representation of a Plex library section sensor."""
_attr_available = True
_attr_entity_registry_enabled_default = False
_attr_should_poll = False
_attr_native_unit_of_measurement = "Items"
def __init__(self, hass, plex_server, plex_library_section): def __init__(self, hass, plex_server, plex_library_section):
"""Initialize the sensor.""" """Initialize the sensor."""
self._server = plex_server self._server = plex_server
@ -137,14 +142,10 @@ class PlexLibrarySectionSensor(SensorEntity):
self.library_section = plex_library_section self.library_section = plex_library_section
self.library_type = plex_library_section.type self.library_type = plex_library_section.type
self._attr_available = True
self._attr_entity_registry_enabled_default = False
self._attr_extra_state_attributes = {} self._attr_extra_state_attributes = {}
self._attr_icon = LIBRARY_ICON_LOOKUP.get(self.library_type, "mdi:plex") self._attr_icon = LIBRARY_ICON_LOOKUP.get(self.library_type, "mdi:plex")
self._attr_name = f"{self.server_name} Library - {plex_library_section.title}" self._attr_name = f"{self.server_name} Library - {plex_library_section.title}"
self._attr_should_poll = False
self._attr_unique_id = f"library-{self.server_id}-{plex_library_section.uuid}" self._attr_unique_id = f"library-{self.server_id}-{plex_library_section.uuid}"
self._attr_native_unit_of_measurement = "Items"
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Run when about to be added to hass.""" """Run when about to be added to hass."""