import console from 'console' ; import createDebug from 'debug' ; import chalk from 'chalk' ; import { chalkString , chalkKeyword } from './chalk' ; import { Characteristic } from '../config/hap' ; import type { PlatformAccessory , Service } from 'homebridge' ; type IdentifiableAccessoryObject = PlatformAccessory | Service ; export const debug = createDebug ( 'homebridge-tydom' ) ; export const enableDebug = ( ) => createDebug . enable ( 'homebridge-tydom' ) ; export const dir = ( ... args ) : void => { console . dir ( args . length > 1 ? args : args [ 0 ] , { colors : true , depth : 10 } ) ; } ; export const debugGet = ( characteristic , { displayName : name , UUID : id } ) : void => { debug ( `${ chalk . bold . green ( '→GET' ) }:${ chalk . blue ( characteristic . name ) } for accessory named=${ chalkString ( name ) } with id=${ chalkString ( id ) } ...` ) ; } ; export const debugGetResult = ( characteristic , { displayName : name , UUID : id } , value ) : void => { debug ( `${ chalk . bold . green ( '←GET' ) }:${ chalk . blue ( characteristic . name ) } value=${ chalk . yellow ( value ) } for accessory named=${ chalkString ( name ) } with id=${ chalkString ( id ) } ...` ) ; } ; export const debugSetUpdate = ( characteristic , { displayName : name , UUID : id } , value ) : void => { debug ( `${ chalk . bold . yellow ( '←UPD' ) }:${ chalk . blue ( characteristic . name ) } value=${ chalk . yellow ( value ) } for accessory named=${ chalkString ( name ) } with id=${ chalkString ( id ) }` ) ; } ; export const debugSet = ( characteristic , { displayName : name , UUID : id } , value ) : void => { debug ( `${ chalk . bold . red ( '→SET' ) }:${ chalk . blue ( characteristic . name ) } value=${ chalk . yellow ( value ) } for accessory named=${ chalkString ( name ) } with id=${ chalkString ( id ) } ...` ) ; } ; export const debugSetResult = ( characteristic , { displayName : name , UUID : id } , value , tydomValue ? ) : void => { debug ( `${ chalk . bold . red ( '←SET' ) }:${ chalk . blue ( characteristic . name ) } value=${ chalk . yellow ( value ) }${ tydomValue !== undefined ? ` (tydomValue=${ chalk . yellow ( tydomValue ) })` : '' } for accessory named=${ chalkString ( name ) } with id=${ chalkString ( id ) }` ) ; } ; export const debugTydomPut = ( property , { displayName : name , UUID : id } , value ) : void => { debug ( `${ chalk . bold . red ( '→PUT' ) }:${ chalk . blue ( property ) } value=${ chalk . yellow ( value ) } for accessory named=${ chalkString ( name ) } with id=${ chalkString ( id ) }` ) ; } ; export const debugAddSubService = ( service , { displayName : name , UUID : id } ) : void => { debug ( `Adding new sub service ${ chalkKeyword ( service . constructor . name ) } with name=${ chalkString ( service . displayName ) }, subtype=${ chalkString ( service . subtype ) } and id="${ chalkString ( service . UUID ) }" for accessory named=${ chalkString ( name ) } with id=${ chalkString ( id ) }` ) ; } ;