import { Service , Characteristic , CharacteristicEventTypes } from 'homebridge' ; export function add ( maybeDevice , service , characteristic ) { const { INACTIVE , PURIFYING_AIR , } = characteristic ; maybeDevice . then ( ( device ) => { device . on ( 'powerChanged' , ( isOn ) => { service . updateCharacteristic ( characteristic , isOn ? PURIFYING_AIR : INACTIVE ) ; } ) ; } ) ; return service . getCharacteristic ( characteristic ) . onGet ( async ( ) => { const device = await maybeDevice ; const isOn = await device . power ( ) ; return isOn ? PURIFYING_AIR : INACTIVE ; } ) ; }