import { AccessoryPlugin , CharacteristicGetCallback , CharacteristicSetCallback , CharacteristicValue , HAP , Logging , Service , CharacteristicEventTypes } from "homebridge" ; export class ExampleSwitch implements AccessoryPlugin { private readonly log : Logging ; private switchOn = false ; name : string ; private readonly switchService : Service ; private readonly informationService : Service ; constructor ( hap , log , name ) { this . log = log ; this . name = name ; this . switchService = new hap . Service . Switch ( name ) ; this . switchService . getCharacteristic ( hap . Characteristic . On ) . on ( CharacteristicEventTypes . GET , ( callback ) => { log . info ( "Current state of the switch was returned: " + ( this . switchOn ? "ON" : "OFF" ) ) ; callback ( undefined , this . switchOn ) ; } ) . on ( CharacteristicEventTypes . SET , ( value , callback ) => { this . switchOn = value as boolean ; log . info ( "Switch state was set to: " + ( this . switchOn ? "ON" : "OFF" ) ) ; callback ( ) ; } ) ; this . informationService = new hap . Service . AccessoryInformation ( ) . setCharacteristic ( hap . Characteristic . Manufacturer , "Custom Manufacturer" ) . setCharacteristic ( hap . Characteristic . Model , "Custom Model" ) ; log . info ( "Example switch '%s' created!" , name ) ; } identify ( ) { this . log ( "Identify!" ) ; } getServices ( ) { return [ this . informationService , this . switchService , ] ; } }