dhleong / wemore

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

Added a function to update the status of emulated devices? #17

Closed piznel closed 5 years ago

piznel commented 5 years ago

Hello, Is it possible to add a function to update the status of a virtual device? Because I use your library by coupling it with a home automation application, and that would allow me to be synchronized between Alexa and the application. Thank you!

dhleong commented 5 years ago

You mean just change Wemore's internal state so a "toggle" command sent to it works as expected? There's a property .binaryState on the device instance; just set it to 1 (on) or 0 (off).

piznel commented 5 years ago

thank you for your very quick answer:)

So that means that, using the example of emulated TV in your readme: tv.binaryState = 1 will update the TV status in Alexa?

I also have a small problem with the example you give next:

tv.on('state', function(binaryState, self, sender) {
    console.log("TV set to=", binaryState);
    tv.close(); // stop advertising the device
});

What's the point? I read all your code, but I couldn't find the broadcast of the state event.

Thank you in advance!

dhleong commented 5 years ago

That won't actively update Alexa's status (it doesn't make any network calls) but if Alexa queries the device, it should see it as "on."

The state event is broadcast immediately after on/off. There's no real difference from the normal events, but it is called for both on and off, and you get the raw binary state. In most cases you're probably fine with on and/or off, but state is there for advanced use cases.

piznel commented 5 years ago

Thanks !