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

update to new hue-js interface, storing username token in config file #14

Merged
merged 5 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions hue-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,20 @@ switch (args[0]) {
case 'register': // register this app
client = getclient();
console.log('please go and press the link button on your base station');
client.register(function(err) {
client.register(function(err, resp) {
if (err) {
console.error('failed to pair to Hue Base Station %s', config.host);
throw err;
}

console.log('Hue Base Station paired!')
console.log('username: ' + resp[0].success.username);
config.username = resp[0].success.username;

// writing config file
var s = JSON.stringify(config, null, 2);
Copy link
Owner

@bahamas10 bahamas10 Sep 21, 2016

Choose a reason for hiding this comment

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

I didn't realize hue-cli had as large of a community as it did (thanks everyone!) so I'm interested in gathering insight from everyone. My only concern with this is, when a user runs hue register it will clobber their existing config file without passing the --save option. Admittedly, the --save function currently operates in a less-than-ideal way.

My current proposal would be to drop the --save functionality completely, and make it so hue register will automatically write out the config IF ONE DOES NOT ALREADY EXIST. If one exists, hue register should print a warning, dump the current config, and exit non-zero, and leave it up to the user to remove it before registering a new bridge. What do you all think of that?

Either way though, I'm currently 👍 on this change and appreciate the small diff!

addendum: if you all like this idea, i wouldn't mind merging this as-is and making the code do what i described in a second commit

fs.writeFileSync(configfile, s + '\n');
console.log('config file written to `%s`', configfile);
});
break;
case 'search': // search for base stations
Expand Down Expand Up @@ -290,7 +298,8 @@ function getclient() {
// create the client
var client = Hue.createClient({
stationIp: config.host,
appName: app
appName: app,
username: config.username
});
return client;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"posix-getopt": "~1.0.0",
"hue.js": "https://github.com/bahamas10/hue.js/tarball/dave-1432672068",
"hue.js": "https://github.com/bahamas10/hue.js/tarball/master",
"latest": "~0.1.1",
"css-color-names": "0.0.0",
"extsprintf": "~1.0.2"
Expand Down