mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Improve sonos typing (#78661)
This commit is contained in:
parent
38548b0986
commit
b9d34ce169
@ -32,7 +32,7 @@ class SonosFavorites(SonosHouseholdCoordinator):
|
||||
self._favorites: list[DidlFavorite] = []
|
||||
self.last_polled_ids: dict[str, int] = {}
|
||||
|
||||
def __iter__(self) -> Iterator:
|
||||
def __iter__(self) -> Iterator[DidlFavorite]:
|
||||
"""Return an iterator for the known favorites."""
|
||||
favorites = self._favorites.copy()
|
||||
return iter(favorites)
|
||||
|
@ -7,13 +7,17 @@ from functools import partial
|
||||
import logging
|
||||
from typing import cast
|
||||
|
||||
from soco.data_structures import DidlFavorite, DidlObject
|
||||
from soco.data_structures import DidlObject
|
||||
from soco.ms_data_structures import MusicServiceItem
|
||||
from soco.music_library import MusicLibrary
|
||||
|
||||
from homeassistant.components import media_source, plex, spotify
|
||||
from homeassistant.components.media_player import BrowseMedia, MediaClass, MediaType
|
||||
from homeassistant.components.media_player.errors import BrowseError
|
||||
from homeassistant.components.media_player import (
|
||||
BrowseError,
|
||||
BrowseMedia,
|
||||
MediaClass,
|
||||
MediaType,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.network import is_internal_request
|
||||
|
||||
@ -32,6 +36,7 @@ from .const import (
|
||||
SONOS_TYPES_MAPPING,
|
||||
)
|
||||
from .exception import UnknownMediaType
|
||||
from .favorites import SonosFavorites
|
||||
from .speaker import SonosMedia, SonosSpeaker
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -363,15 +368,15 @@ def library_payload(media_library: MusicLibrary, get_thumbnail_url=None) -> Brow
|
||||
)
|
||||
|
||||
|
||||
def favorites_payload(favorites: list[DidlFavorite]) -> BrowseMedia:
|
||||
def favorites_payload(favorites: SonosFavorites) -> BrowseMedia:
|
||||
"""
|
||||
Create response payload to describe contents of a specific library.
|
||||
|
||||
Used by async_browse_media.
|
||||
"""
|
||||
children = []
|
||||
children: list[BrowseMedia] = []
|
||||
|
||||
group_types = {fav.reference.item_class for fav in favorites}
|
||||
group_types: set[str] = {fav.reference.item_class for fav in favorites}
|
||||
for group_type in sorted(group_types):
|
||||
try:
|
||||
media_content_type = SONOS_TYPES_MAPPING[group_type]
|
||||
@ -402,13 +407,13 @@ def favorites_payload(favorites: list[DidlFavorite]) -> BrowseMedia:
|
||||
|
||||
|
||||
def favorites_folder_payload(
|
||||
favorites: list[DidlFavorite], media_content_id: str
|
||||
favorites: SonosFavorites, media_content_id: str
|
||||
) -> BrowseMedia:
|
||||
"""Create response payload to describe all items of a type of favorite.
|
||||
|
||||
Used by async_browse_media.
|
||||
"""
|
||||
children = []
|
||||
children: list[BrowseMedia] = []
|
||||
content_type = SONOS_TYPES_MAPPING[media_content_id]
|
||||
|
||||
for favorite in favorites:
|
||||
|
@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Callable, Coroutine
|
||||
from collections.abc import Callable, Collection, Coroutine
|
||||
import contextlib
|
||||
import datetime
|
||||
from functools import partial
|
||||
@ -946,7 +946,7 @@ class SonosSpeaker:
|
||||
) -> None:
|
||||
"""Snapshot all the speakers and optionally their groups."""
|
||||
|
||||
def _snapshot_all(speakers: list[SonosSpeaker]) -> None:
|
||||
def _snapshot_all(speakers: Collection[SonosSpeaker]) -> None:
|
||||
"""Sync helper."""
|
||||
for speaker in speakers:
|
||||
speaker.snapshot(with_group)
|
||||
@ -1032,7 +1032,7 @@ class SonosSpeaker:
|
||||
|
||||
return groups
|
||||
|
||||
def _restore_players(speakers: list[SonosSpeaker]) -> None:
|
||||
def _restore_players(speakers: Collection[SonosSpeaker]) -> None:
|
||||
"""Restore state of all players."""
|
||||
for speaker in (s for s in speakers if not s.is_coordinator):
|
||||
speaker.restore()
|
||||
|
Loading…
x
Reference in New Issue
Block a user