import { CommandClasses } from "@zwave-js/core" ; import type { Driver } from "../driver/Driver" ; import { createEmptyMockDriver } from "../test/mocks" ; import { TimeCC , TimeCCDateGet , TimeCCDateReport , TimeCCTimeGet , TimeCCTimeReport , TimeCommand , } from "./TimeCC" ; const fakeDriver = createEmptyMockDriver ( ) as unknown as Driver ; function buildCCBuffer ( payload ) { return Buffer . concat ( [ Buffer . from ( [ CommandClasses . Time , ] ) , payload , ] ) ; } describe ( "lib/commandclass/TimeCC => " , ( ) => { it ( "the TimeGet command should serialize correctly" , ( ) => { const cc = new TimeCCTimeGet ( fakeDriver , { nodeId : 1 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ TimeCommand . TimeGet , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the TimeReport command should be deserialized correctly" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ TimeCommand . TimeReport , 14 , 23 , 59 , ] ) ) ; const cc = new TimeCCTimeReport ( fakeDriver , { nodeId : 8 , data : ccData , } ) ; expect ( cc . hour ) . toBe ( 14 ) ; expect ( cc . minute ) . toBe ( 23 ) ; expect ( cc . second ) . toBe ( 59 ) ; } ) ; it ( "the DateGet command should serialize correctly" , ( ) => { const cc = new TimeCCDateGet ( fakeDriver , { nodeId : 1 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ TimeCommand . DateGet , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the DateReport command should be deserialized correctly" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ TimeCommand . DateReport , 0x07 , 0xc5 , 10 , 17 , ] ) ) ; const cc = new TimeCCDateReport ( fakeDriver , { nodeId : 8 , data : ccData , } ) ; expect ( cc . year ) . toBe ( 1989 ) ; expect ( cc . month ) . toBe ( 10 ) ; expect ( cc . day ) . toBe ( 17 ) ; } ) ; it ( "deserializing an unsupported command should return an unspecified version of TimeCC" , ( ) => { const serializedCC = buildCCBuffer ( Buffer . from ( [ 255 ] ) ) ; const cc = new TimeCC ( fakeDriver , { nodeId : 8 , data : serializedCC , } ) ; expect ( cc . constructor ) . toBe ( TimeCC ) ; } ) ; } ) ;