import type { SmartHomeV1ExecuteRequestCommands , SmartHomeV1SyncDevices } from 'actions-on-google' ; import { Characteristic } from '../hap-types' ; import { HapService , AccessoryTypeExecuteResponse } from '../interfaces' ; export class GarageDoorOpener { public twoFactorRequired = true ; sync ( service ) { return { id : service . uniqueId , type : 'action.devices.types.GARAGE' , traits : [ 'action.devices.traits.OpenClose' , ] , name : { defaultNames : [ service . serviceName , service . accessoryInformation . Name , ] , name : service . serviceName , nicknames : [ ] , } , willReportState : true , attributes : { openDirection : [ 'UP' , 'DOWN' ] , } , deviceInfo : { manufacturer : service . accessoryInformation . Manufacturer , model : service . accessoryInformation . Model , hwVersion : service . accessoryInformation . HardwareRevision , swVersion : service . accessoryInformation . SoftwareRevision , } , customData : { aid : service . aid , iid : service . iid , instanceUsername : service . instance . username , instanceIpAddress : service . instance . ipAddress , instancePort : service . instance . port , } , } ; } query ( service ) { /**
         * GSH impliments garrage door as an open percentage, while HomeKit impliments it as open/closed/opening/closing
         * To work around this we just set the values to something that works.
         */ const currentDoorState = service . characteristics . find ( x => x . type === Characteristic . CurrentDoorState ) . value ; const openPercent = [ 100 , 0 , 50 , 50 , 50 , 50 ] [ currentDoorState ] ; return { on : true , online : true , openPercent , } as any ; } execute ( service , command ) { if ( ! command . execution . length ) { return { payload : { characteristics : [ ] } } ; } switch ( command . execution [ 0 ] . command ) { case ( 'action.devices.commands.OpenClose' ) : { const payload = { characteristics : [ { aid : service . aid , iid : service . characteristics . find ( x => x . type === Characteristic . TargetDoorState ) . iid , value : command . execution [ 0 ] . params . openPercent ? 0 : 1 , } ] , } ; return { payload } ; } } } is2faRequired ( command ) { if ( ! command . execution . length ) { return false ; } switch ( command . execution [ 0 ] . command ) { case ( 'action.devices.commands.OpenClose' ) : { if ( command . execution [ 0 ] . params . openPercent > 0 ) { return true ; } } } return false ; } }