homebridge-plugins / node-arlo

JS library for Arlo Cameras
17 stars 15 forks source link

Callback for login and getdevices #1

Closed danroot closed 7 years ago

danroot commented 7 years ago

This is great code for a very tricky API - I'm tinkering with it here https://glitch.com/edit/#!/rootshiregarden , with the goal of adding the missing timelapse feature to my Arlo setup ;) I'm finding that sometimes arlo.devices is not "filled" depending on how quickly I call .devices after login. One thing that would be helpful (I think, correct me if I'm using it incorrectly) is a callback on login and ensuring callback gets called in getdevices. This would allow us to be sure getdevices has completed before continuing :

arlo.login(username,password,function(err,res,data){ if(!err) doStuffWithDevices(arlo.devices); })

I think this would be a matter of changing line 54 of Arlo.js to login(username,password, callback) and adding this in getDevices around line 49 and 66:

if (callback) callback(err,res,data);

I think this wouldn't break any existing code that works. I can try to do a PR if you'd like.

devbobo commented 7 years ago

@danroot I'm glad someone is using this :)

See if this works for you, otherwise I'm more than happy to add the callback.

A "found" event is broadcast whenever a new device is discovered. This works for me in my implementation of a homebridge plugin, but may not work in your situation.

Here's some sample code... https://github.com/devbobo/homebridge-arlo/blob/master/index.js#L66

Let me know 👍

danroot commented 7 years ago

Thanks for your help! I was able to make that work.