-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitHub #8 - Add support for light management
- Loading branch information
Showing
16 changed files
with
935 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
let huejay = require('../lib/Huejay'); | ||
let credentials = require('./.credentials.json'); | ||
|
||
let client = new huejay.Client(credentials); | ||
|
||
console.log('Retrieving lights...'); | ||
console.log(); | ||
|
||
client.getLights() | ||
.then(lights => { | ||
for (let light of lights) { | ||
console.log(`Light [${light.id}]: ${light.name}`); | ||
console.log(` Type: ${light.type}`); | ||
console.log(` Unique ID: ${light.uniqueId}`); | ||
console.log(` Manufacturer: ${light.manufacturer}`); | ||
console.log(` Model Id: ${light.modelId}`); | ||
console.log(` Software Version: ${light.softwareVersion}`); | ||
console.log(' State:'); | ||
console.log(` On: ${light.on}`); | ||
console.log(` Reachable: ${light.reachable}`); | ||
console.log(` Brightness: ${light.brightness}`); | ||
console.log(` Color mode: ${light.colorMode}`); | ||
console.log(` Hue: ${light.hue}`); | ||
console.log(` Saturation: ${light.saturation}`); | ||
console.log(` X/Y: ${light.xy[0]}, ${light.xy[1]}`); | ||
console.log(` Color Temp: ${light.colorTemp}`); | ||
console.log(` Alert: ${light.alert}`); | ||
console.log(` Effect: ${light.effect}`); | ||
console.log(); | ||
} | ||
}) | ||
.catch(error => { | ||
console.log(error.stack); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
let huejay = require('../lib/Huejay'); | ||
let credentials = require('./.credentials.json'); | ||
|
||
let client = new huejay.Client(credentials); | ||
|
||
console.log('Retrieving new lights...'); | ||
console.log(); | ||
|
||
client.getNewLights() | ||
.then(lights => { | ||
for (let light of lights) { | ||
console.log(light); | ||
console.log(); | ||
} | ||
}) | ||
.catch(error => { | ||
console.log(error.stack); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
let huejay = require('../lib/Huejay'); | ||
let credentials = require('./.credentials.json'); | ||
|
||
let client = new huejay.Client(credentials); | ||
|
||
console.log(`Retrieving light from (${credentials.host})...`); | ||
|
||
client.getLights() | ||
.then(lights => { | ||
let light = lights[4]; | ||
|
||
light.name = `Name test`; | ||
light.on = true; | ||
|
||
console.log(`Saving light...`); | ||
|
||
return client.saveLight(light); | ||
}) | ||
.then(() => { | ||
console.log('Success'); | ||
}) | ||
.catch(error => { | ||
console.log(error.stack); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
let huejay = require('../lib/Huejay'); | ||
let credentials = require('./.credentials.json'); | ||
|
||
let client = new huejay.Client(credentials); | ||
|
||
console.log('Starting light scan...'); | ||
|
||
client.startLightScan() | ||
.then(() => { | ||
console.log('Success'); | ||
}) | ||
.catch(error => { | ||
console.log(error.stack); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Delete light command | ||
* | ||
* Delete a light by id | ||
*/ | ||
class DeleteLight { | ||
/** | ||
* Constructor | ||
* | ||
* @param {string} lightId Light Id or Light object | ||
*/ | ||
constructor(lightId) { | ||
this.lightId = String(lightId); | ||
} | ||
|
||
/** | ||
* Invoke command | ||
* | ||
* @param {Client} client Client | ||
* | ||
* @return {Promise} Promise for chaining | ||
*/ | ||
invoke(client) { | ||
let options = { | ||
method: 'DELETE', | ||
path: `api/${client.username}/lights/${this.lightId}` | ||
}; | ||
|
||
return client.getTransport() | ||
.sendRequest(options) | ||
.then(() => true); | ||
} | ||
} | ||
|
||
module.exports = DeleteLight; |
Oops, something went wrong.