Fix race during initial Sonos group construction (#26371)

* Fix race during initial Sonos group construction

* Update homeassistant/components/sonos/media_player.py
pull/26379/head
Anders Melchiorsen 2019-09-03 14:14:33 +02:00 committed by Pascal Vizeli
parent 617133e465
commit 3534b8a977
1 changed files with 8 additions and 4 deletions

View File

@ -337,8 +337,16 @@ class SonosEntity(MediaPlayerDevice):
async def async_added_to_hass(self):
"""Subscribe sonos events."""
await self.async_seen()
self.hass.data[DATA_SONOS].entities.append(self)
def _rebuild_groups():
"""Build the current group topology."""
for entity in self.hass.data[DATA_SONOS].entities:
entity.update_groups()
self.hass.async_add_executor_job(_rebuild_groups)
@property
def unique_id(self):
"""Return a unique ID."""
@ -469,10 +477,6 @@ class SonosEntity(MediaPlayerDevice):
self.update_volume()
self._set_favorites()
# New player available, build the current group topology
for entity in self.hass.data[DATA_SONOS].entities:
entity.update_groups()
player = self.soco
def subscribe(service, action):