-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from oeuillot/master
Basic sensor support
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use strict"; | ||
|
||
// | ||
// The Documented Phillips Hue Bridge API for lights http://developers.meethue.com/1_lightsapi.html | ||
// | ||
// This module wraps up all the functionality for the definition and basic processing of the parameters for the API | ||
// so that it can be called from the httpPromise module. | ||
// | ||
// The benefits of keeping all this code here is that it is much simpler to update the keep in step with the Phillips | ||
// Hue API documentation, than having it scatter piece meal through various other classes and functions. | ||
// | ||
|
||
var Trait = require("traits").Trait | ||
, deepExtend = require("deep-extend") | ||
, tApiMethod = require("./traits/tApiMethod") | ||
, tDescription = require("./traits/tDescription") | ||
, tBodyArguments = require("./traits/tBodyArguments") | ||
, tLightStateBody = require("./traits/tLightStateBody") | ||
, tPostProcessing = require("./traits/tPostProcessing") | ||
, ApiError = require("../errors").ApiError | ||
, utils = require("../utils") | ||
; | ||
|
||
var apiTraits = {}; | ||
|
||
|
||
//TODO tie this into the API definition as a post processing step, then apply it via the http.invoke() | ||
function buildSensorsResult(result) { | ||
var sensors = []; | ||
|
||
if (result) { | ||
Object.keys(result).forEach(function (id) { | ||
sensors.push(deepExtend({id: id}, result[id])); | ||
}); | ||
} | ||
return {"sensors": sensors}; | ||
} | ||
|
||
apiTraits.getAllSensors = Trait.compose( | ||
tApiMethod( | ||
"/api/<username>/sensors", | ||
"GET", | ||
"1.0", | ||
"Whitelist" | ||
), | ||
tDescription("Gets a list of all sensors that have been discovered by the bridge."), | ||
tPostProcessing(buildSensorsResult) | ||
); | ||
|
||
|
||
module.exports = { | ||
"getAllSensors": Trait.create(Object.prototype, apiTraits.getAllSensors) | ||
}; |
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