From d1037e582c229cb4b5555291ef3a05e63ba157fe Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 10:56:35 +0100 Subject: [PATCH 01/26] Update media_player.py --- .../bluesound_alt/media_player.py | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 945eacb..55c8c1d 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -69,6 +69,8 @@ UPDATE_PRESETS_INTERVAL = timedelta(minutes=30) UPDATE_SERVICES_INTERVAL = timedelta(minutes=30) +EPOCH_REBUILD_GROUPS_MODULO = 100 + PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_HOSTS): vol.All( @@ -287,9 +289,11 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False async def _start_poll_command(self): """Loop which polls the status of the player.""" - try: + try: + epoch = 0 while True: - await self.async_update_status() + await self.async_update_status(epoch) + epoch += 1 except (asyncio.TimeoutError, ClientError, BluesoundPlayer._TimeoutException): _LOGGER.info("Node %s:%s is offline, retrying later", self.name, self.port) @@ -380,7 +384,7 @@ async def send_bluesound_command( return data - async def async_update_status(self): + async def async_update_status(self, epoch): """Use the poll session to always get the status of the player.""" response = None @@ -407,16 +411,19 @@ async def async_update_status(self): self._last_status_update = dt_util.utcnow() self._status = xmltodict.parse(result)["status"].copy() - # update group name - group_name = self._status.get("groupName") - self._group_name = group_name + # update groups if enough epochs have passed + if epoch % EPOCH_REBUILD_GROUPS_MODULO == 0: + # update group name + group_name = self._status.get("groupName") + self._group_name = group_name - # rebuild ordered list of entity_ids that are in the group, master is first - self._group_list = await self.rebuild_bluesound_group() + # rebuild ordered list of entity_ids that are in the group, master is first + self._group_list = await self.rebuild_bluesound_group() + + # the sleep is needed to make sure that the + # devices is synced + await asyncio.sleep(1) - # the sleep is needed to make sure that the - # devices is synced - await asyncio.sleep(1) await self.async_trigger_sync_on_all() if self.is_grouped: @@ -853,6 +860,9 @@ async def async_join(self, master): else: _LOGGER.error("Master not found %s", master_device) + # rebuild ordered list of entity_ids that are in the group, master is first + self._group_list = await self.rebuild_bluesound_group() + @property def extra_state_attributes(self): """List members in group.""" @@ -959,18 +969,31 @@ async def async_unjoin(self): _LOGGER.debug("Trying to unjoin player: %s", self.id) await self._master.async_remove_slave(self) + # rebuild ordered list of entity_ids that are in the group, master is first + self._group_list = await self.rebuild_bluesound_group() + async def async_add_slave(self, slave_device): """Add slave to master.""" - return await self.send_bluesound_command( + result = await self.send_bluesound_command( f"/AddSlave?slave={slave_device.host}&port={slave_device.port}" ) + + # rebuild ordered list of entity_ids that are in the group, master is first + self._group_list = await self.rebuild_bluesound_group() + + return result async def async_remove_slave(self, slave_device): """Remove slave to master.""" - return await self.send_bluesound_command( + result = await self.send_bluesound_command( f"/RemoveSlave?slave={slave_device.host}&port={slave_device.port}" ) + # rebuild ordered list of entity_ids that are in the group, master is first + self._group_list = await self.rebuild_bluesound_group() + + return result + async def async_increase_timer(self): """Increase sleep time on player.""" sleep_time = await self.send_bluesound_command("/Sleep") From 5b0b7cd4f40b1c356fce7565de1baf6fb7715725 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 11:05:41 +0100 Subject: [PATCH 02/26] Sleeps and logging --- .../bluesound_alt/media_player.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 55c8c1d..e8f7c26 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -413,6 +413,8 @@ async def async_update_status(self, epoch): # update groups if enough epochs have passed if epoch % EPOCH_REBUILD_GROUPS_MODULO == 0: + _LOGGER.debug("Time for a group rebuild.") + # update group name group_name = self._status.get("groupName") self._group_name = group_name @@ -860,6 +862,10 @@ async def async_join(self, master): else: _LOGGER.error("Master not found %s", master_device) + # the sleep is needed to make sure that the + # devices is synced + await asyncio.sleep(1) + # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() @@ -882,6 +888,8 @@ async def rebuild_bluesound_group(self): new_device_group = [] if self.is_master: + _LOGGER.debug("Device is a master: %s", self._id) + # Add device itself to the start of array new_device_group.append(self.entity_id) @@ -910,7 +918,7 @@ async def rebuild_bluesound_group(self): if str(device._id) == slave_id + ":" + slave_port: new_device_group.append(device.entity_id) else: - _LOGGER.debug("Device is a slave: %s", new_device_group) + _LOGGER.debug("Device is a slave: %s", self._id) # Call to get slaves sync_status = await self.send_bluesound_command( @@ -969,6 +977,10 @@ async def async_unjoin(self): _LOGGER.debug("Trying to unjoin player: %s", self.id) await self._master.async_remove_slave(self) + # the sleep is needed to make sure that the + # devices is synced + await asyncio.sleep(1) + # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() @@ -977,6 +989,10 @@ async def async_add_slave(self, slave_device): result = await self.send_bluesound_command( f"/AddSlave?slave={slave_device.host}&port={slave_device.port}" ) + + # the sleep is needed to make sure that the + # devices is synced + await asyncio.sleep(1) # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() @@ -989,6 +1005,10 @@ async def async_remove_slave(self, slave_device): f"/RemoveSlave?slave={slave_device.host}&port={slave_device.port}" ) + # the sleep is needed to make sure that the + # devices is synced + await asyncio.sleep(1) + # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() From 19c739e8bf52b9d30af1722aaceaf43e1bdaed1b Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 11:14:09 +0100 Subject: [PATCH 03/26] Update media_player.py --- .../bluesound_alt/media_player.py | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index e8f7c26..cfb272e 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -411,6 +411,8 @@ async def async_update_status(self, epoch): self._last_status_update = dt_util.utcnow() self._status = xmltodict.parse(result)["status"].copy() + _LOGGER.debug("Epoch is: %s", epoch) + # update groups if enough epochs have passed if epoch % EPOCH_REBUILD_GROUPS_MODULO == 0: _LOGGER.debug("Time for a group rebuild.") @@ -862,12 +864,12 @@ async def async_join(self, master): else: _LOGGER.error("Master not found %s", master_device) - # the sleep is needed to make sure that the - # devices is synced - await asyncio.sleep(1) - # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() + master._group_list = await master.rebuild_bluesound_group() + + # the sleep is needed to make sure that the devices are synced + await asyncio.sleep(1) @property def extra_state_attributes(self): @@ -977,25 +979,24 @@ async def async_unjoin(self): _LOGGER.debug("Trying to unjoin player: %s", self.id) await self._master.async_remove_slave(self) - # the sleep is needed to make sure that the - # devices is synced - await asyncio.sleep(1) - # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() + # the sleep is needed to make sure that the devices are synced + await asyncio.sleep(1) + async def async_add_slave(self, slave_device): """Add slave to master.""" result = await self.send_bluesound_command( f"/AddSlave?slave={slave_device.host}&port={slave_device.port}" ) - # the sleep is needed to make sure that the - # devices is synced - await asyncio.sleep(1) - # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() + slave_device._group_list = await slave_device.rebuild_bluesound_group() + + # the sleep is needed to make sure that the devices are synced + await asyncio.sleep(1) return result @@ -1005,12 +1006,12 @@ async def async_remove_slave(self, slave_device): f"/RemoveSlave?slave={slave_device.host}&port={slave_device.port}" ) - # the sleep is needed to make sure that the - # devices is synced - await asyncio.sleep(1) - # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() + slave_device._group_list = await slave_device.rebuild_bluesound_group() + + # the sleep is needed to make sure that the devices are synced + await asyncio.sleep(1) return result From c9a46ad8ca99417710c99b6ad8a83b61a671003a Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 11:17:54 +0100 Subject: [PATCH 04/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index cfb272e..d9763c6 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -866,7 +866,7 @@ async def async_join(self, master): # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() - master._group_list = await master.rebuild_bluesound_group() + master_device._group_list = await master_device.rebuild_bluesound_group() # the sleep is needed to make sure that the devices are synced await asyncio.sleep(1) From 07b8d070c027c8f31a338e6d11ae59ab2799072e Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 11:22:58 +0100 Subject: [PATCH 05/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index d9763c6..5c2b5cf 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -69,7 +69,7 @@ UPDATE_PRESETS_INTERVAL = timedelta(minutes=30) UPDATE_SERVICES_INTERVAL = timedelta(minutes=30) -EPOCH_REBUILD_GROUPS_MODULO = 100 +EPOCH_REBUILD_GROUPS_MODULO = 10 PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { @@ -866,7 +866,7 @@ async def async_join(self, master): # rebuild ordered list of entity_ids that are in the group, master is first self._group_list = await self.rebuild_bluesound_group() - master_device._group_list = await master_device.rebuild_bluesound_group() + master_device[0]._group_list = await master_device[0].rebuild_bluesound_group() # the sleep is needed to make sure that the devices are synced await asyncio.sleep(1) From 69d76b0f506b3395407b9fd0a97065dbaed5e389 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 11:26:29 +0100 Subject: [PATCH 06/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 5c2b5cf..c6562b5 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -884,8 +884,7 @@ def extra_state_attributes(self): async def rebuild_bluesound_group(self): """Rebuild the list of entities in speaker group.""" - if self._group_name is None: - return None + _LOGGER.debug("Rebuilding group for %s", self._id) new_device_group = [] From bff6574076b99aeafd98d3d307661810f51ccbcd Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:03:21 +0100 Subject: [PATCH 07/26] Update media_player.py --- .../bluesound_alt/media_player.py | 127 ++++++++++++++---- 1 file changed, 101 insertions(+), 26 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index c6562b5..fcf0acf 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -224,6 +224,7 @@ def __init__(self, hass, host, port=None, name=None, init_callback=None): self._muted = False self._master = None self._is_master = False + self._is_grouped = False self._group_name = None self._group_list = [] self._bluesound_device_name = None @@ -262,26 +263,106 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False self._bluesound_device_name = self._sync_status.get("@name", self.host) if (master := self._sync_status.get("master")) is not None: + # Device is a slave + _LOGGER.debug("Device is a slave: %s", self._id) + self._is_master = False + self._master = None + self.is_grouped = True + + # Build parameters master_host = master.get("#text") master_port = master.get("@port", "11000") master_id = f"{master_host}:{master_port}" - master_device = [ - device - for device in self._hass.data[DATA_BLUESOUND] - if device.id == master_id - ] - if master_device and master_id != self.id: - self._master = master_device[0] - else: - self._master = None + # Find device + for device in self._hass.data[DATA_BLUESOUND]: + if device.id == master_id: + self._master = device + + # Error if master is not found + if self._master is None: _LOGGER.error("Master not found %s", master_id) - else: + + # New group for master + new_device_group = [] + new_device_group.append(self._master.entity_id) + + # Call to get slaves for master + resp_two = await self.send_bluesound_command( + "SyncStatus", raise_timeout, raise_timeout + ) + + self._master._sync_status = resp_two["SyncStatus"].copy() + + if self._master.sync_status["SyncStatus"]["slave"] != None: + # Extract information from slave objects + slave_objects = self._master._sync_status["SyncStatus"].get('slave', []) + if isinstance(slave_objects, list): + # Multiple slave objects + for slave_obj in slave_objects: + slave_id = slave_obj['@id'] + slave_port = slave_obj['@port'] + # Find correct entity_id for slave + for device in self._hass.data[DATA_BLUESOUND]: + if str(device._id) == slave_id + ":" + slave_port: + new_device_group.append(device.entity_id) + elif slave_objects != None: + # Single slave object + slave_id = slave_objects['@id'] + slave_port = slave_objects['@port'] + # Find correct entity_id for slave + for device in self._hass.data[DATA_BLUESOUND]: + if str(device._id) == slave_id + ":" + slave_port: + new_device_group.append(device.entity_id) + + # Add new group to master and slave + for device in new_device_group: + device._group_list = new_device_group + + elif self._sync_status.get("slave") is not None: + # Device is a master + _LOGGER.debug("Device is a master: %s", self._id) + if self._master is not None: self._master = None - slaves = self._sync_status.get("slave") - self._is_master = slaves is not None + self._is_master = False + self.is_grouped = True + + slave_objects = [] + slave_objects.append(self.entity_id) + + # Extract information from slave objects + slave_objects = self._sync_status["SyncStatus"].get('slave', []) + if isinstance(slave_objects, list): + # Multiple slave objects + for slave_obj in slave_objects: + slave_id = slave_obj['@id'] + slave_port = slave_obj['@port'] + # Find correct entity_id for slave + for device in self._hass.data[DATA_BLUESOUND]: + if str(device._id) == slave_id + ":" + slave_port: + new_device_group.append(device.entity_id) + self._is_master = True + elif slave_objects != None: + # Single slave object + slave_id = slave_objects['@id'] + slave_port = slave_objects['@port'] + # Find correct entity_id for slave + for device in self._hass.data[DATA_BLUESOUND]: + if str(device._id) == slave_id + ":" + slave_port: + new_device_group.append(device.entity_id) + self._is_master = True + + # Add new group to master and slave + for device in new_device_group: + device._group_list = new_device_group + + else: + self._is_master = False + self._master = None + self.is_grouped = False + device._group_list = [] if on_updated_cb: on_updated_cb() @@ -411,22 +492,16 @@ async def async_update_status(self, epoch): self._last_status_update = dt_util.utcnow() self._status = xmltodict.parse(result)["status"].copy() - _LOGGER.debug("Epoch is: %s", epoch) + # update group name + group_name = self._status.get("groupName") + self._group_name = group_name - # update groups if enough epochs have passed - if epoch % EPOCH_REBUILD_GROUPS_MODULO == 0: - _LOGGER.debug("Time for a group rebuild.") + # rebuild ordered list of entity_ids that are in the group, master is first + # self._group_list = await self.rebuild_bluesound_group() - # update group name - group_name = self._status.get("groupName") - self._group_name = group_name - - # rebuild ordered list of entity_ids that are in the group, master is first - self._group_list = await self.rebuild_bluesound_group() - - # the sleep is needed to make sure that the - # devices is synced - await asyncio.sleep(1) + # the sleep is needed to make sure that the + # devices is synced + # await asyncio.sleep(1) await self.async_trigger_sync_on_all() From 07baeef01c0a873bd2514dc960a821c6d3a8bb63 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:06:23 +0100 Subject: [PATCH 08/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index fcf0acf..11a9acc 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -224,7 +224,7 @@ def __init__(self, hass, host, port=None, name=None, init_callback=None): self._muted = False self._master = None self._is_master = False - self._is_grouped = False + self.is_grouped = False self._group_name = None self._group_list = [] self._bluesound_device_name = None From 179f7378ab4b1cc7c3eb9a4a4b200b1e03e15392 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:10:12 +0100 Subject: [PATCH 09/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 11a9acc..669bf76 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -224,7 +224,6 @@ def __init__(self, hass, host, port=None, name=None, init_callback=None): self._muted = False self._master = None self._is_master = False - self.is_grouped = False self._group_name = None self._group_list = [] self._bluesound_device_name = None @@ -268,7 +267,6 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False self._is_master = False self._master = None - self.is_grouped = True # Build parameters master_host = master.get("#text") @@ -327,7 +325,6 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False if self._master is not None: self._master = None self._is_master = False - self.is_grouped = True slave_objects = [] slave_objects.append(self.entity_id) @@ -361,7 +358,6 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False else: self._is_master = False self._master = None - self.is_grouped = False device._group_list = [] if on_updated_cb: From d130f39ef55c9dbc32f8879dd351a38263b484b5 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:12:14 +0100 Subject: [PATCH 10/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 669bf76..e9fa79f 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -358,7 +358,7 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False else: self._is_master = False self._master = None - device._group_list = [] + self._group_list = [] if on_updated_cb: on_updated_cb() From 84338501b1251b34f6d6202dab15e1740ebfcd77 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:16:36 +0100 Subject: [PATCH 11/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index e9fa79f..2e1aac1 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -272,11 +272,13 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False master_host = master.get("#text") master_port = master.get("@port", "11000") master_id = f"{master_host}:{master_port}" + master_device = None # Find device for device in self._hass.data[DATA_BLUESOUND]: if device.id == master_id: self._master = device + master_device = device # Error if master is not found if self._master is None: @@ -284,18 +286,18 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False # New group for master new_device_group = [] - new_device_group.append(self._master.entity_id) + new_device_group.append(master_device.entity_id) # Call to get slaves for master resp_two = await self.send_bluesound_command( "SyncStatus", raise_timeout, raise_timeout ) - self._master._sync_status = resp_two["SyncStatus"].copy() + master_device._sync_status = resp_two["SyncStatus"].copy() - if self._master.sync_status["SyncStatus"]["slave"] != None: + if master_device._sync_status["SyncStatus"]["slave"] != None: # Extract information from slave objects - slave_objects = self._master._sync_status["SyncStatus"].get('slave', []) + slave_objects = master_device._sync_status["SyncStatus"].get('slave', []) if isinstance(slave_objects, list): # Multiple slave objects for slave_obj in slave_objects: From c46153d81ca556d79f7667405bfbb0505de3d3d9 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:19:38 +0100 Subject: [PATCH 12/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 2e1aac1..9eadd70 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -272,7 +272,6 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False master_host = master.get("#text") master_port = master.get("@port", "11000") master_id = f"{master_host}:{master_port}" - master_device = None # Find device for device in self._hass.data[DATA_BLUESOUND]: @@ -286,18 +285,18 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False # New group for master new_device_group = [] - new_device_group.append(master_device.entity_id) + new_device_group.append(self._master.entity_id) # Call to get slaves for master resp_two = await self.send_bluesound_command( "SyncStatus", raise_timeout, raise_timeout ) - master_device._sync_status = resp_two["SyncStatus"].copy() + self._master._sync_status = resp_two["SyncStatus"].copy() - if master_device._sync_status["SyncStatus"]["slave"] != None: + if self._master._sync_status["SyncStatus"]["slave"] != None: # Extract information from slave objects - slave_objects = master_device._sync_status["SyncStatus"].get('slave', []) + slave_objects = self._master._sync_status["SyncStatus"].get('slave', []) if isinstance(slave_objects, list): # Multiple slave objects for slave_obj in slave_objects: From 268850513d2e98fa3a75c8131cf0f446a67b651d Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:24:42 +0100 Subject: [PATCH 13/26] Update media_player.py --- .../bluesound_alt/media_player.py | 63 +++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 9eadd70..38637d5 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -277,47 +277,46 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False for device in self._hass.data[DATA_BLUESOUND]: if device.id == master_id: self._master = device - master_device = device # Error if master is not found if self._master is None: - _LOGGER.error("Master not found %s", master_id) - - # New group for master - new_device_group = [] - new_device_group.append(self._master.entity_id) - - # Call to get slaves for master - resp_two = await self.send_bluesound_command( - "SyncStatus", raise_timeout, raise_timeout - ) + _LOGGER.error("Master not found for: %s", master_id) + else: + # New group for master + new_device_group = [] + new_device_group.append(self._master.entity_id) + + # Call to get slaves for master + resp_two = await self.send_bluesound_command( + "SyncStatus", raise_timeout, raise_timeout + ) - self._master._sync_status = resp_two["SyncStatus"].copy() + self._master._sync_status = resp_two["SyncStatus"].copy() - if self._master._sync_status["SyncStatus"]["slave"] != None: - # Extract information from slave objects - slave_objects = self._master._sync_status["SyncStatus"].get('slave', []) - if isinstance(slave_objects, list): - # Multiple slave objects - for slave_obj in slave_objects: - slave_id = slave_obj['@id'] - slave_port = slave_obj['@port'] + if self._master._sync_status["SyncStatus"]["slave"] != None: + # Extract information from slave objects + slave_objects = self._master._sync_status["SyncStatus"].get('slave', []) + if isinstance(slave_objects, list): + # Multiple slave objects + for slave_obj in slave_objects: + slave_id = slave_obj['@id'] + slave_port = slave_obj['@port'] + # Find correct entity_id for slave + for device in self._hass.data[DATA_BLUESOUND]: + if str(device._id) == slave_id + ":" + slave_port: + new_device_group.append(device.entity_id) + elif slave_objects != None: + # Single slave object + slave_id = slave_objects['@id'] + slave_port = slave_objects['@port'] # Find correct entity_id for slave for device in self._hass.data[DATA_BLUESOUND]: if str(device._id) == slave_id + ":" + slave_port: new_device_group.append(device.entity_id) - elif slave_objects != None: - # Single slave object - slave_id = slave_objects['@id'] - slave_port = slave_objects['@port'] - # Find correct entity_id for slave - for device in self._hass.data[DATA_BLUESOUND]: - if str(device._id) == slave_id + ":" + slave_port: - new_device_group.append(device.entity_id) - # Add new group to master and slave - for device in new_device_group: - device._group_list = new_device_group + # Add new group to master and slave + for device in new_device_group: + device._group_list = new_device_group elif self._sync_status.get("slave") is not None: # Device is a master @@ -331,7 +330,7 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False slave_objects.append(self.entity_id) # Extract information from slave objects - slave_objects = self._sync_status["SyncStatus"].get('slave', []) + slave_objects = self._sync_status.get('slave', []) if isinstance(slave_objects, list): # Multiple slave objects for slave_obj in slave_objects: From 3f33b647d5dc891ccee4ef69446c0885752a8533 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:28:33 +0100 Subject: [PATCH 14/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 38637d5..69fbda5 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -315,8 +315,10 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False new_device_group.append(device.entity_id) # Add new group to master and slave - for device in new_device_group: - device._group_list = new_device_group + for main_device in self._hass.data[DATA_BLUESOUND]: + for device in new_device_group: + if main_device.id == device.id: + main_device._group_list = new_device_group elif self._sync_status.get("slave") is not None: # Device is a master @@ -352,8 +354,10 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False self._is_master = True # Add new group to master and slave - for device in new_device_group: - device._group_list = new_device_group + for main_device in self._hass.data[DATA_BLUESOUND]: + for device in new_device_group: + if main_device.id == device.id: + main_device._group_list = new_device_group else: self._is_master = False From 5e1447bd6e38ec1bb7a8162bfbbe0daede7911a2 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:31:42 +0100 Subject: [PATCH 15/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 69fbda5..69ce350 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -314,11 +314,8 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False if str(device._id) == slave_id + ":" + slave_port: new_device_group.append(device.entity_id) - # Add new group to master and slave - for main_device in self._hass.data[DATA_BLUESOUND]: - for device in new_device_group: - if main_device.id == device.id: - main_device._group_list = new_device_group + # Add new group + self._group_list = new_device_group elif self._sync_status.get("slave") is not None: # Device is a master @@ -353,11 +350,8 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False new_device_group.append(device.entity_id) self._is_master = True - # Add new group to master and slave - for main_device in self._hass.data[DATA_BLUESOUND]: - for device in new_device_group: - if main_device.id == device.id: - main_device._group_list = new_device_group + # Add new group + self._group_list = new_device_group else: self._is_master = False From 1a4d9076f674992ccc30b52ca5c26d86ee91360d Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:33:59 +0100 Subject: [PATCH 16/26] Revert "Update media_player.py" This reverts commit 5e1447bd6e38ec1bb7a8162bfbbe0daede7911a2. --- custom_components/bluesound_alt/media_player.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 69ce350..69fbda5 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -314,8 +314,11 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False if str(device._id) == slave_id + ":" + slave_port: new_device_group.append(device.entity_id) - # Add new group - self._group_list = new_device_group + # Add new group to master and slave + for main_device in self._hass.data[DATA_BLUESOUND]: + for device in new_device_group: + if main_device.id == device.id: + main_device._group_list = new_device_group elif self._sync_status.get("slave") is not None: # Device is a master @@ -350,8 +353,11 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False new_device_group.append(device.entity_id) self._is_master = True - # Add new group - self._group_list = new_device_group + # Add new group to master and slave + for main_device in self._hass.data[DATA_BLUESOUND]: + for device in new_device_group: + if main_device.id == device.id: + main_device._group_list = new_device_group else: self._is_master = False From 8b9489d417df1cd6babc03d8412a369759cf40d3 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:34:20 +0100 Subject: [PATCH 17/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 69fbda5..e666d6b 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -328,8 +328,8 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False self._master = None self._is_master = False - slave_objects = [] - slave_objects.append(self.entity_id) + new_device_group = [] + new_device_group.append(self.entity_id) # Extract information from slave objects slave_objects = self._sync_status.get('slave', []) From a9567bd92bb3718c43235b8a7e0128ed95e2c2d8 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:37:26 +0100 Subject: [PATCH 18/26] ID should be _ID --- custom_components/bluesound_alt/media_player.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index e666d6b..ec198df 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -317,7 +317,7 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False # Add new group to master and slave for main_device in self._hass.data[DATA_BLUESOUND]: for device in new_device_group: - if main_device.id == device.id: + if main_device._id == device._id: main_device._group_list = new_device_group elif self._sync_status.get("slave") is not None: @@ -356,7 +356,7 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False # Add new group to master and slave for main_device in self._hass.data[DATA_BLUESOUND]: for device in new_device_group: - if main_device.id == device.id: + if main_device._id == device._id: main_device._group_list = new_device_group else: From fe87cecbac8fd69bc984f7d43617711b202f9031 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:40:21 +0100 Subject: [PATCH 19/26] Two issues --- custom_components/bluesound_alt/media_player.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index ec198df..bd0fe04 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -293,9 +293,9 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False self._master._sync_status = resp_two["SyncStatus"].copy() - if self._master._sync_status["SyncStatus"]["slave"] != None: + if self._master._sync_status["slave"] != None: # Extract information from slave objects - slave_objects = self._master._sync_status["SyncStatus"].get('slave', []) + slave_objects = self._master._sync_status.get('slave', []) if isinstance(slave_objects, list): # Multiple slave objects for slave_obj in slave_objects: @@ -317,7 +317,7 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False # Add new group to master and slave for main_device in self._hass.data[DATA_BLUESOUND]: for device in new_device_group: - if main_device._id == device._id: + if main_device.entity_id == device: main_device._group_list = new_device_group elif self._sync_status.get("slave") is not None: @@ -356,7 +356,7 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False # Add new group to master and slave for main_device in self._hass.data[DATA_BLUESOUND]: for device in new_device_group: - if main_device._id == device._id: + if main_device.entity_id == device: main_device._group_list = new_device_group else: From e762c7e5634ee06c51e27503fbcb463896414b6c Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:44:13 +0100 Subject: [PATCH 20/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index bd0fe04..be60d48 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -293,9 +293,8 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False self._master._sync_status = resp_two["SyncStatus"].copy() - if self._master._sync_status["slave"] != None: + if (slave_objects := self._master._sync_status.get('slave', [])) is not None: # Extract information from slave objects - slave_objects = self._master._sync_status.get('slave', []) if isinstance(slave_objects, list): # Multiple slave objects for slave_obj in slave_objects: @@ -314,11 +313,11 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False if str(device._id) == slave_id + ":" + slave_port: new_device_group.append(device.entity_id) - # Add new group to master and slave - for main_device in self._hass.data[DATA_BLUESOUND]: - for device in new_device_group: - if main_device.entity_id == device: - main_device._group_list = new_device_group + # Add new group to master and slave + for main_device in self._hass.data[DATA_BLUESOUND]: + for device in new_device_group: + if main_device.entity_id == device: + main_device._group_list = new_device_group elif self._sync_status.get("slave") is not None: # Device is a master From 145b75fc1e6507dbcc57c6af4b066efda718c5e5 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:49:59 +0100 Subject: [PATCH 21/26] Update media_player.py --- .../bluesound_alt/media_player.py | 111 +----------------- 1 file changed, 4 insertions(+), 107 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index be60d48..0b09175 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -939,11 +939,7 @@ async def async_join(self, master): _LOGGER.error("Master not found %s", master_device) # rebuild ordered list of entity_ids that are in the group, master is first - self._group_list = await self.rebuild_bluesound_group() - master_device[0]._group_list = await master_device[0].rebuild_bluesound_group() - - # the sleep is needed to make sure that the devices are synced - await asyncio.sleep(1) + await self.async_update_status() @property def extra_state_attributes(self): @@ -956,94 +952,6 @@ def extra_state_attributes(self): return attributes - async def rebuild_bluesound_group(self): - """Rebuild the list of entities in speaker group.""" - _LOGGER.debug("Rebuilding group for %s", self._id) - - new_device_group = [] - - if self.is_master: - _LOGGER.debug("Device is a master: %s", self._id) - - # Add device itself to the start of array - new_device_group.append(self.entity_id) - - # Call to get slaves - sync_status = await self.send_bluesound_command( - f"/SyncStatus" - ) - - # Extract information from slave objects - slave_objects = sync_status["SyncStatus"].get('slave', []) - if isinstance(slave_objects, list): - # Multiple slave objects - for slave_obj in slave_objects: - slave_id = slave_obj['@id'] - slave_port = slave_obj['@port'] - # Find correct entity_id for slave - for device in self._hass.data[DATA_BLUESOUND]: - if str(device._id) == slave_id + ":" + slave_port: - new_device_group.append(device.entity_id) - elif slave_objects != None: - # Single slave object - slave_id = slave_objects['@id'] - slave_port = slave_objects['@port'] - # Find correct entity_id for slave - for device in self._hass.data[DATA_BLUESOUND]: - if str(device._id) == slave_id + ":" + slave_port: - new_device_group.append(device.entity_id) - else: - _LOGGER.debug("Device is a slave: %s", self._id) - - # Call to get slaves - sync_status = await self.send_bluesound_command( - f"/SyncStatus" - ) - - master = sync_status["SyncStatus"].get('master') - master_device = None - - if master != None: - master_id = master['#text'] - master_port = master['@port'] - - for device in self._hass.data[DATA_BLUESOUND]: - if str(device._id) == master_id + ":" + master_port: - master_device = device - - if master_device != None: - # Add device itself to the start of array - new_device_group.append(master_device.entity_id) - - # Call to get slaves - sync_status = await master_device.send_bluesound_command( - f"/SyncStatus" - ) - - if sync_status["SyncStatus"]["slave"] != None: - # Extract information from slave objects - slave_objects = sync_status["SyncStatus"].get('slave', []) - if isinstance(slave_objects, list): - # Multiple slave objects - for slave_obj in slave_objects: - slave_id = slave_obj['@id'] - slave_port = slave_obj['@port'] - # Find correct entity_id for slave - for device in self._hass.data[DATA_BLUESOUND]: - if str(device._id) == slave_id + ":" + slave_port: - new_device_group.append(device.entity_id) - elif slave_objects != None: - # Single slave object - slave_id = slave_objects['@id'] - slave_port = slave_objects['@port'] - # Find correct entity_id for slave - for device in self._hass.data[DATA_BLUESOUND]: - if str(device._id) == slave_id + ":" + slave_port: - new_device_group.append(device.entity_id) - - _LOGGER.debug("New group for device: %s", new_device_group) - return new_device_group - async def async_unjoin(self): """Unjoin the player from a group.""" if self._master is None: @@ -1053,10 +961,7 @@ async def async_unjoin(self): await self._master.async_remove_slave(self) # rebuild ordered list of entity_ids that are in the group, master is first - self._group_list = await self.rebuild_bluesound_group() - - # the sleep is needed to make sure that the devices are synced - await asyncio.sleep(1) + await self.async_update_status() async def async_add_slave(self, slave_device): """Add slave to master.""" @@ -1065,11 +970,7 @@ async def async_add_slave(self, slave_device): ) # rebuild ordered list of entity_ids that are in the group, master is first - self._group_list = await self.rebuild_bluesound_group() - slave_device._group_list = await slave_device.rebuild_bluesound_group() - - # the sleep is needed to make sure that the devices are synced - await asyncio.sleep(1) + await self.async_update_status() return result @@ -1080,11 +981,7 @@ async def async_remove_slave(self, slave_device): ) # rebuild ordered list of entity_ids that are in the group, master is first - self._group_list = await self.rebuild_bluesound_group() - slave_device._group_list = await slave_device.rebuild_bluesound_group() - - # the sleep is needed to make sure that the devices are synced - await asyncio.sleep(1) + await self.async_update_status() return result From 15992b9fc2d1cc1613a073374987db4460f4513c Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:53:10 +0100 Subject: [PATCH 22/26] Epoch remove --- custom_components/bluesound_alt/media_player.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 0b09175..886ce94 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -69,8 +69,6 @@ UPDATE_PRESETS_INTERVAL = timedelta(minutes=30) UPDATE_SERVICES_INTERVAL = timedelta(minutes=30) -EPOCH_REBUILD_GROUPS_MODULO = 10 - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_HOSTS): vol.All( @@ -370,10 +368,8 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False async def _start_poll_command(self): """Loop which polls the status of the player.""" try: - epoch = 0 while True: - await self.async_update_status(epoch) - epoch += 1 + await self.async_update_status() except (asyncio.TimeoutError, ClientError, BluesoundPlayer._TimeoutException): _LOGGER.info("Node %s:%s is offline, retrying later", self.name, self.port) @@ -464,7 +460,7 @@ async def send_bluesound_command( return data - async def async_update_status(self, epoch): + async def async_update_status(self): """Use the poll session to always get the status of the player.""" response = None From d202a773ec632b8eb2de16e71976ffb460934ffc Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 12:57:32 +0100 Subject: [PATCH 23/26] Update media_player.py --- .../bluesound_alt/media_player.py | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 886ce94..75eeb9c 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -914,6 +914,17 @@ def is_grouped(self): def shuffle(self): """Return true if shuffle is active.""" return self._status.get("shuffle", "0") == "1" + + @property + def extra_state_attributes(self): + """List members in group.""" + attributes = {} + if self._group_list: + attributes = {ATTR_BLUESOUND_GROUP: self._group_list} + + attributes[ATTR_MASTER] = self._is_master + + return attributes async def async_join(self, master): """Join the player to a group.""" @@ -934,20 +945,12 @@ async def async_join(self, master): else: _LOGGER.error("Master not found %s", master_device) + # the sleep is needed to make sure that the devices are synced + await asyncio.sleep(1) + # rebuild ordered list of entity_ids that are in the group, master is first await self.async_update_status() - @property - def extra_state_attributes(self): - """List members in group.""" - attributes = {} - if self._group_list: - attributes = {ATTR_BLUESOUND_GROUP: self._group_list} - - attributes[ATTR_MASTER] = self._is_master - - return attributes - async def async_unjoin(self): """Unjoin the player from a group.""" if self._master is None: @@ -956,6 +959,9 @@ async def async_unjoin(self): _LOGGER.debug("Trying to unjoin player: %s", self.id) await self._master.async_remove_slave(self) + # the sleep is needed to make sure that the devices are synced + await asyncio.sleep(1) + # rebuild ordered list of entity_ids that are in the group, master is first await self.async_update_status() @@ -965,6 +971,9 @@ async def async_add_slave(self, slave_device): f"/AddSlave?slave={slave_device.host}&port={slave_device.port}" ) + # the sleep is needed to make sure that the devices are synced + await asyncio.sleep(1) + # rebuild ordered list of entity_ids that are in the group, master is first await self.async_update_status() @@ -976,6 +985,9 @@ async def async_remove_slave(self, slave_device): f"/RemoveSlave?slave={slave_device.host}&port={slave_device.port}" ) + # the sleep is needed to make sure that the devices are synced + await asyncio.sleep(1) + # rebuild ordered list of entity_ids that are in the group, master is first await self.async_update_status() From 079a875ad490b201dbef5519f0597a45447d3e48 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 13:02:50 +0100 Subject: [PATCH 24/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 75eeb9c..3ddb6e2 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -311,11 +311,8 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False if str(device._id) == slave_id + ":" + slave_port: new_device_group.append(device.entity_id) - # Add new group to master and slave - for main_device in self._hass.data[DATA_BLUESOUND]: - for device in new_device_group: - if main_device.entity_id == device: - main_device._group_list = new_device_group + # Add new group to list + self._group_list = new_device_group elif self._sync_status.get("slave") is not None: # Device is a master @@ -350,11 +347,8 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False new_device_group.append(device.entity_id) self._is_master = True - # Add new group to master and slave - for main_device in self._hass.data[DATA_BLUESOUND]: - for device in new_device_group: - if main_device.entity_id == device: - main_device._group_list = new_device_group + # Add new group to list + self._group_list = new_device_group else: self._is_master = False From 10a6930e645cd2d8d4e17ce5aa8cfa43150a2c91 Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 13:07:07 +0100 Subject: [PATCH 25/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 3ddb6e2..1182f59 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -285,7 +285,7 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False new_device_group.append(self._master.entity_id) # Call to get slaves for master - resp_two = await self.send_bluesound_command( + resp_two = await self._master.send_bluesound_command( "SyncStatus", raise_timeout, raise_timeout ) From 1eea5de43c65dae2b7f4e56302a6652f53ab262c Mon Sep 17 00:00:00 2001 From: aunefyren Date: Wed, 31 Jan 2024 13:10:09 +0100 Subject: [PATCH 26/26] Update media_player.py --- custom_components/bluesound_alt/media_player.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/bluesound_alt/media_player.py b/custom_components/bluesound_alt/media_player.py index 1182f59..cc1848f 100644 --- a/custom_components/bluesound_alt/media_player.py +++ b/custom_components/bluesound_alt/media_player.py @@ -943,7 +943,7 @@ async def async_join(self, master): await asyncio.sleep(1) # rebuild ordered list of entity_ids that are in the group, master is first - await self.async_update_status() + await self.async_trigger_sync_on_all() async def async_unjoin(self): """Unjoin the player from a group.""" @@ -957,7 +957,7 @@ async def async_unjoin(self): await asyncio.sleep(1) # rebuild ordered list of entity_ids that are in the group, master is first - await self.async_update_status() + await self.async_trigger_sync_on_all() async def async_add_slave(self, slave_device): """Add slave to master.""" @@ -969,7 +969,7 @@ async def async_add_slave(self, slave_device): await asyncio.sleep(1) # rebuild ordered list of entity_ids that are in the group, master is first - await self.async_update_status() + await self.async_trigger_sync_on_all() return result @@ -983,7 +983,7 @@ async def async_remove_slave(self, slave_device): await asyncio.sleep(1) # rebuild ordered list of entity_ids that are in the group, master is first - await self.async_update_status() + await self.async_trigger_sync_on_all() return result