jimmywarting / wemo-client

JavaScript client library for controlling and subscribing to Wemo Devices
MIT License
132 stars 40 forks source link

Provide example on how to use it with Wemo Light #1

Closed timonreinhard closed 9 years ago

cbrake commented 9 years ago

Hi -- thanks for the excellent library. I'm experimenting with it some, and I see statusChange events when I turn a Wemo light on/off:

statusChange 94103EF6BF427B58 10006 0
statusChange 94103EF6BF427B58 30008 0:0
statusChange 94103EF6BF427B58 10008 255:0
statusChange 94103EF6BF427B58 10006 1

Is there any way to "discover" the lights attached to the system, or do we need to toggle the light states using a wemo phone app, note the deviceId, and then use it?

Thanks!

timonreinhard commented 9 years ago

Hi Cliff,

thanks for providing feedback. The yet undocumented client.getEndDevices(cb) is what you're looking for. I'll provide docs and an example later on.

Cheers. Timon

cbrake commented 9 years ago

Hi Timon,

Thanks -- I gave it a try. Works pretty well, but only reports one of my two lights. Poking into the XML a little, it looks like there are multiple DeviceLists:

<?xml version="1.0" encoding="utf-8"?><DeviceLists><DeviceList><DeviceListType>Paired</DeviceListType><DeviceInfos><DeviceInfo><DeviceIndex>0</DeviceIndex><DeviceID>94103EF6BF421ADA</DeviceID><FriendlyName>office</FriendlyName><IconVersion>1</IconVersion><FirmwareVersion>7E</FirmwareVersion><CapabilityIDs>10006,10008,30008,30009,3000A</CapabilityIDs><CurrentState>1,255:0,0:0,,</CurrentState><Manufacturer>MRVL</Manufacturer><ModelCode>MZ100</ModelCode><WeMoCertified>YES</WeMoCertified></DeviceInfo><DeviceInfo><DeviceIndex>1</DeviceIndex><DeviceID>94103EF6BF427B58</DeviceID><FriendlyName>school</FriendlyName><IconVersion>1</IconVersion><FirmwareVersion>7E</FirmwareVersion><CapabilityIDs>10006,10008,30008,30009,3000A</CapabilityIDs><CurrentState>1,255:0,0:0,,</CurrentState><Manufacturer>MRVL</Manufacturer><ModelCode>MZ100</ModelCode><WeMoCertified>YES</WeMoCertified></DeviceInfo></DeviceInfos></DeviceList></DeviceLists>

I'm out of time today, but will try to work on it some more at some point.

Thanks, Cliff

timonreinhard commented 9 years ago

The bug you mentioned should be resolved now. Thanks for providing the XML, that helped a lot fixing it.

Please note that I also changed the behavior of client.getEndDevices a bit – it now calls the callback only a single time and passes an array of found devices:

client.getEndDevices(function(err, endDevices) {
  if (!err) {
    console.log(endDevices.length + ' bulbs found');
    console.log(endDevices);
  }
});
cbrake commented 9 years ago

works great -- thanks!