@@ -11,7 +11,7 @@ import { TradfriClient } from "..";
1111import { createNetworkMock } from "../../test/mocks" ;
1212import { Accessory } from "./accessory" ;
1313import { Light , LightOperation , Spectrum } from "./light" ;
14- import { MAX_COLOR , predefinedColors } from "./predefined-colors" ;
14+ import { MAX_COLOR , predefinedColors , whiteSpectrumHex } from "./predefined-colors" ;
1515
1616// enable the should interface with sinon
1717should ( ) ;
@@ -232,7 +232,7 @@ describe("ipso/light => basic functionality =>", () => {
232232 // the model name is internally responsible for detecting the spectrum
233233 // so we use that to test
234234 expect ( light . spectrum ) . to . equal ( clone . spectrum ) ;
235- } )
235+ } ) ;
236236
237237} ) ;
238238
@@ -449,6 +449,23 @@ describe("ipso/light => simplified API => ", () => {
449449 expect ( ( ) => lightWhiteSpectrum . setColor ( "efd275" ) ) . not . to . throw ;
450450 } ) ;
451451
452+ it ( "setColor() for a white spectrum bulb should send the correct payload" , async ( ) => {
453+ const keys = Object . keys ( whiteSpectrumHex ) ;
454+
455+ for ( let i = 0 , hex = keys [ i ] ; i < keys . length ; i ++ ) {
456+ lightWhiteSpectrum . colorTemperature = 1 ;
457+ const expected = predefinedColors . get ( hex ) . temperature ;
458+
459+ await lightWhiteSpectrum . setColor ( hex ) . should . become ( true ) ;
460+ assertPayload ( fakeCoap . request . getCall ( i ) . args [ 2 ] , {
461+ 3311 : [ {
462+ 5711 : expected ,
463+ 5712 : 5 ,
464+ } ] ,
465+ } , `color temperature for "${ hex } " did not equal ${ expected } ` ) ;
466+ }
467+ } ) ;
468+
452469 it ( "setColor() without transition time" , async ( ) => {
453470 await lightRGBSpectrum . setColor ( "FF0000" ) . should . become ( true ) ;
454471 assertPayload ( fakeCoap . request . getCall ( 0 ) . args [ 2 ] , {
0 commit comments