Skip to content
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
25 changes: 18 additions & 7 deletions homeassistant/components/media_player/snapcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ def _handle_service(service):
host, port)
return

groups = [SnapcastGroupDevice(group) for group in server.groups]
clients = [SnapcastClientDevice(client) for client in server.clients]
# Note: Host part is needed, when using multiple snapservers
hpid = '{}:{}'.format(host, port)

groups = [SnapcastGroupDevice(group, hpid) for group in server.groups]
clients = [SnapcastClientDevice(client, hpid) for client in server.clients]
devices = groups + clients
hass.data[DATA_KEY] = devices
async_add_devices(devices)
Expand All @@ -90,10 +93,12 @@ def _handle_service(service):
class SnapcastGroupDevice(MediaPlayerDevice):
"""Representation of a Snapcast group device."""

def __init__(self, group):
def __init__(self, group, uid_part):
"""Initialize the Snapcast group device."""
group.set_callback(self.schedule_update_ha_state)
self._group = group
self._uid = '{}{}_{}'.format(GROUP_PREFIX, uid_part,
self._group.identifier)

@property
def state(self):
Expand All @@ -107,7 +112,7 @@ def state(self):
@property
def unique_id(self):
"""Return the ID of snapcast group."""
return '{}{}'.format(GROUP_PREFIX, self._group.identifier)
return self._uid

@property
def name(self):
Expand Down Expand Up @@ -185,15 +190,21 @@ def async_restore(self):
class SnapcastClientDevice(MediaPlayerDevice):
"""Representation of a Snapcast client device."""

def __init__(self, client):
def __init__(self, client, uid_part):
"""Initialize the Snapcast client device."""
client.set_callback(self.schedule_update_ha_state)
self._client = client
self._uid = '{}{}_{}'.format(CLIENT_PREFIX, uid_part,
self._client.identifier)

@property
def unique_id(self):
"""Return the ID of this snapcast client."""
return '{}{}'.format(CLIENT_PREFIX, self._client.identifier)
"""
Return the ID of this snapcast client.

Note: Host part is needed, when using multiple snapservers
"""
return self._uid

@property
def name(self):
Expand Down