Skip to content

Commit

Permalink
Sleeps and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
aunefyren committed Jan 31, 2024
1 parent d1037e5 commit 5b0b7cd
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion custom_components/bluesound_alt/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand All @@ -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()

Expand Down

0 comments on commit 5b0b7cd

Please sign in to comment.