diff --git a/homeassistant/components/sonos/manifest.json b/homeassistant/components/sonos/manifest.json index 4e65edc1f5b..8c231ec63e0 100644 --- a/homeassistant/components/sonos/manifest.json +++ b/homeassistant/components/sonos/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/components/sonos", "requirements": [ - "pysonos==0.0.22" + "pysonos==0.0.23" ], "dependencies": [], "ssdp": { diff --git a/homeassistant/components/sonos/media_player.py b/homeassistant/components/sonos/media_player.py index 38ae99f2d3f..a4d461f289f 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -102,6 +102,7 @@ class SonosData: def __init__(self, hass): """Initialize the data.""" self.entities = [] + self.discovered = [] self.topology_condition = asyncio.Condition() @@ -132,14 +133,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities): """Handle a (re)discovered player.""" try: _LOGGER.debug("Reached _discovered_player, soco=%s", soco) - entity = _get_entity_from_soco_uid(hass, soco.uid) - if not entity: + if soco not in hass.data[DATA_SONOS].discovered: _LOGGER.debug("Adding new entity") + hass.data[DATA_SONOS].discovered.append(soco) hass.add_job(async_add_entities, [SonosEntity(soco)]) else: - _LOGGER.debug("Seen %s", entity) - hass.add_job(entity.async_seen()) + entity = _get_entity_from_soco_uid(hass, soco.uid) + if entity: + _LOGGER.debug("Seen %s", entity) + hass.add_job(entity.async_seen()) except SoCoException as ex: _LOGGER.debug("SoCoException, ex=%s", ex) @@ -222,7 +225,10 @@ class _ProcessSonosEventQueue: def put(self, item, block=True, timeout=None): """Process event.""" - self._handler(item) + try: + self._handler(item) + except SoCoException as ex: + _LOGGER.warning("Error calling %s: %s", self._handler, ex) def _get_entity_from_soco_uid(hass, uid): @@ -318,7 +324,7 @@ class SonosEntity(MediaPlayerDevice): self._night_sound = None self._speech_enhance = None self._source_name = None - self._favorites = None + self._favorites = [] self._soco_snapshot = None self._snapshot_group = None @@ -748,6 +754,8 @@ class SonosEntity(MediaPlayerDevice): @property def volume_level(self): """Volume level of the media player (0..1).""" + if self._player_volume is None: + return None return self._player_volume / 100 @property diff --git a/requirements_all.txt b/requirements_all.txt index 36855c23bf1..044552371ea 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1404,7 +1404,7 @@ pysmarty==0.8 pysnmp==4.4.9 # homeassistant.components.sonos -pysonos==0.0.22 +pysonos==0.0.23 # homeassistant.components.spc pyspcwebgw==0.4.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c447e5cb289..dac3562bf79 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -316,7 +316,7 @@ pysmartapp==0.3.2 pysmartthings==0.6.9 # homeassistant.components.sonos -pysonos==0.0.22 +pysonos==0.0.23 # homeassistant.components.spc pyspcwebgw==0.4.0