Add Sonos device attribute with grouping information (#13553)

This commit is contained in:
Anders Melchiorsen 2018-04-25 20:31:42 +02:00 committed by GitHub
parent a94864c86f
commit 241a0793bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,7 +67,7 @@ ATTR_WITH_GROUP = 'with_group'
ATTR_NIGHT_SOUND = 'night_sound' ATTR_NIGHT_SOUND = 'night_sound'
ATTR_SPEECH_ENHANCE = 'speech_enhance' ATTR_SPEECH_ENHANCE = 'speech_enhance'
ATTR_IS_COORDINATOR = 'is_coordinator' ATTR_SONOS_GROUP = 'sonos_group'
UPNP_ERRORS_TO_IGNORE = ['701', '711'] UPNP_ERRORS_TO_IGNORE = ['701', '711']
@ -340,6 +340,7 @@ class SonosDevice(MediaPlayerDevice):
self._play_mode = None self._play_mode = None
self._name = None self._name = None
self._coordinator = None self._coordinator = None
self._sonos_group = None
self._status = None self._status = None
self._media_duration = None self._media_duration = None
self._media_position = None self._media_position = None
@ -688,7 +689,14 @@ class SonosDevice(MediaPlayerDevice):
if p.uid != coordinator_uid] if p.uid != coordinator_uid]
if self.unique_id == coordinator_uid: if self.unique_id == coordinator_uid:
sonos_group = []
for uid in (coordinator_uid, *slave_uids):
entity = _get_entity_from_soco_uid(self.hass, uid)
if entity:
sonos_group.append(entity.entity_id)
self._coordinator = None self._coordinator = None
self._sonos_group = sonos_group
self.schedule_update_ha_state() self.schedule_update_ha_state()
for slave_uid in slave_uids: for slave_uid in slave_uids:
@ -696,6 +704,7 @@ class SonosDevice(MediaPlayerDevice):
if slave: if slave:
# pylint: disable=protected-access # pylint: disable=protected-access
slave._coordinator = self slave._coordinator = self
slave._sonos_group = sonos_group
slave.schedule_update_ha_state() slave.schedule_update_ha_state()
@property @property
@ -1038,7 +1047,7 @@ class SonosDevice(MediaPlayerDevice):
@property @property
def device_state_attributes(self): def device_state_attributes(self):
"""Return device specific state attributes.""" """Return device specific state attributes."""
attributes = {ATTR_IS_COORDINATOR: self.is_coordinator} attributes = {ATTR_SONOS_GROUP: self._sonos_group}
if self._night_sound is not None: if self._night_sound is not None:
attributes[ATTR_NIGHT_SOUND] = self._night_sound attributes[ATTR_NIGHT_SOUND] = self._night_sound