mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Move action implementation out of HEOS Coordinator (#136539)
* Move play_source * Update property docstring * Correct import location
This commit is contained in:
parent
ee07f1f290
commit
f8013655be
@ -15,7 +15,6 @@ from pyheos import (
|
|||||||
HeosError,
|
HeosError,
|
||||||
HeosNowPlayingMedia,
|
HeosNowPlayingMedia,
|
||||||
HeosOptions,
|
HeosOptions,
|
||||||
HeosPlayer,
|
|
||||||
MediaItem,
|
MediaItem,
|
||||||
MediaType,
|
MediaType,
|
||||||
PlayerUpdateResult,
|
PlayerUpdateResult,
|
||||||
@ -25,12 +24,12 @@ from pyheos import (
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
||||||
from homeassistant.core import HassJob, HomeAssistant, callback
|
from homeassistant.core import HassJob, HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady, ServiceValidationError
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
from . import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -62,6 +61,11 @@ class HeosCoordinator(DataUpdateCoordinator[None]):
|
|||||||
self._inputs: list[MediaItem] = []
|
self._inputs: list[MediaItem] = []
|
||||||
super().__init__(hass, _LOGGER, config_entry=config_entry, name=DOMAIN)
|
super().__init__(hass, _LOGGER, config_entry=config_entry, name=DOMAIN)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def inputs(self) -> list[MediaItem]:
|
||||||
|
"""Get input sources across all devices."""
|
||||||
|
return self._inputs
|
||||||
|
|
||||||
async def async_setup(self) -> None:
|
async def async_setup(self) -> None:
|
||||||
"""Set up the coordinator; connect to the host; and retrieve initial data."""
|
"""Set up the coordinator; connect to the host; and retrieve initial data."""
|
||||||
# Add before connect as it may occur during initial connection
|
# Add before connect as it may occur during initial connection
|
||||||
@ -265,21 +269,3 @@ class HeosCoordinator(DataUpdateCoordinator[None]):
|
|||||||
):
|
):
|
||||||
return favorite.name
|
return favorite.name
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def async_play_source(self, source: str, player: HeosPlayer) -> None:
|
|
||||||
"""Determine type of source and play it."""
|
|
||||||
# Favorite
|
|
||||||
if (index := self.async_get_favorite_index(source)) is not None:
|
|
||||||
await player.play_preset_station(index)
|
|
||||||
return
|
|
||||||
# Input source
|
|
||||||
for input_source in self._inputs:
|
|
||||||
if input_source.name == source:
|
|
||||||
await player.play_media(input_source)
|
|
||||||
return
|
|
||||||
|
|
||||||
raise ServiceValidationError(
|
|
||||||
translation_domain=DOMAIN,
|
|
||||||
translation_key="unknown_source",
|
|
||||||
translation_placeholders={"source": source},
|
|
||||||
)
|
|
||||||
|
@ -306,7 +306,21 @@ class HeosMediaPlayer(CoordinatorEntity[HeosCoordinator], MediaPlayerEntity):
|
|||||||
@catch_action_error("select source")
|
@catch_action_error("select source")
|
||||||
async def async_select_source(self, source: str) -> None:
|
async def async_select_source(self, source: str) -> None:
|
||||||
"""Select input source."""
|
"""Select input source."""
|
||||||
await self.coordinator.async_play_source(source, self._player)
|
# Favorite
|
||||||
|
if (index := self.coordinator.async_get_favorite_index(source)) is not None:
|
||||||
|
await self._player.play_preset_station(index)
|
||||||
|
return
|
||||||
|
# Input source
|
||||||
|
for input_source in self.coordinator.inputs:
|
||||||
|
if input_source.name == source:
|
||||||
|
await self._player.play_media(input_source)
|
||||||
|
return
|
||||||
|
|
||||||
|
raise ServiceValidationError(
|
||||||
|
translation_domain=HEOS_DOMAIN,
|
||||||
|
translation_key="unknown_source",
|
||||||
|
translation_placeholders={"source": source},
|
||||||
|
)
|
||||||
|
|
||||||
@catch_action_error("set repeat")
|
@catch_action_error("set repeat")
|
||||||
async def async_set_repeat(self, repeat: RepeatMode) -> None:
|
async def async_set_repeat(self, repeat: RepeatMode) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user