Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added simple LIFX example #2

Merged
merged 2 commits into from
May 1, 2017
Merged

Added simple LIFX example #2

merged 2 commits into from
May 1, 2017

Conversation

GeertWille
Copy link

I quickly wrote an extra example to show off how easy it is to attach new devices with the SDK. This one integrates a basic example of an LIFX light. I still have like the very first model that came out but I think it will work with any version. Enjoy!

Copy link
Contributor

@neophob neophob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you @GeerWille for your PR! There are some minor updates - but else it looks good to me!

* Quick example for an LIFX light wrote by Geert Wille
*/

'use strict';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use strict should be at the first line of the file

const BluePromise = require('bluebird');

let lifx = require('lifx-http-api');
let client = new lifx({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lifx and client should be a const, they will never change

*/
module.exports.onPulse = function (deviceId, name) {
// Just randomly pulse the light
client.pulse('id:' + name, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 'id:' + name correct here?

can you make a helper function to get device selector, for example

function getLifxDeviceSelector(deviceId) {
  return 'id:' + deviceId;
}

this would make the code much more readable

* Discover all LIFX lights and return them in the proper format
*/
module.exports.discoverLIFX = function discoverLIFX() {
return client.listLights('all')
Copy link
Contributor

@neophob neophob Apr 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make a const for 'all' like:

const LIFX_ALL_DEVICES_SELECTOR = 'all';

so it's much more readable

@neophob
Copy link
Contributor

neophob commented Apr 30, 2017

About the bearerToken - is it possible to request the token programatically (for a future revision)?

@neophob
Copy link
Contributor

neophob commented May 1, 2017

Hi @GeertWille again, I just tested your implementation, some feedback:

  • I had to update the bulb to the latest firmware and enable the cloud lookup feature in the LIFX app itself to make it usable. What do you think, does it make sense to add this hint to the discovery page?
  • what do you think about adding adding a "All Lights Off" button?

@GeertWille
Copy link
Author

@neophob Changed everything as request above I think.

  • Requesting the token by oAuth2 is not possible yet in the API version of LIFX or you need to contact them to make it possible and partner up with LIFX
  • Wrote a note on discovery about the need to be authenticated in the app before using it with NEEO
  • Added an all off button

I also think there is a small mistake in the SDK. The function called with the addButtonHander has its parameters inverted. The first param is name and the second one deviceId. I think it should be switched around since most of the calls have deviceId first but If you think it shouldn't then the 2 examples should be changed. :)

@neophob neophob merged commit 041b84a into NEEOInc:master May 1, 2017
@neophob
Copy link
Contributor

neophob commented May 1, 2017

Hi @GeertWille
Thanks for that! will take a look at the reported parameter switch.

BR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants