mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Squeezebox Fix duplicate server from discovery (#12063)
* Fix duplicate server from discovery * Use hass.data instead of global * Simplify
This commit is contained in:
parent
e9508405bc
commit
81a6178931
@ -47,6 +47,8 @@ SERVICE_CALL_METHOD = 'squeezebox_call_method'
|
|||||||
|
|
||||||
DATA_SQUEEZEBOX = 'squeezebox'
|
DATA_SQUEEZEBOX = 'squeezebox'
|
||||||
|
|
||||||
|
KNOWN_SERVERS = 'squeezebox_known_servers'
|
||||||
|
|
||||||
ATTR_PARAMETERS = 'parameters'
|
ATTR_PARAMETERS = 'parameters'
|
||||||
|
|
||||||
SQUEEZEBOX_CALL_METHOD_SCHEMA = MEDIA_PLAYER_SCHEMA.extend({
|
SQUEEZEBOX_CALL_METHOD_SCHEMA = MEDIA_PLAYER_SCHEMA.extend({
|
||||||
@ -67,6 +69,10 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
"""Set up the squeezebox platform."""
|
"""Set up the squeezebox platform."""
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
known_servers = hass.data.get(KNOWN_SERVERS)
|
||||||
|
if known_servers is None:
|
||||||
|
hass.data[KNOWN_SERVERS] = known_servers = set()
|
||||||
|
|
||||||
if DATA_SQUEEZEBOX not in hass.data:
|
if DATA_SQUEEZEBOX not in hass.data:
|
||||||
hass.data[DATA_SQUEEZEBOX] = []
|
hass.data[DATA_SQUEEZEBOX] = []
|
||||||
|
|
||||||
@ -92,6 +98,10 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
"Could not communicate with %s:%d: %s", host, port, error)
|
"Could not communicate with %s:%d: %s", host, port, error)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if ipaddr in known_servers:
|
||||||
|
return
|
||||||
|
|
||||||
|
known_servers.add(ipaddr)
|
||||||
_LOGGER.debug("Creating LMS object for %s", ipaddr)
|
_LOGGER.debug("Creating LMS object for %s", ipaddr)
|
||||||
lms = LogitechMediaServer(hass, host, port, username, password)
|
lms = LogitechMediaServer(hass, host, port, username, password)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user