Skip to content

Commit

Permalink
Adding simple test to back the new sensors function
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-murray committed Oct 10, 2016
1 parent c3f3727 commit f009ea3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hue-api/commands/sensors-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ var Trait = require("traits").Trait
, 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 = [];
Expand All @@ -40,14 +38,16 @@ apiTraits.getAllSensors = Trait.compose(
tApiMethod(
"/api/<username>/sensors",
"GET",
"1.0",
"1.3",
"Whitelist"
),
tDescription("Gets a list of all sensors that have been discovered by the bridge."),
tPostProcessing(buildSensorsResult)
);


//TODO there are many more endpoints that need to be added to this: http://www.developers.meethue.com/documentation/sensors-api

module.exports = {
"getAllSensors": Trait.create(Object.prototype, apiTraits.getAllSensors)
};
24 changes: 24 additions & 0 deletions test/sensor-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var expect = require("chai").expect
, HueApi = require("../").api
, testValues = require("./support/testValues.js")
;

describe("Hue API", function () {

var hue = new HueApi(testValues.host, testValues.username);

describe("#sensors()", function() {

it("should obtain all the sensors in the bridge", function() {
return hue.sensors()
.then(function(results) {
expect(results.sensors).to.be.instanceOf(Array);

expect(results.sensors[0]).to.have.property("id", "1");
expect(results.sensors[0]).to.have.property("name", "Daylight");
expect(results.sensors[0]).to.have.property("type", "Daylight");
expect(results.sensors[0]).to.have.property("manufacturername", "Philips");
});
});
});
});

0 comments on commit f009ea3

Please sign in to comment.