Skip to content

Commit

Permalink
Fix grouping feature for MusicCast (home-assistant#95958)
Browse files Browse the repository at this point in the history
check the current source for grouping using the source ID instead of the label
  • Loading branch information
micha91 authored and joostlek committed Jul 6, 2023
1 parent 4b01955 commit 8b17d6e
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions homeassistant/components/yamaha_musiccast/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,11 @@ def zone_id(self):

@property
def _is_netusb(self):
return (
self.coordinator.data.netusb_input
== self.coordinator.data.zones[self._zone_id].input
)
return self.coordinator.data.netusb_input == self.source_id

@property
def _is_tuner(self):
return self.coordinator.data.zones[self._zone_id].input == "tuner"
return self.source_id == "tuner"

@property
def media_content_id(self):
Expand Down Expand Up @@ -516,10 +513,15 @@ async def async_select_source(self, source: str) -> None:
self._zone_id, self.reverse_source_mapping.get(source, source)
)

@property
def source_id(self):
"""ID of the current input source."""
return self.coordinator.data.zones[self._zone_id].input

@property
def source(self):
"""Name of the current input source."""
return self.source_mapping.get(self.coordinator.data.zones[self._zone_id].input)
return self.source_mapping.get(self.source_id)

@property
def source_list(self):
Expand Down Expand Up @@ -597,7 +599,7 @@ def is_network_client(self) -> bool:
return (
self.coordinator.data.group_role == "client"
and self.coordinator.data.group_id != NULL_GROUP
and self.source == ATTR_MC_LINK
and self.source_id == ATTR_MC_LINK
)

@property
Expand All @@ -606,7 +608,7 @@ def is_client(self) -> bool:
If the media player is not part of a group, False is returned.
"""
return self.is_network_client or self.source == ATTR_MAIN_SYNC
return self.is_network_client or self.source_id == ATTR_MAIN_SYNC

def get_all_mc_entities(self) -> list[MusicCastMediaPlayer]:
"""Return all media player entities of the musiccast system."""
Expand Down Expand Up @@ -639,11 +641,11 @@ def is_part_of_group(self, group_server) -> bool:
and self.coordinator.data.group_id
== group_server.coordinator.data.group_id
and self.ip_address != group_server.ip_address
and self.source == ATTR_MC_LINK
and self.source_id == ATTR_MC_LINK
)
or (
self.ip_address == group_server.ip_address
and self.source == ATTR_MAIN_SYNC
and self.source_id == ATTR_MAIN_SYNC
)
)

Expand Down Expand Up @@ -859,8 +861,12 @@ async def async_client_leave_group(self, force=False):
"""
_LOGGER.debug("%s client leave called", self.entity_id)
if not force and (
self.source == ATTR_MAIN_SYNC
or [entity for entity in self.other_zones if entity.source == ATTR_MC_LINK]
self.source_id == ATTR_MAIN_SYNC
or [
entity
for entity in self.other_zones
if entity.source_id == ATTR_MC_LINK
]
):
await self.coordinator.musiccast.zone_unjoin(self._zone_id)
else:
Expand Down

0 comments on commit 8b17d6e

Please sign in to comment.