mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Prevent devices from being discovered twice
This commit is contained in:
parent
9db1a58cb1
commit
c2b8f8d34e
@ -113,6 +113,11 @@ def media_prev_track(hass, entity_id=None):
|
||||
|
||||
def setup_chromecast(casts, host):
|
||||
""" Tries to convert host to Chromecast object and set it up. """
|
||||
|
||||
# Check if already setup
|
||||
if any(cast.host == host for cast in casts.values()):
|
||||
return
|
||||
|
||||
try:
|
||||
cast = pychromecast.PyChromecast(host)
|
||||
|
||||
|
@ -81,6 +81,12 @@ class HueLight(ToggleDevice):
|
||||
""" Get the mame of the Hue light. """
|
||||
return self.info['name']
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns the id of this Hue light """
|
||||
return "{}.{}".format(
|
||||
self.__class__, self.info.get('uniqueid', self.get_name()))
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
""" Turn the specified or all lights on. """
|
||||
command = {'on': True}
|
||||
|
@ -86,7 +86,7 @@ def setup(hass, config):
|
||||
|
||||
switch = platform.device_discovered(hass, config, info)
|
||||
|
||||
if switch is not None:
|
||||
if switch is not None and switch not in switches.values():
|
||||
switch.entity_id = util.ensure_unique_string(
|
||||
ENTITY_ID_FORMAT.format(util.slugify(switch.get_name())),
|
||||
switches.keys())
|
||||
|
@ -59,6 +59,11 @@ class WemoSwitch(ToggleDevice):
|
||||
def __init__(self, wemo):
|
||||
self.wemo = wemo
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns the id of this WeMo switch """
|
||||
return "{}.{}".format(self.__class__, self.wemo.serialnumber)
|
||||
|
||||
def get_name(self):
|
||||
""" Returns the name of the switch if any. """
|
||||
return self.wemo.name
|
||||
|
@ -146,9 +146,6 @@ def platform_devices_from_config(config, domain, hass,
|
||||
|
||||
devices.extend(p_devices)
|
||||
|
||||
if len(devices) == 0:
|
||||
logger.error("No devices found for %s", domain)
|
||||
|
||||
# Setup entity IDs for each device
|
||||
no_name_count = 1
|
||||
|
||||
@ -177,6 +174,11 @@ class Device(object):
|
||||
|
||||
entity_id = None
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
""" Returns a unique id. """
|
||||
return "{}.{}".format(self.__class__, id(self))
|
||||
|
||||
def get_name(self):
|
||||
""" Returns the name of the device if any. """
|
||||
return "No Name"
|
||||
@ -208,6 +210,10 @@ class Device(object):
|
||||
return hass.states.set(self.entity_id, self.get_state(),
|
||||
self.get_state_attributes())
|
||||
|
||||
def __eq__(self, other):
|
||||
return (isinstance(other, Device) and
|
||||
other.unique_id == self.unique_id)
|
||||
|
||||
|
||||
class ToggleDevice(Device):
|
||||
""" ABC for devices that can be turned on and off. """
|
||||
|
Loading…
x
Reference in New Issue
Block a user