Skip to content

Commit

Permalink
Fix snapcast uuid to be more unique (#14925)
Browse files Browse the repository at this point in the history
Current uuid is ok when using only 1 snapserver
New uuid is needed when using multiple snapserver

Because the client can connect to more snapservers and
then uuid based on client MAC is not enough
  • Loading branch information
jedi7 authored and MartinHjelmare committed Jun 12, 2018
1 parent 6755ae2 commit 89d008d
Showing 1 changed file with 18 additions and 7 deletions.
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

0 comments on commit 89d008d

Please sign in to comment.