-
Notifications
You must be signed in to change notification settings - Fork 20
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
Improved the interactive-cli #28
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,11 +274,13 @@ Light.prototype.getFirmwareVersion = function(callback) { | |
return callback(err, null); | ||
} | ||
callback(null, pick(msg, [ | ||
'build', | ||
'majorVersion', | ||
'minorVersion' | ||
])); | ||
}, sqnNumber); | ||
}; | ||
Light.prototype.getHostFirmware = Light.prototype.getFirmwareVersion; | ||
|
||
/** | ||
* Requests infos from the microcontroller unit of the light | ||
|
@@ -297,10 +299,12 @@ Light.prototype.getFirmwareInfo = function(callback) { | |
callback(null, pick(msg, [ | ||
'signal', | ||
'tx', | ||
'rx' | ||
'rx', | ||
'mcuTemperature' | ||
])); | ||
}, sqnNumber); | ||
}; | ||
Light.prototype.getHostInfo = Light.prototype.getFirmwareInfo; | ||
|
||
/** | ||
* Requests wifi infos from for the light | ||
|
@@ -319,7 +323,8 @@ Light.prototype.getWifiInfo = function(callback) { | |
callback(null, pick(msg, [ | ||
'signal', | ||
'tx', | ||
'rx' | ||
'rx', | ||
'mcuTemperature' | ||
])); | ||
}, sqnNumber); | ||
}; | ||
|
@@ -329,7 +334,7 @@ Light.prototype.getWifiInfo = function(callback) { | |
* @param {Function} callback a function to accept the data | ||
*/ | ||
Light.prototype.getWifiVersion = function(callback) { | ||
validate.callback(callback, 'light getWifiVersion method'); | ||
validate.callback(callback, 'light getWifiFirmware method'); | ||
|
||
const packetObj = packet.create('getWifiFirmware', {}, this.client.source); | ||
packetObj.target = this.id; | ||
|
@@ -339,11 +344,13 @@ Light.prototype.getWifiVersion = function(callback) { | |
return callback(err, null); | ||
} | ||
return callback(null, pick(msg, [ | ||
'build', | ||
'majorVersion', | ||
'minorVersion' | ||
])); | ||
}, sqnNumber); | ||
}; | ||
Light.prototype.getWifiFirmware = Light.prototype.getWifiVersion; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the rename? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Lifx Api name is getWifiFirmware. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This library is not supposed to be the LIFX API but a library to interface with it. I think this is just confusing. Confusing stuff does not belong in a usage example. |
||
|
||
/** | ||
* Requests the label of the light | ||
|
@@ -397,6 +404,62 @@ Light.prototype.setLabel = function(label, callback) { | |
this.client.send(packetObj, callback); | ||
}; | ||
|
||
/** | ||
* Requests the location of the light | ||
* @param {Function} callback a function to accept the data | ||
* @param {Boolean} [cache=false] return cached result if existent | ||
* @return {Function} callback(err, location) | ||
*/ | ||
Light.prototype.getLocation = function(callback, cache) { | ||
validate.callback(callback, 'light getLocation method'); | ||
|
||
if (cache !== undefined && typeof cache !== 'boolean') { | ||
throw new TypeError('LIFX light getLocation method expects cache to be a boolean'); | ||
} | ||
const packetObj = packet.create('getLocation', { | ||
target: this.id | ||
}, this.client.source); | ||
const sqnNumber = this.client.send(packetObj); | ||
this.client.addMessageHandler('stateLocation', function(err, msg) { | ||
if (err) { | ||
return callback(err, null); | ||
} | ||
return callback(null, pick(msg, [ | ||
'location', | ||
'label', | ||
'updatedAt' | ||
])); | ||
}, sqnNumber); | ||
}; | ||
|
||
/** | ||
* Requests the group of the light | ||
* @param {Function} callback a function to accept the data | ||
* @param {Boolean} [cache=false] return cached result if existent | ||
* @return {Function} callback(err, group) | ||
*/ | ||
Light.prototype.getGroup = function(callback, cache) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't realize this was missing. Nice addition! |
||
validate.callback(callback, 'light getGroup method'); | ||
|
||
if (cache !== undefined && typeof cache !== 'boolean') { | ||
throw new TypeError('LIFX light getGroup method expects cache to be a boolean'); | ||
} | ||
const packetObj = packet.create('getGroup', { | ||
target: this.id | ||
}, this.client.source); | ||
const sqnNumber = this.client.send(packetObj); | ||
this.client.addMessageHandler('stateGroup', function(err, msg) { | ||
if (err) { | ||
return callback(err, null); | ||
} | ||
return callback(null, pick(msg, [ | ||
'group', | ||
'label', | ||
'updatedAt' | ||
])); | ||
}, sqnNumber); | ||
}; | ||
|
||
/** | ||
* Requests ambient light value of the light | ||
* @param {Function} callback a function to accept the data | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you add all these shortcuts because you've found them useful? I'm not using this in the CLI, only via Node.js, so if it's useful to you, it's fine to add them.
Technically, this entire CLI section could be moved to its own project right? We could create this as a monorepo and add it there. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to move it out might be a good idea. And than build the cli tool from ground up again.