Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sonos device attribute with grouping information #13553

Merged
merged 2 commits into from
Apr 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions homeassistant/components/media_player/sonos.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
ATTR_NIGHT_SOUND = 'night_sound'
ATTR_SPEECH_ENHANCE = 'speech_enhance'

ATTR_IS_COORDINATOR = 'is_coordinator'
ATTR_SONOS_GROUP = 'sonos_group'

UPNP_ERRORS_TO_IGNORE = ['701', '711']

Expand Down Expand Up @@ -340,6 +340,7 @@ def __init__(self, player):
self._play_mode = None
self._name = None
self._coordinator = None
self._sonos_group = None
self._status = None
self._media_duration = None
self._media_position = None
Expand Down Expand Up @@ -688,14 +689,22 @@ def update_groups(self, event=None):
if p.uid != 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._sonos_group = sonos_group
self.schedule_update_ha_state()

for slave_uid in slave_uids:
slave = _get_entity_from_soco_uid(self.hass, slave_uid)
if slave:
# pylint: disable=protected-access
slave._coordinator = self
slave._sonos_group = sonos_group
slave.schedule_update_ha_state()

@property
Expand Down Expand Up @@ -1038,7 +1047,7 @@ def set_option(self, **data):
@property
def device_state_attributes(self):
"""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:
attributes[ATTR_NIGHT_SOUND] = self._night_sound
Expand Down