mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Improve the source labels for MusicCast players (#74954)
This commit is contained in:
parent
dd3693caca
commit
16fe79db75
@ -155,6 +155,27 @@ class MusicCastMediaPlayer(MusicCastDeviceEntity, MediaPlayerEntity):
|
|||||||
return MediaPlayerState.PLAYING
|
return MediaPlayerState.PLAYING
|
||||||
return MediaPlayerState.OFF
|
return MediaPlayerState.OFF
|
||||||
|
|
||||||
|
@property
|
||||||
|
def source_mapping(self):
|
||||||
|
"""Return a mapping of the actual source names to their labels configured in the MusicCast App."""
|
||||||
|
ret = {}
|
||||||
|
for inp in self.coordinator.data.zones[self._zone_id].input_list:
|
||||||
|
label = self.coordinator.data.input_names.get(inp, "")
|
||||||
|
if inp != label and (
|
||||||
|
label in self.coordinator.data.zones[self._zone_id].input_list
|
||||||
|
or list(self.coordinator.data.input_names.values()).count(label) > 1
|
||||||
|
):
|
||||||
|
label += f" ({inp})"
|
||||||
|
if label == "":
|
||||||
|
label = inp
|
||||||
|
ret[inp] = label
|
||||||
|
return ret
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reverse_source_mapping(self):
|
||||||
|
"""Return a mapping from the source label to the source name."""
|
||||||
|
return {v: k for k, v in self.source_mapping.items()}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume_level(self):
|
def volume_level(self):
|
||||||
"""Return the volume level of the media player (0..1)."""
|
"""Return the volume level of the media player (0..1)."""
|
||||||
@ -491,17 +512,19 @@ class MusicCastMediaPlayer(MusicCastDeviceEntity, MediaPlayerEntity):
|
|||||||
|
|
||||||
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.musiccast.select_source(self._zone_id, source)
|
await self.coordinator.musiccast.select_source(
|
||||||
|
self._zone_id, self.reverse_source_mapping.get(source, source)
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source(self):
|
def source(self):
|
||||||
"""Name of the current input source."""
|
"""Name of the current input source."""
|
||||||
return self.coordinator.data.zones[self._zone_id].input
|
return self.source_mapping.get(self.coordinator.data.zones[self._zone_id].input)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_list(self):
|
def source_list(self):
|
||||||
"""List of available input sources."""
|
"""List of available input sources."""
|
||||||
return self.coordinator.data.zones[self._zone_id].input_list
|
return list(self.source_mapping.values())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_duration(self):
|
def media_duration(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user