import { Service , Characteristic } from 'homebridge' ; function pm2_5ToAqi ( aqi ) { if ( ! aqi ) { return 0 ; } else if ( aqi <= 25 ) { return 1 ; } else if ( aqi > 25 && aqi <= 50 ) { return 2 ; } else if ( aqi > 50 && aqi <= 75 ) { return 3 ; } else if ( aqi > 75 && aqi <= 100 ) { return 4 ; } else if ( aqi > 100 ) { return 5 ; } else { return 0 ; } } export function add ( maybeDevice , service , characteristic ) { maybeDevice . then ( ( device ) => { device . on ( 'pm2.5Changed' , ( value ) => { service . updateCharacteristic ( characteristic , pm2_5ToAqi ( value ) ) ; } ) ; } ) ; return service . getCharacteristic ( characteristic ) . onGet ( async ( ) => { const device = await maybeDevice ; return pm2_5ToAqi ( await device . pm2_5 ( ) ) ; } ) ; }