Skip to content

Commit 3d889b8

Browse files
authored
More optimizations and logging (#3)
* Removed sleep * More logging * Removed comments/old code
1 parent 4111e04 commit 3d889b8

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

custom_components/bluesound_alt/media_player.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ async def force_update_sync_status(self, on_updated_cb=None, raise_timeout=False
351351
self._group_list = new_device_group
352352

353353
else:
354+
# Device is a master
355+
_LOGGER.debug("Device is independent: %s", self._id)
356+
354357
self._is_master = False
355358
self._master = None
356359
self._group_list = []
@@ -485,13 +488,6 @@ async def async_update_status(self):
485488
group_name = self._status.get("groupName")
486489
self._group_name = group_name
487490

488-
# rebuild ordered list of entity_ids that are in the group, master is first
489-
# self._group_list = await self.rebuild_bluesound_group()
490-
491-
# the sleep is needed to make sure that the
492-
# devices is synced
493-
# await asyncio.sleep(1)
494-
495491
await self.async_trigger_sync_on_all()
496492

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

508503
self.async_write_ha_state()
@@ -922,6 +917,9 @@ def extra_state_attributes(self):
922917

923918
async def async_join(self, master):
924919
"""Join the player to a group."""
920+
921+
_LOGGER.debug("Device '%s' joining master '%s'.", self._id, master)
922+
925923
master_device = [
926924
device
927925
for device in self.hass.data[DATA_BLUESOUND]
@@ -939,8 +937,7 @@ async def async_join(self, master):
939937
else:
940938
_LOGGER.error("Master not found %s", master_device)
941939

942-
# the sleep is needed to make sure that the devices are synced
943-
await asyncio.sleep(1)
940+
_LOGGER.debug("Syncing all devices.")
944941

945942
# rebuild ordered list of entity_ids that are in the group, master is first
946943
await self.async_trigger_sync_on_all()
@@ -949,24 +946,25 @@ async def async_unjoin(self):
949946
"""Unjoin the player from a group."""
950947
if self._master is None:
951948
return
952-
953-
_LOGGER.debug("Trying to unjoin player: %s", self.id)
949+
950+
_LOGGER.debug("Trying to unjoin player from group: %s", self.id)
954951
await self._master.async_remove_slave(self)
955952

956-
# the sleep is needed to make sure that the devices are synced
957-
await asyncio.sleep(1)
953+
_LOGGER.debug("Syncing all devices.")
958954

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

962958
async def async_add_slave(self, slave_device):
963959
"""Add slave to master."""
960+
961+
_LOGGER.debug("Master '%s' is adding slave '%s'.", self._id, slave_device._id)
962+
964963
result = await self.send_bluesound_command(
965964
f"/AddSlave?slave={slave_device.host}&port={slave_device.port}"
966965
)
967966

968-
# the sleep is needed to make sure that the devices are synced
969-
await asyncio.sleep(1)
967+
_LOGGER.debug("Syncing all devices.")
970968

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

976974
async def async_remove_slave(self, slave_device):
977975
"""Remove slave to master."""
976+
977+
_LOGGER.debug("Master '%s' is removing slave '%s'.", self._id, slave_device._id)
978+
978979
result = await self.send_bluesound_command(
979980
f"/RemoveSlave?slave={slave_device.host}&port={slave_device.port}"
980981
)
981982

982-
# the sleep is needed to make sure that the devices are synced
983-
await asyncio.sleep(1)
983+
_LOGGER.debug("Syncing all devices.")
984984

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

0 commit comments

Comments
 (0)