Add album id sensor that has primary share link url attribute
This commit is contained in:
@@ -63,6 +63,7 @@ async def async_setup_entry(
|
||||
coordinator = subentry_data.coordinator
|
||||
|
||||
entities: list[SensorEntity] = [
|
||||
ImmichAlbumIdSensor(coordinator, entry, subentry),
|
||||
ImmichAlbumAssetCountSensor(coordinator, entry, subentry),
|
||||
ImmichAlbumPhotoCountSensor(coordinator, entry, subentry),
|
||||
ImmichAlbumVideoCountSensor(coordinator, entry, subentry),
|
||||
@@ -160,6 +161,45 @@ class ImmichAlbumBaseSensor(CoordinatorEntity[ImmichAlbumWatcherCoordinator], Se
|
||||
return {"assets": assets}
|
||||
|
||||
|
||||
class ImmichAlbumIdSensor(ImmichAlbumBaseSensor):
|
||||
"""Sensor exposing the Immich album ID."""
|
||||
|
||||
_attr_icon = "mdi:identifier"
|
||||
_attr_translation_key = "album_id"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: ImmichAlbumWatcherCoordinator,
|
||||
entry: ConfigEntry,
|
||||
subentry: ConfigSubentry,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator, entry, subentry)
|
||||
self._attr_unique_id = f"{self._unique_id_prefix}_album_id"
|
||||
|
||||
@property
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the album ID."""
|
||||
if self._album_data:
|
||||
return self._album_data.id
|
||||
return None
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return extra state attributes."""
|
||||
if not self._album_data:
|
||||
return {}
|
||||
|
||||
attrs: dict[str, Any] = {}
|
||||
|
||||
# Primary share URL (prefers public, falls back to protected)
|
||||
share_url = self.coordinator.get_any_url()
|
||||
if share_url:
|
||||
attrs["share_url"] = share_url
|
||||
|
||||
return attrs
|
||||
|
||||
|
||||
class ImmichAlbumAssetCountSensor(ImmichAlbumBaseSensor):
|
||||
"""Sensor representing an Immich album asset count."""
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"album_id": {
|
||||
"name": "{album_name}: Album ID"
|
||||
},
|
||||
"album_asset_count": {
|
||||
"name": "{album_name}: Asset Count"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user