import { CommandClasses , Duration } from "@zwave-js/core" ; import type { Driver } from "../driver/Driver" ; import { createEmptyMockDriver } from "../test/mocks" ; import { SceneActivationCC , SceneActivationCCSet , SceneActivationCommand , } from "./SceneActivationCC" ; const fakeDriver = createEmptyMockDriver ( ) as unknown as Driver ; function buildCCBuffer ( payload ) { return Buffer . concat ( [ Buffer . from ( [ CommandClasses [ "Scene Activation" ] , ] ) , payload , ] ) ; } describe ( "lib/commandclass/SceneActivationCC => " , ( ) => { it ( "the Set command (without Duration) should serialize correctly" , ( ) => { const cc = new SceneActivationCCSet ( fakeDriver , { nodeId : 2 , sceneId : 55 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ SceneActivationCommand . Set , 55 , 0xff , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Set command (with Duration) should serialize correctly" , ( ) => { const cc = new SceneActivationCCSet ( fakeDriver , { nodeId : 2 , sceneId : 56 , dimmingDuration : new Duration ( 1 , "minutes" ) } ) ; const expected = buildCCBuffer ( Buffer . from ( [ SceneActivationCommand . Set , 56 , 0x80 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Set command should be deserialized correctly" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ SceneActivationCommand . Set , 15 , 0x00 , ] ) ) ; const cc = new SceneActivationCCSet ( fakeDriver , { nodeId : 2 , data : ccData } ) ; expect ( cc . sceneId ) . toBe ( 15 ) ; expect ( cc . dimmingDuration ) . toEqual ( new Duration ( 0 , "seconds" ) ) ; } ) ; it ( "deserializing an unsupported command should return an unspecified version of SceneActivationCC" , ( ) => { const serializedCC = buildCCBuffer ( Buffer . from ( [ 255 ] ) ) ; const cc = new SceneActivationCC ( fakeDriver , { nodeId : 2 , data : serializedCC } ) ; expect ( cc . constructor ) . toBe ( SceneActivationCC ) ; } ) ; } ) ;