Skip to content

Commit

Permalink
More optimizations and logging (#3)
Browse files Browse the repository at this point in the history
* Removed sleep

* More logging

* Removed comments/old code
  • Loading branch information
aunefyren authored Feb 3, 2024
1 parent 4111e04 commit 3d889b8
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions custom_components/bluesound_alt/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False
self._group_list = new_device_group

else:
# Device is a master
_LOGGER.debug("Device is independent: %s", self._id)

self._is_master = False
self._master = None
self._group_list = []
Expand Down Expand Up @@ -485,13 +488,6 @@ async def async_update_status(self):
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)

await self.async_trigger_sync_on_all()

if self.is_grouped:
Expand All @@ -502,7 +498,6 @@ async def async_update_status(self):
# the device is playing. This would solve a lot of
# problems. This change will be done when the
# communication is moved to a separate library
await asyncio.sleep(1)
await self.force_update_sync_status()

self.async_write_ha_state()
Expand Down Expand Up @@ -922,6 +917,9 @@ def extra_state_attributes(self):

async def async_join(self, master):
"""Join the player to a group."""

_LOGGER.debug("Device '%s' joining master '%s'.", self._id, master)

master_device = [
device
for device in self.hass.data[DATA_BLUESOUND]
Expand All @@ -939,8 +937,7 @@ 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)
_LOGGER.debug("Syncing all devices.")

# rebuild ordered list of entity_ids that are in the group, master is first
await self.async_trigger_sync_on_all()
Expand All @@ -949,24 +946,25 @@ async def async_unjoin(self):
"""Unjoin the player from a group."""
if self._master is None:
return

_LOGGER.debug("Trying to unjoin player: %s", self.id)
_LOGGER.debug("Trying to unjoin player from group: %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)
_LOGGER.debug("Syncing all devices.")

# rebuild ordered list of entity_ids that are in the group, master is first
await self.async_trigger_sync_on_all()

async def async_add_slave(self, slave_device):
"""Add slave to master."""

_LOGGER.debug("Master '%s' is adding slave '%s'.", self._id, slave_device._id)

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 are synced
await asyncio.sleep(1)
_LOGGER.debug("Syncing all devices.")

# rebuild ordered list of entity_ids that are in the group, master is first
await self.async_trigger_sync_on_all()
Expand All @@ -975,12 +973,14 @@ async def async_add_slave(self, slave_device):

async def async_remove_slave(self, slave_device):
"""Remove slave to master."""

_LOGGER.debug("Master '%s' is removing slave '%s'.", self._id, slave_device._id)

result = await self.send_bluesound_command(
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)
_LOGGER.debug("Syncing all devices.")

# rebuild ordered list of entity_ids that are in the group, master is first
await self.async_trigger_sync_on_all()
Expand Down

0 comments on commit 3d889b8

Please sign in to comment.