From a02840379d56999a1755fb5dad952e92a091399a Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 1 Mar 2016 10:49:38 -0800 Subject: [PATCH] Track WeMo devices by serial number This makes us track WeMo devices by serial number instead of URL. Per @jaharkes' suggestion, tracking via URL could potentially be a problem if a device changes to another IP and then appears to be discovered again. Since we can't track based on mac (for static-configured devices), we can use the serial number exposed to make sure we're always looking at a list of unique devices. --- homeassistant/components/wemo.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/wemo.py b/homeassistant/components/wemo.py index e6fc88bea1a..35603b21d64 100644 --- a/homeassistant/components/wemo.py +++ b/homeassistant/components/wemo.py @@ -58,12 +58,13 @@ def setup(hass, config): def discovery_dispatch(service, discovery_info): """Dispatcher for WeMo discovery events.""" # name, model, location, mac - _, model_name, url, _ = discovery_info + _, model_name, _, _, serial = discovery_info # Only register a device once - if url in KNOWN_DEVICES: + if serial in KNOWN_DEVICES: return - KNOWN_DEVICES.append(url) + _LOGGER.debug('Discovered unique device %s', serial) + KNOWN_DEVICES.append(serial) service = WEMO_MODEL_DISPATCH.get(model_name) or DISCOVER_SWITCHES component = WEMO_SERVICE_DISPATCH.get(service) @@ -91,6 +92,7 @@ def setup(hass, config): if device is None: device = pywemo.discovery.device_from_description(url, None) - discovery_info = (device.name, device.model_name, url, device.mac) + discovery_info = (device.name, device.model_name, url, device.mac, + device.serialnumber) discovery.discover(hass, discovery.SERVICE_WEMO, discovery_info) return True