import { CommandClasses } from "@zwave-js/core" ; import type { Driver } from "../driver/Driver" ; import { ZWaveNode } from "../node/Node" ; import { createEmptyMockDriver } from "../test/mocks" ; import { ThermostatFanMode , ThermostatFanModeCCGet , ThermostatFanModeCCReport , ThermostatFanModeCCSet , ThermostatFanModeCommand , } from "./ThermostatFanModeCC" ; function buildCCBuffer ( payload ) { return Buffer . concat ( [ Buffer . from ( [ CommandClasses [ "Thermostat Fan Mode" ] , ] ) , payload , ] ) ; } describe ( "lib/commandclass/ThermostatFanModeCC => " , ( ) => { let fakeDriver ; let node1 ; let node5 ; beforeAll ( ( ) => { fakeDriver = createEmptyMockDriver ( ) as unknown as Driver ; node1 = new ZWaveNode ( 1 , fakeDriver as any ) ; node5 = new ZWaveNode ( 5 , fakeDriver as any ) ; ( fakeDriver . controller . nodes as any ) . set ( 1 , node1 ) ; ( fakeDriver . controller . nodes as any ) . set ( 5 , node5 ) ; node1 . addCC ( CommandClasses [ "Thermostat Fan Mode" ] , { isSupported : true , version : 1 , } ) ; node5 . addCC ( CommandClasses [ "Thermostat Fan Mode" ] , { isSupported : true , version : 5 , } ) ; } ) ; afterAll ( ( ) => { node1 . destroy ( ) ; node5 . destroy ( ) ; } ) ; it ( "the Get command should serialize correctly" , ( ) => { const cc = new ThermostatFanModeCCGet ( fakeDriver , { nodeId : 5 } ) ; const expected = buildCCBuffer ( Buffer . from ( [ ThermostatFanModeCommand . Get , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Set command should serialize correctly (off = false)" , ( ) => { const cc = new ThermostatFanModeCCSet ( fakeDriver , { nodeId : 5 , mode : ThermostatFanMode [ "Auto medium" ] , off : false , } ) ; const expected = buildCCBuffer ( Buffer . from ( [ ThermostatFanModeCommand . Set , 0x04 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Set command should serialize correctly (off = true)" , ( ) => { const cc = new ThermostatFanModeCCSet ( fakeDriver , { nodeId : 5 , mode : ThermostatFanMode [ "Auto medium" ] , off : true , } ) ; const expected = buildCCBuffer ( Buffer . from ( [ ThermostatFanModeCommand . Set , 132 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the V1 Set command ignores off=true" , ( ) => { const cc = new ThermostatFanModeCCSet ( fakeDriver , { nodeId : 1 , mode : ThermostatFanMode [ "Auto medium" ] , off : true , } ) ; const expected = buildCCBuffer ( Buffer . from ( [ ThermostatFanModeCommand . Set , 4 , ] ) ) ; expect ( cc . serialize ( ) ) . toEqual ( expected ) ; } ) ; it ( "the Report command (v1-v2) should be deserialized correctly" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ ThermostatFanModeCommand . Report , ThermostatFanMode [ "Auto low" ] , ] ) ) ; const cc = new ThermostatFanModeCCReport ( fakeDriver , { nodeId : 1 , data : ccData , } ) ; expect ( cc . mode ) . toBe ( ThermostatFanMode [ "Auto low" ] ) ; expect ( cc . off ) . toBeUndefined ( ) ; } ) ; it ( "the Report command (v3-v5) should be deserialized correctly" , ( ) => { const ccData = buildCCBuffer ( Buffer . from ( [ ThermostatFanModeCommand . Report , 130 , ] ) ) ; const cc = new ThermostatFanModeCCReport ( fakeDriver , { nodeId : 5 , data : ccData , } ) ; expect ( cc . mode ) . toBe ( ThermostatFanMode [ "Auto high" ] ) ; expect ( cc . off ) . toBe ( true ) ; } ) ; } ) ;