Created
July 16, 2016 18:48
-
-
Save thesephist/d0dc82ab24a24a4f6e217bf4c6270ea4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var request = require('request'); | |
var given = process.argv.splice(2); | |
function command(args) { | |
var payload = {}; | |
if (args[0]) payload.power = args[0]; | |
if (parseFloat(args[1])) payload.brightness = parseFloat(args[1]); | |
if (args[2]) payload.color = args[2]; | |
if (parseFloat(args[3])) payload.duration = parseFloat(args[3]); | |
request({ | |
uri: "https://api.lifx.com/v1/lights/all/state", // custom selectors? | |
method: "PUT", | |
headers: { | |
"Authorization": "Bearer lifx_api_token" | |
}, | |
json: true, | |
body: payload | |
}, function(err, res, body) { | |
if (given.indexOf("verbose") > -1) console.log(body); | |
}); | |
}; | |
if ( | |
(given[0] == "off" || given[0] == "on") | |
&& ((parseFloat(given[1]) < 1 && parseFloat(given[1]) > 0) || !given[1] ) | |
&& (typeof given[2] === "string" || !given[2]) | |
&& (typeof parseFloat(given[3]) === "number" || !given[3]) | |
) { | |
command(given); | |
} else { | |
console.log("lux [on|off] [0-1] [color] [seconds] [verbose (optional)]"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment