mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
Clean up Google Photos media source (#124977)
* Clean up Google Photos media source * Fix typo --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
3e60d7aa11
commit
81f5068354
@ -3,7 +3,7 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, cast
|
from typing import Any, Self, cast
|
||||||
|
|
||||||
from homeassistant.components.media_player import MediaClass, MediaType
|
from homeassistant.components.media_player import MediaClass, MediaType
|
||||||
from homeassistant.components.media_source import (
|
from homeassistant.components.media_source import (
|
||||||
@ -77,37 +77,31 @@ class PhotosIdentifier:
|
|||||||
"""Identifies the album or photo contents to show."""
|
"""Identifies the album or photo contents to show."""
|
||||||
|
|
||||||
def as_string(self) -> str:
|
def as_string(self) -> str:
|
||||||
"""Serialize the identiifer as a string.
|
"""Serialize the identifier as a string."""
|
||||||
|
|
||||||
This is the opposite if of().
|
|
||||||
"""
|
|
||||||
if self.id_type is None:
|
if self.id_type is None:
|
||||||
return self.config_entry_id
|
return self.config_entry_id
|
||||||
return f"{self.config_entry_id}/{self.id_type}/{self.media_id}"
|
return f"{self.config_entry_id}/{self.id_type}/{self.media_id}"
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def of(identifier: str) -> "PhotosIdentifier":
|
def of(cls, identifier: str) -> Self:
|
||||||
"""Parse a PhotosIdentifier form a string.
|
"""Parse a PhotosIdentifier form a string."""
|
||||||
|
|
||||||
This is the opposite of as_string().
|
|
||||||
"""
|
|
||||||
parts = identifier.split("/")
|
parts = identifier.split("/")
|
||||||
_LOGGER.debug("parts=%s", parts)
|
_LOGGER.debug("parts=%s", parts)
|
||||||
if len(parts) == 1:
|
if len(parts) == 1:
|
||||||
return PhotosIdentifier(parts[0])
|
return cls(parts[0])
|
||||||
if len(parts) != 3:
|
if len(parts) != 3:
|
||||||
raise BrowseError(f"Invalid identifier: {identifier}")
|
raise BrowseError(f"Invalid identifier: {identifier}")
|
||||||
return PhotosIdentifier(parts[0], PhotosIdentifierType.of(parts[1]), parts[2])
|
return cls(parts[0], PhotosIdentifierType.of(parts[1]), parts[2])
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def album(config_entry_id: str, media_id: str) -> "PhotosIdentifier":
|
def album(cls, config_entry_id: str, media_id: str) -> Self:
|
||||||
"""Create an album PhotosIdentifier."""
|
"""Create an album PhotosIdentifier."""
|
||||||
return PhotosIdentifier(config_entry_id, PhotosIdentifierType.ALBUM, media_id)
|
return cls(config_entry_id, PhotosIdentifierType.ALBUM, media_id)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def photo(config_entry_id: str, media_id: str) -> "PhotosIdentifier":
|
def photo(cls, config_entry_id: str, media_id: str) -> Self:
|
||||||
"""Create an album PhotosIdentifier."""
|
"""Create an album PhotosIdentifier."""
|
||||||
return PhotosIdentifier(config_entry_id, PhotosIdentifierType.PHOTO, media_id)
|
return cls(config_entry_id, PhotosIdentifierType.PHOTO, media_id)
|
||||||
|
|
||||||
|
|
||||||
async def async_get_media_source(hass: HomeAssistant) -> MediaSource:
|
async def async_get_media_source(hass: HomeAssistant) -> MediaSource:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user