dhleong / wemore

A more awesome library for Belkin WeMo interactions
37 stars 11 forks source link

EmulatedDevice.close doesn't remove the device from the SSDP SERVER #10

Closed biddster closed 7 years ago

biddster commented 7 years ago

From what I can see, if I call close on a device, the device doesn't get removed from the SERVER within emulate.js and it still discoverable.

I'm using wemore within node-red-contrib-wemo-emulator and when I reconfigure my node-red node, I close the EmulatedDevice and create a new one. However, as the device isn't removed from the SERVER, the callbacks for the first device are always executed, not the second one.

dhleong commented 7 years ago

Good catch. Released a fix as 0.4.3—let me know if that doesn't resolve the issue.

biddster commented 7 years ago

Wow, mega fast.

I think that has helped. But it still doesn't appear to rebind the socket so the closure that gets called for 'on' is still the original closure before I called stop, not the closure I supplied when calling emulate again.

dhleong commented 7 years ago

Hmm... I admit I haven't spent a lot of time with this code in some time, but I can't seem to reproduce that issue. Using a very dumb script:


var wemore = require('.');

var test = wemore.Emulate({friendlyName: "Test"})
.on('on', function() {
    console.log("original.on");

    test.close();

    var test2 = wemore.Emulate({friendlyName: "Test"})
    .on('on', function() {
        console.log("2.on");
    });
});

Two sequential calls to wemore-toggle Test cause this script to print the expected original.on followed by 2.on. I also threw together a quick search script to verify that the location on the Test device has changed between these, which it does—the old http server no longer appears to be advertised, and should be stopped by the call to close().

I'm not sure how the original device's events could be triggered unless the http server was somehow still open, which suggests to me that close() isn't actually getting called....

Do you have a minimal example that can reproduce the issue you're seeing?

biddster commented 7 years ago

Thanks @dhleong, let me work up a few cases over the weekend and see if I can get to the bottom of it. Probably user error :-)

biddster commented 7 years ago

Forgot to link to my source code @dhleong, this is how I'm using it. https://github.com/biddster/node-red-contrib-wemo-emulator/blob/develop/index.js