package Ġio . github . zero one 3 0 1 0 . y ah ue api Ċ Ċ import Ġcom . fasterxml . jackson . core . Json Processing Exception Ċ import Ġcom . fasterxml . jackson . databind . JsonNode Ċ import Ġcom . fasterxml . jackson . databind . ObjectMapper Ċ import Ġcom . github . tom ake hur st . wire mock . Wire Mock Server Ċ import Ġcom . github . tom ake hur st . wire mock . client . Wire Mock .* Ċ import Ġcom . github . tom ake hur st . wire mock . core . Wire Mock Configuration . wire Mock Config Ċ import Ġcom . github . tom ake hur st . wire mock . matching . EqualTo Json Pattern Ċ import Ġcom . github . tom ake hur st . wire mock . matching . EqualTo Pattern Ċ import Ġorg . junit . jupiter . api . After Each Ċ import Ġorg . junit . jupiter . api . Assertions .* Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġjava . io . File Ċ import Ġjava . io . IOException Ċ import Ġjava . math . BigDecimal Ċ import Ġjava . util .* Ċ import Ġkotlin . math . abs Ċ Ċ internal Ġclass ĠH ue Test Ġ{ ĊĊĠ Ġprivate Ġval Ġwire Mock Server Ġ= ĠWire Mock Server ( wire Mock Config (). dynamic Port ()) ĊĊĠ Ġ@ BeforeEach ĊĠ Ġfun Ġstart Server () Ġ{ ĊĠĠĠ Ġwire Mock Server . start () ĊĠ Ġ} ĊĊĠ Ġ@ After Each ĊĠ Ġfun Ġstop Server () Ġ{ ĊĠĠĠ Ġwire Mock Server . stop () ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcreate Hue And Initialize Mock Server (): ĠH ue Ġ{ ĊĠĠĠ Ġval Ġhue Root Ġ= ĠreadFile (" hue Root . json ") ĊĊĠĠĠ Ġval ĠobjectMapper Ġ= ĠObjectMapper () ĊĠĠĠ Ġval Ġjson Node : ĠJsonNode ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġjson Node Ġ= ĠobjectMapper . read Tree ( hue Root ) ĊĠĠĠĠĠ Ġwire Mock Server . stub For ( get ( API _ BASE _ PATH ). willReturn ( ok Json ( hue Root ))) ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" lights ", Ġ" 1 0 0 ") ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" lights ", Ġ" 1 0 1 ") ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" lights ", Ġ" 2 0 0 ") ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" lights ", Ġ" 3 0 0 ") ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" sensors ", Ġ" 1 ") ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" sensors ", Ġ" 4 ") ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" sensors ", Ġ" 1 5 ") ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" sensors ", Ġ" 1 6 ") ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" groups ", Ġ" 1 ") ĊĠĠĠĠĠ Ġmock Individual GetResponse ( json Node , Ġ" groups ", Ġ" 2 ") ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠIOException ) Ġ{ ĊĠĠĠĠĠ Ġthrow ĠRuntimeException ( e ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn ĠH ue (" localhost :" Ġ+ Ġwire Mock Server . port (), ĠAPI _ KEY ) ĊĠ Ġ} ĊĊĠ Ġ@ Throws ( Json Processing Exception :: class ) ĊĠ Ġprivate Ġfun Ġmock Individual GetResponse ( hue Root : ĠJsonNode , Ġitem Class : ĠString , Ġid : ĠString ) Ġ{ ĊĠĠĠ Ġval ĠobjectMapper Ġ= ĠObjectMapper () ĊĠĠĠ Ġval Ġjson Ġ= ĠobjectMapper . writeValue AsString ( hue Root . get ( item Class ). get ( id )) ĊĠĠĠ Ġwire Mock Server . stub For ( get ("$ API _ BASE _ PATH $ item Class /$ id "). willReturn ( ok Json ( json ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Initialization And Refresh () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġwire Mock Server . verify ( 0 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĊĠĠĠ Ġhue . refresh () ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĊĠĠĠ Ġhue . refresh () ĊĠĠĠ Ġwire Mock Server . verify ( 2 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Rooms () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĊĠĠĠ ĠassertEquals ( 3 , Ġhue . get Rooms (). size ) ĊĠĠĠ Ġhue . get Rooms () ĊĠĠĠ Ġhue . get Rooms () ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Room ByName () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĊĠĠĠ ĠassertEquals ( 2 , Ġhue . get Room ByName (" Living Ġroom ") !!. lights . size ) ĊĠĠĠ ĠassertEquals ( 1 , Ġhue . get Room ByName (" Bed room ") !!. lights . size ) ĊĠĠĠ ĠassertFalse ( hue . get Room ByName (" No Ġsuch Ġroom ") Ġ!= Ġnull ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Zones () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĊĠĠĠ ĠassertEquals ( 1 , Ġhue . get Zones (). size ) ĊĠĠĠ Ġhue . get Zones () ĊĠĠĠ Ġhue . get Zones () ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Zone ByName () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĊĠĠĠ ĠassertEquals ( 2 , Ġhue . get Zone ByName (" Path Ġto Ġto ilet ") !!. lights . size ) ĊĠĠĠ ĠassertFalse ( hue . get Zone ByName (" No Ġsuch Ġzone ") Ġ!= Ġnull ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Light Reach ability () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĊĠĠĠ ĠassertTrue ( hue . get Room ByName (" Living Ġroom ") !!. get Light ByName (" LR Ġ 1 ") !!. is Reach able ) ĊĠĠĠ ĠassertFalse ( hue . get Room ByName (" Bed room ") !!. get Light ByName (" P endant ") !!. is Reach able ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Light Types () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ ĠassertEquals ( Light Type . EXT ENDED _ COLOR , ĊĠĠĠĠĠĠĠ Ġhue . get Room ByName (" Living Ġroom ") !!. get Light ByName (" LR Ġ 1 ") !!. type ) ĊĠĠĠ ĠassertEquals ( Light Type . COLOR _ TEMP ER ATURE , ĊĠĠĠĠĠĠĠ Ġhue . get Room ByName (" Living Ġroom ") !!. get Light ByName (" LR Ġ 2 ") !!. type ) ĊĠĠĠ ĠassertEquals ( Light Type . COLOR , ĊĠĠĠĠĠĠĠ Ġhue . get Room ByName (" H all way Ġ 1 ") !!. get Light ByName (" LED Ġstrip Ġ 1 ") !!. type ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Light State When Xy Mode () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġstate Ġ= Ġhue . get Room ByName (" Living Ġroom ") !!. get Light ByName (" LR Ġ 1 ") !!. state ĊĠĠĠ ĠassertFalse ( state . on !! ) ĊĠĠĠ ĠassertEquals ( 0 . 3 6 8 9 f , Ġstate . xy ! ![ 0 ]) ĊĠĠĠ ĠassertEquals ( 0 . 3 7 1 9 f , Ġstate . xy ! ![ 1 ]) ĊĠĠĠ ĠassertEquals ( 2 5 4 , Ġstate . b ri !!. toInt ()) ĊĠĠĠ ĠassertNull ( state . hue ) ĊĠĠĠ ĠassertNull ( state . sat ) ĊĠĠĠ ĠassertNull ( state . ct ) ĊĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 0 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Light State When Ct Mode () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġstate Ġ= Ġhue . get Room ByName (" Living Ġroom ") !!. get Light ByName (" LR Ġ 2 ") !!. state ĊĠĠĠ ĠassertFalse ( state . on !! ) ĊĠĠĠ ĠassertNull ( state . xy ) ĊĠĠĠ ĠassertEquals ( 1 2 3 , Ġstate . b ri !!. toInt ()) ĊĠĠĠ ĠassertEquals ( 2 3 0 , Ġstate . ct !!. toInt ()) ĊĠĠĠ ĠassertNull ( state . hue ) ĊĠĠĠ ĠassertNull ( state . sat ) ĊĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 1 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Light State When Hs Mode () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġstate Ġ= Ġhue . get Room ByName (" H all way Ġ 1 ") !! ĊĠĠĠĠĠĠĠ Ġ. get Light ByName (" LED Ġstrip Ġ 1 ") !!. state ĊĊĠĠĠ ĠassertTrue ( state . on !! ) ĊĠĠĠ ĠassertNull ( state . xy ) ĊĠĠĠ ĠassertEquals ( 4 2 , Ġstate . b ri !!. toInt ()) ĊĠĠĠ ĠassertEquals ( 3 8 6 7 7 , Ġstate . hue !!. toInt ()) ĊĠĠĠ ĠassertEquals ( 6 1 , Ġstate . sat !!. toInt ()) ĊĠĠĠ ĠassertNull ( state . ct ) ĊĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 3 0 0 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Light State Queries The Bridge Every Time When Caching Is Off ByDefault () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġlight Ġ= Ġhue . get Room ByName (" H all way Ġ 1 ") !!. get Light ByName (" LED Ġstrip Ġ 1 ") !! ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 5 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 3 0 0 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Light State Queries The Bridge Every Time When Caching Is Off Explicit ly () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġhue . is Caching Ġ= Ġfalse ĊĠĠĠ Ġval Ġlight Ġ= Ġhue . get Room ByName (" H all way Ġ 1 ") !!. get Light ByName (" LED Ġstrip Ġ 1 ") !! ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 5 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 3 0 0 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Light State IsNot Qu er ied From The Bridge When Caching Is On () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġhue . is Caching Ġ= Ġtrue ĊĠĠĠ Ġval Ġlight Ġ= Ġhue . get Room ByName (" H all way Ġ 1 ") !!. get Light ByName (" LED Ġstrip Ġ 1 ") !! ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ ĠassertTrue ( light . state . on !! ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 0 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 3 0 0 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Light State When To g gling Caching On And Off () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĊĠĠĠ Ġhue . is Caching Ġ= Ġtrue ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġval Ġlight Ġ= Ġhue . get Room ByName (" H all way Ġ 1 ") !!. get Light ByName (" LED Ġstrip Ġ 1 ") !! ĊĠĠĠ Ġlight . state ĊĠĠĠ Ġlight . state ĊĠĠĠ Ġwire Mock Server . verify ( 0 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 3 0 0 "))) ĊĊĠĠĠ Ġhue . is Caching Ġ= Ġfalse ĊĠĠĠ Ġwire Mock Server . verify ( 2 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġlight . state ĊĠĠĠ Ġlight . state ĊĠĠĠ Ġlight . state ĊĠĠĠ Ġwire Mock Server . verify ( 3 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 3 0 0 "))) ĊĊĠĠĠ Ġhue . is Caching Ġ= Ġtrue ĊĠĠĠ Ġwire Mock Server . verify ( 3 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġlight . state ĊĠĠĠ Ġlight . state ĊĠĠĠ Ġlight . state ĊĠĠĠ Ġwire Mock Server . verify ( 3 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 3 0 0 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Unknown Sensors () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġsensors Ġ= Ġhue . unknown Sensors ĊĠĠĠ ĠassertEquals ( 2 , Ġsensors . size ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Temperature Sensor ByName () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ ĠassertNotNull ( hue . get Temperature Sensor ByName ( TEMP ER ATURE _ SENSOR _ NAME )) ĊĠĠĠ ĠassertNull ( hue . get Temperature Sensor ByName (" No Ġsuch Ġsensor ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Motion Sensor ByName () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ ĠassertTrue ( hue . get Motion Sensor ByName ( MOT ION _ SENSOR _ NAME ) Ġ!= Ġnull ) ĊĠĠĠ ĠassertFalse ( hue . get Motion Sensor ByName (" No Ġsuch Ġsensor ") Ġ!= Ġnull ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Motion Sensor Last Updated () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġactual Ġ= Ġhue . get Motion Sensor ByName ( MOT ION _ SENSOR _ NAME ) !!. last Updated ĊĊĠĠĠ Ġval Ġexpected Ġ= Ġget Date UTC ( 2 0 1 8 , Ġ 7 , Ġ 2 9 , Ġ 6 , Ġ 6 , Ġ 6 ) ĊĠĠĠ ĠassertEquals ( expected , Ġactual ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Motion Sensor Presence () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ ĠassertTrue ( hue . get Motion Sensor ByName ( MOT ION _ SENSOR _ NAME ) Ġ!= Ġnull ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Temperature Sensor Temperature () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġtemperature Ġ= Ġhue . get Temperature Sensor ByName ( TEMP ER ATURE _ SENSOR _ NAME ) !!. degrees C els ius . toDouble () ĊĠĠĠ ĠassertEquals ( 2 9 . 5 3 , Ġtemperature ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Day light Sensor () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġday light Ġ= Ġhue . day light Sensors ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit . is Day light Time Ġ} ĊĠĠĠĠĠĠĠ Ġ. first OrNull () ĊĠĠĠ ĠassertTrue ( day light Ġ!= Ġnull ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Dim mer Switch Last Updated () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġactual Ġ= Ġhue . get Dim mer Switch ByName ( DI MM ER _ SWITCH _ NAME ) !!. last Updated ĊĊĠĠĠ Ġval Ġexpected Ġ= Ġget Date UTC ( 2 0 1 8 , ĠCalendar . J UL Y , Ġ 2 8 , Ġ 2 1 , Ġ 1 2 , Ġ 0 ) ĊĊĠĠĠ ĠassertEquals ( expected , Ġactual ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Dim mer Switch Last Button Event () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġevent Ġ= Ġhue . get Dim mer Switch ByName ( DI MM ER _ SWITCH _ NAME ) !!. latest Button Event ĊĠĠĠ ĠassertEquals ( Dim mer Switch Action . SHORT _ RELEASE D , Ġevent . action ) ĊĠĠĠ ĠassertEquals ( Dim mer Switch Button . OFF , Ġevent . button ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Sensor State Queries The Bridge Every Time When Caching Is Off ByDefault () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġsensor Ġ= Ġhue . get Temperature Sensor ByName (" Hue Ġtemperature Ġsensor Ġ 1 ") ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor !!. degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 5 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" sensors / 1 5 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Sensor State Queries The Bridge Every Time When Caching Is Off Explicit ly () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġhue . is Caching Ġ= Ġfalse ĊĠĠĠ Ġval Ġsensor Ġ= Ġhue . get Temperature Sensor ByName (" Hue Ġtemperature Ġsensor Ġ 1 ") ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor !!. degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 5 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" sensors / 1 5 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Sensor State IsNot Qu er ied From The Bridge When Caching Is On () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġhue . is Caching Ġ= Ġtrue ĊĠĠĠ Ġval Ġsensor Ġ= Ġhue . get Temperature Sensor ByName (" Hue Ġtemperature Ġsensor Ġ 1 ") ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor !!. degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ ĠassertEquals ( BigDecimal (" 2 9 . 5 3 "), Ġsensor . degrees C els ius ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 0 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" sensors / 1 5 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Sensor State When To g gling Caching On And Off () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĊĠĠĠ Ġhue . is Caching Ġ= Ġtrue ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġval Ġsensor Ġ= Ġhue . get Temperature Sensor ByName (" Hue Ġtemperature Ġsensor Ġ 1 ") ĊĠĠĠ Ġsensor !!. degrees C els ius ĊĠĠĠ Ġsensor . degrees C els ius ĊĠĠĠ Ġwire Mock Server . verify ( 0 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" sensors / 1 5 "))) ĊĊĠĠĠ Ġhue . is Caching Ġ= Ġfalse ĊĠĠĠ Ġwire Mock Server . verify ( 2 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġsensor . degrees C els ius ĊĠĠĠ Ġsensor . degrees C els ius ĊĠĠĠ Ġsensor . degrees C els ius ĊĠĠĠ Ġwire Mock Server . verify ( 3 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" sensors / 1 5 "))) ĊĊĠĠĠ Ġhue . is Caching Ġ= Ġtrue ĊĠĠĠ Ġwire Mock Server . verify ( 3 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġsensor . degrees C els ius ĊĠĠĠ Ġsensor . degrees C els ius ĊĠĠĠ Ġsensor . degrees C els ius ĊĠĠĠ Ġwire Mock Server . verify ( 3 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" sensors / 1 5 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Set Light Brightness () Ġ{ ĊĠĠĠ Ġwire Mock Server . stub For ( put ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 0 / state ") ĊĠĠĠĠĠĠĠ Ġ. with RequestBody ( equal ToJson ("{ \" b ri \": 4 2 } ")) ĊĠĠĠĠĠĠĠ Ġ. willReturn ( ok Json (" [{ \" success \":{\" / lights / 1 0 0 / state / b ri \": 4 2 }} ] "))) ĊĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġlight Ġ= Ġhue . get Room ByName (" Living Ġroom ") !!. get Light ByName (" LR Ġ 1 ") !! ĊĠĠĠ Ġlight . set Brightness ( 4 2 ) ĊĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġput Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 0 / state ")) ĊĠĠĠĠĠĠĠ Ġ. with RequestBody ( EqualTo Json Pattern ("{ \" b ri \": 4 2 }", Ġfalse , Ġfalse ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Turn Light Off () Ġ{ ĊĠĠĠ Ġwire Mock Server . stub For ( put ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 0 / state ") ĊĠĠĠĠĠĠĠ Ġ. with RequestBody ( equal ToJson ("{ \" on \": false } ")) ĊĠĠĠĠĠĠĠ Ġ. willReturn ( ok Json (" [{ \" success \":{\" / lights / 1 0 0 / state / on \": false }} ] "))) ĊĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġlight Ġ= Ġhue . get Room ByName (" Living Ġroom ") !!. get Light ByName (" LR Ġ 1 ") !! ĊĠĠĠ Ġlight . turn Off () ĊĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġput Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 0 / state ")) ĊĠĠĠĠĠĠĠ Ġ. with RequestBody ( EqualTo Json Pattern ("{ \" on \": false }", Ġfalse , Ġfalse ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Turn Light On () Ġ{ ĊĠĠĠ Ġwire Mock Server . stub For ( put ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 0 / state ") ĊĠĠĠĠĠĠĠ Ġ. with RequestBody ( equal ToJson ("{ \" on \": true } ")) ĊĠĠĠĠĠĠĠ Ġ. willReturn ( ok Json (" [{ \" success \":{\" / lights / 1 0 0 / state / on \": true }} ] "))) ĊĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġlight Ġ= Ġhue . get Room ByName (" Living Ġroom ") !!. get Light ByName (" LR Ġ 1 ") !! ĊĠĠĠ Ġlight . turn On () ĊĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġput Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 0 / state ")) ĊĠĠĠĠĠĠĠ Ġ. with RequestBody ( EqualTo Json Pattern ("{ \" on \": true }", Ġfalse , Ġfalse ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Set Light State () Ġ{ ĊĠĠĠ Ġwire Mock Server . stub For ( put ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 0 / state ") ĊĠĠĠĠĠĠĠ Ġ. with RequestBody ( equal ToJson ("{ \" hue \": 1 , Ġ\" sat \": 2 , Ġ\" b ri \": 3 } ")) ĊĠĠĠĠĠĠĠ Ġ. willReturn ( ok Json (" [{ \" success \":{\" / lights / 1 0 0 / state / on \": true }} ] "))) ĊĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġlight Ġ= Ġhue . get Room ByName (" Living Ġroom ") !!. get Light ByName (" LR Ġ 1 ") !! ĊĠĠĠ Ġlight . state Ġ= ĠState . builder (). hue ( 1 ). sat uration ( 2 ). brightness ( 3 ). keep Current State () ĊĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġput Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" lights / 1 0 0 / state ")) ĊĠĠĠĠĠĠĠ Ġ. with RequestBody ( EqualTo Json Pattern ("{ \" hue \": 1 , Ġ\" sat \": 2 , Ġ\" b ri \": 3 }", Ġfalse , Ġfalse ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Set Room Brightness () Ġ{ ĊĠĠĠ Ġwire Mock Server . stub For ( put ( API _ BASE _ PATH Ġ+ Ġ" groups / 1 / action ") ĊĠĠĠĠĠĠĠ Ġ. willReturn ( ok Json (" [{ \" success \":{\" / gr u ops / 1 / action / b ri \": 4 2 }} ] "))) ĊĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġhue . get Room ByName (" Living Ġroom ") !!. set Brightness ( 4 2 ) ĊĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġput Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" groups / 1 / action ")) ĊĠĠĠĠĠĠĠ Ġ. with RequestBody ( EqualTo Pattern ("{ \" b ri \": 4 2 }", Ġfalse ))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Room State Queries The Bridge Every Time When Caching Is Off ByDefault () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġroom Ġ= Ġhue . get Room ByName (" Living Ġroom ") !! ĊĠĠĠ ĠassertFalse ( room . is Any On ) ĊĠĠĠ ĠassertFalse ( room . is All On ) ĊĠĠĠ ĠassertFalse ( room . is Any On ) ĊĠĠĠ ĠassertFalse ( room . is All On ) ĊĠĠĠ ĠassertFalse ( room . is Any On ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 5 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" groups / 1 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Room State Queries The Bridge Every Time When Caching Is Off Explicit ly () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġhue . is Caching Ġ= Ġfalse ĊĠĠĠ Ġval Ġroom Ġ= Ġhue . get Room ByName (" Living Ġroom ") !! ĊĠĠĠ ĠassertFalse ( room . is Any On ) ĊĠĠĠ ĠassertFalse ( room . is All On ) ĊĠĠĠ ĠassertFalse ( room . is Any On ) ĊĠĠĠ ĠassertFalse ( room . is All On ) ĊĠĠĠ ĠassertFalse ( room . is Any On ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 5 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" groups / 1 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Room State IsNot Qu er ied From The Bridge When Caching Is On () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġhue . is Caching Ġ= Ġtrue ĊĠĠĠ Ġval Ġroom Ġ= Ġhue . get Room ByName (" Living Ġroom ") !! ĊĠĠĠ ĠassertFalse ( room . is Any On ) ĊĠĠĠ ĠassertFalse ( room . is All On ) ĊĠĠĠ ĠassertFalse ( room . is Any On ) ĊĠĠĠ ĠassertFalse ( room . is All On ) ĊĠĠĠ ĠassertFalse ( room . is Any On ) ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġwire Mock Server . verify ( 0 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" groups / 1 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Room State When To g gling Caching On And Off () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĊĠĠĠ Ġhue . is Caching Ġ= Ġtrue ĊĠĠĠ Ġwire Mock Server . verify ( 1 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ Ġval Ġroom Ġ= Ġhue . get Room ByName (" Bed room ") !! ĊĠĠĠ ĠassertTrue ( room . is Any On ) ĊĠĠĠ ĠassertTrue ( room . is All On ) ĊĠĠĠ Ġwire Mock Server . verify ( 0 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" groups / 2 "))) ĊĊĠĠĠ Ġhue . is Caching Ġ= Ġfalse ĊĠĠĠ Ġwire Mock Server . verify ( 2 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ ĠassertTrue ( room . is Any On ) ĊĠĠĠ ĠassertTrue ( room . is All On ) ĊĠĠĠ ĠassertTrue ( room . is Any On ) ĊĠĠĠ Ġwire Mock Server . verify ( 3 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" groups / 2 "))) ĊĊĠĠĠ Ġhue . is Caching Ġ= Ġtrue ĊĠĠĠ Ġwire Mock Server . verify ( 3 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH ))) ĊĠĠĠ ĠassertTrue ( room . is All On ) ĊĠĠĠ ĠassertTrue ( room . is Any On ) ĊĠĠĠ ĠassertTrue ( room . is All On ) ĊĠĠĠ Ġwire Mock Server . verify ( 3 , Ġget Requested For ( url EqualTo ( API _ BASE _ PATH Ġ+ Ġ" groups / 2 "))) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Raw Rules () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġroot Ġ= Ġhue . raw ĊĠĠĠ ĠassertEquals ( 2 , Ġroot !!. rules !!. size ) ĊĠĠĠ ĠassertEquals (" Dim mer ĠSwitch Ġ 4 Ġon 0 ", Ġroot . rules !! [" 1 "] !!. name ) ĊĠĠĠ ĠassertEquals (" 6 6 5 5 6 6 4 4 5 4 5 2 2 1 3 1 aaa ee aae ae ae aea ", Ġroot . rules !! [" 1 "] !!. owner ) ĊĠĠĠ ĠassertEquals (" 2 0 1 7 - 0 7 - 1 4 T 1 4 : 0 4 : 0 4 ", Ġroot . rules !! [" 1 "] !!. created ) ĊĠĠĠ ĠassertEquals (" 2 0 1 8 - 0 7 - 2 7 T 1 3 : 0 0 : 1 3 ", Ġroot . rules !! [" 1 "] !!. last Triggered ) ĊĠĠĠ ĠassertEquals ( 5 , Ġroot . rules !! [" 1 "] !!. times Triggered ) ĊĠĠĠ ĠassertEquals (" enabled ", Ġroot . rules !! [" 1 "] !!. status ) ĊĠĠĠ ĠassertEquals ( true , Ġroot . rules !! [" 1 "] !!. is Re cycle ) ĊĠĠĠ Ġval Ġconditions Ġ= Ġroot . rules !! [" 1 "] !!. conditions ĊĠĠĠ ĠassertEquals ( 3 , Ġconditions !!. size ) ĊĠĠĠ ĠassertEquals ("/ sensors / 4 / state / but tone vent ", Ġconditions [ 0 ]. address ) ĊĠĠĠ ĠassertEquals (" eq ", Ġconditions [ 0 ]. operator ) ĊĠĠĠ ĠassertEquals (" 1 0 0 0 ", Ġconditions [ 0 ]. value ) ĊĠĠĠ Ġval Ġactions Ġ= Ġroot . rules !! [" 1 "] !!. actions ĊĠĠĠ ĠassertEquals ( 1 , Ġactions !!. size ) ĊĠĠĠ ĠassertEquals ("/ groups / 1 / action ", Ġactions [ 0 ]. address ) ĊĠĠĠ ĠassertEquals (" PUT ", Ġactions [ 0 ]. method ) ĊĠĠĠ ĠassertEquals ( Collections . singleton Map (" on ", Ġtrue ), Ġactions [ 0 ]. body ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun ĠtestGet Raw Config () Ġ{ ĊĠĠĠ Ġval Ġhue Ġ= Ġcreate Hue And Initialize Mock Server () ĊĠĠĠ Ġval Ġconfig Ġ= Ġhue . raw !!. config ĊĠĠĠ ĠassertEquals ( 1 1 , Ġconfig !!. zig bee Channel ) ĊĠĠĠ ĠassertEquals (" 0 0 : 1 7 : 1 1 : 2 2 : 3 3 : aa ", Ġconfig . mac ) ĊĠĠĠ ĠassertEquals ( true , Ġconfig . is Dh cp ) ĊĠĠĠ ĠassertEquals (" 1 . 2 6 . 0 ", Ġconfig . apiVersion ) ĊĠĠĠ ĠassertEquals (" no updates ", Ġconfig . software Update 2 !!. bridge !!. state ) ĊĠĠĠ ĠassertEquals ( true , Ġconfig . portal State !!. is Signed On ) ĊĠĠĠ ĠassertEquals ( false , Ġconfig . portal State !!. is Incoming ) ĊĠĠĠ ĠassertEquals ( true , Ġconfig . portal State !!. is Outgoing ) ĊĠĠĠ ĠassertEquals (" disconnected ", Ġconfig . portal State !!. communication ) ĊĠĠĠ ĠassertEquals (" 2 0 1 5 - 0 1 - 0 9 T 1 9 : 1 9 : 1 9 ", Ġconfig . white List !! [" 6 6 5 5 6 6 4 4 5 4 5 2 2 1 3 1 aaa ee aae ae ae aea "] !!. create Date ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠreadFile ( fileName : ĠString ): ĠString Ġ{ ĊĠĠĠ Ġval Ġclass Loader Ġ= Ġjava Class . class Loader ĊĠĠĠ Ġval Ġfile Ġ= ĠFile ( class Loader . getResource ( fileName ) !!. file ) ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġreturn Ġfile . read Text () ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠIOException ) Ġ{ ĊĠĠĠĠĠ Ġthrow ĠRuntimeException ( e ) ĊĠĠĠ Ġ} ĊĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġprivate Ġval ĠAPI _ KEY Ġ= Ġ" abcd 1 2 3 4 " ĊĠĠĠ Ġprivate Ġval ĠAPI _ BASE _ PATH Ġ= Ġ"/ api /$ API _ KEY /" ĊĠĠĠ Ġprivate Ġval ĠM OT ION _ SENSOR _ NAME Ġ= Ġ" H all way Ġsensor " ĊĠĠĠ Ġprivate Ġval ĠTEMP ER ATURE _ SENSOR _ NAME Ġ= Ġ" Hue Ġtemperature Ġsensor Ġ 1 " ĊĠĠĠ Ġprivate Ġval ĠDIM MER _ SWITCH _ NAME Ġ= Ġ" Living Ġroom Ġdoor " ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠassertEquals ( date A : ĠDate , Ġdate B : ĠDate ) Ġ{ ĊĠĠĠ ĠassertTrue ( abs ( date A . time Ġ- Ġdate A . time ) Ġ< Ġ 1 0 0 0 , Ġ" Dates Ġare Ġnot Ġequal \ n $ date A \ n $ date B ") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget Date UTC ( year : ĠInt , Ġmonth : ĠInt , Ġdate : ĠInt , Ġhour OfDay : ĠInt , Ġminute : ĠInt , Ġsecond : ĠInt ): ĠDate Ġ{ ĊĠĠĠ Ġreturn ĠCalendar . getInstance (). apply Ġ{ ĊĠĠĠĠĠ Ġset ( year , Ġmonth , Ġdate , Ġhour OfDay , Ġminute , Ġsecond ) ĊĠĠĠĠĠ Ġset TimeZone ( TimeZone . getTime Zone (" UTC ")) ĊĠĠĠ Ġ}. time ĊĠ Ġ} Ċ } Ċ