Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions homeassistant/components/yamaha_musiccast/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,27 @@ def state(self):
return STATE_PLAYING
return STATE_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:
Comment thread
marcelveldt marked this conversation as resolved.
label = self.coordinator.data.input_names.get(inp, "")
if inp != label and (
label in self.coordinator.data.zones[self._zone_id].input_list
Comment thread
marcelveldt marked this conversation as resolved.
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
def volume_level(self):
"""Return the volume level of the media player (0..1)."""
Expand Down Expand Up @@ -499,17 +520,19 @@ async def async_set_repeat(self, repeat):

async def async_select_source(self, 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
def source(self):
"""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
def source_list(self):
"""List of available input sources."""
return self.coordinator.data.zones[self._zone_id].input_list
return list(self.source_mapping.values())

@property
def media_duration(self):
Expand Down