Add latest added media as Plex library sensor attribute (#56235)
This commit is contained in:
parent
a967a1d1df
commit
2ff1fc83bc
12 changed files with 779 additions and 4 deletions
|
@ -16,6 +16,7 @@ from .const import (
|
|||
PLEX_UPDATE_SENSOR_SIGNAL,
|
||||
SERVERS,
|
||||
)
|
||||
from .helpers import pretty_title
|
||||
|
||||
LIBRARY_ATTRIBUTE_TYPES = {
|
||||
"artist": ["artist", "album"],
|
||||
|
@ -28,6 +29,11 @@ LIBRARY_PRIMARY_LIBTYPE = {
|
|||
"artist": "track",
|
||||
}
|
||||
|
||||
LIBRARY_RECENT_LIBTYPE = {
|
||||
"show": "episode",
|
||||
"artist": "album",
|
||||
}
|
||||
|
||||
LIBRARY_ICON_LOOKUP = {
|
||||
"artist": "mdi:music",
|
||||
"movie": "mdi:movie",
|
||||
|
@ -174,6 +180,17 @@ class PlexLibrarySectionSensor(SensorEntity):
|
|||
libtype=libtype, includeCollections=False
|
||||
)
|
||||
|
||||
recent_libtype = LIBRARY_RECENT_LIBTYPE.get(
|
||||
self.library_type, self.library_type
|
||||
)
|
||||
recently_added = self.library_section.recentlyAdded(
|
||||
maxresults=1, libtype=recent_libtype
|
||||
)
|
||||
if recently_added:
|
||||
media = recently_added[0]
|
||||
self._attr_extra_state_attributes["last_added_item"] = pretty_title(media)
|
||||
self._attr_extra_state_attributes["last_added_timestamp"] = media.addedAt
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return a device description for device registry."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue