Skip to content

Commit

Permalink
added a test for setting hex colors on ws bulbs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Mar 6, 2018
1 parent 6cf127d commit 2addc90
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/lib/light.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TradfriClient } from "..";
import { createNetworkMock } from "../../test/mocks";
import { Accessory } from "./accessory";
import { Light, LightOperation, Spectrum } from "./light";
import { MAX_COLOR, predefinedColors } from "./predefined-colors";
import { MAX_COLOR, predefinedColors, whiteSpectrumHex } from "./predefined-colors";

// enable the should interface with sinon
should();
Expand Down Expand Up @@ -232,7 +232,7 @@ describe("ipso/light => basic functionality =>", () => {
// the model name is internally responsible for detecting the spectrum
// so we use that to test
expect(light.spectrum).to.equal(clone.spectrum);
})
});

});

Expand Down Expand Up @@ -449,6 +449,23 @@ describe("ipso/light => simplified API => ", () => {
expect(() => lightWhiteSpectrum.setColor("efd275")).not.to.throw;
});

it("setColor() for a white spectrum bulb should send the correct payload", async () => {
const keys = Object.keys(whiteSpectrumHex);

for (let i = 0, hex = keys[i]; i < keys.length; i++) {
lightWhiteSpectrum.colorTemperature = 1;
const expected = predefinedColors.get(hex).temperature;

await lightWhiteSpectrum.setColor(hex).should.become(true);
assertPayload(fakeCoap.request.getCall(i).args[2], {
3311: [{
5711: expected,
5712: 5,
}],
}, `color temperature for "${hex}" did not equal ${expected}`);
}
});

it("setColor() without transition time", async () => {
await lightRGBSpectrum.setColor("FF0000").should.become(true);
assertPayload(fakeCoap.request.getCall(0).args[2], {
Expand Down

0 comments on commit 2addc90

Please sign in to comment.