diff --git a/drivers/SmartThings/wemo/src/discovery.lua b/drivers/SmartThings/wemo/src/discovery.lua index 84f1c9643c..f6fc422313 100644 --- a/drivers/SmartThings/wemo/src/discovery.lua +++ b/drivers/SmartThings/wemo/src/discovery.lua @@ -59,7 +59,8 @@ local function fetch_device_metadata(url) return { name = tablefind(parsed_xml, "root.device.friendlyName"), - model = tablefind(parsed_xml, "root.device.modelName") + model = tablefind(parsed_xml, "root.device.modelName"), + mac = tablefind(parsed_xml, "root.device.macAddress") } end @@ -103,7 +104,12 @@ local function find(deviceid, callback) if val then local headers = process_response(val) local ip, port = headers["location"]:match("http://([^,/]+):([^/]+)") - local id = headers["usn"] + -- local id = headers["usn"] --instead of usn, we need to use mac as id (to handle migration scenario) + local meta = fetch_device_metadata(headers["location"]) + if not meta then + meta = {} + end + local id = meta.mac log.trace("discovery response from:", rip, headers["usn"]) @@ -114,11 +120,11 @@ local function find(deviceid, callback) ids_found[id] = true number_found = number_found + 1 - local meta = fetch_device_metadata(headers["location"]) + -- local meta = fetch_device_metadata(headers["location"]) - if not meta then - meta = {} - end + -- if not meta then + -- meta = {} + -- end -- the ID in the response is a substring of the search ID, check if they match (if search ID set) local is_correct_responder = deviceid and string.find(deviceid, id, nil, "plaintext")