import { Service , Characteristic , CharacteristicEventTypes } from 'homebridge' ; export const DEFAULT_FILTER_CHANGE_THRESHOLD = 5 ; interface FilterChangeIndicationOptions { filterChangeThreshold : number ; } export function add ( maybeDevice , service , characteristic , options ) { const { FILTER_OK , CHANGE_FILTER } = characteristic ; maybeDevice . then ( ( device ) => { device . on ( 'filterLifeChanged' , ( value ) => { if ( value <= options . filterChangeThreshold ) { service . updateCharacteristic ( characteristic , CHANGE_FILTER ) ; } } ) ; } ) ; return service . getCharacteristic ( characteristic ) . onGet ( async ( ) => { const device = await maybeDevice ; return ( await device . filterLifeLevel ( ) ) <= options . filterChangeThreshold ? CHANGE_FILTER : FILTER_OK ; } ) ; }