panasonic_viera: Provide unique_id from SSDP UDN, if available (#13541)

This commit is contained in:
Ville Skyttä 2018-05-01 20:54:06 +02:00 committed by Paulus Schoutsen
parent 38560cda1c
commit 5d96751168

View File

@ -56,8 +56,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
name = discovery_info.get('name') name = discovery_info.get('name')
host = discovery_info.get('host') host = discovery_info.get('host')
port = discovery_info.get('port') port = discovery_info.get('port')
udn = discovery_info.get('udn')
if udn and udn.startswith('uuid:'):
uuid = udn[len('uuid:'):]
else:
uuid = None
remote = RemoteControl(host, port) remote = RemoteControl(host, port)
add_devices([PanasonicVieraTVDevice(mac, name, remote)]) add_devices([PanasonicVieraTVDevice(mac, name, remote, uuid)])
return True return True
host = config.get(CONF_HOST) host = config.get(CONF_HOST)
@ -70,19 +75,25 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class PanasonicVieraTVDevice(MediaPlayerDevice): class PanasonicVieraTVDevice(MediaPlayerDevice):
"""Representation of a Panasonic Viera TV.""" """Representation of a Panasonic Viera TV."""
def __init__(self, mac, name, remote): def __init__(self, mac, name, remote, uuid=None):
"""Initialize the Panasonic device.""" """Initialize the Panasonic device."""
import wakeonlan import wakeonlan
# Save a reference to the imported class # Save a reference to the imported class
self._wol = wakeonlan self._wol = wakeonlan
self._mac = mac self._mac = mac
self._name = name self._name = name
self._uuid = uuid
self._muted = False self._muted = False
self._playing = True self._playing = True
self._state = STATE_UNKNOWN self._state = STATE_UNKNOWN
self._remote = remote self._remote = remote
self._volume = 0 self._volume = 0
@property
def unique_id(self) -> str:
"""Return the unique ID of this Viera TV."""
return self._uuid
def update(self): def update(self):
"""Retrieve the latest data.""" """Retrieve the latest data."""
try: try: