UNPKG

homebridge-rpi

Version:
36 lines (31 loc) 1.17 kB
// homebridge-rpi/lib/RpiService/GpioInput/GpioCarbonMonoxide.js // Copyright © 2019-2026 Erik Baauw and Bill Stoddart. All rights reserved. // // Homebridge plugin for Raspberry Pi. import { GpioInput } from '../GpioInput.js' import { RpiService } from '../../RpiService.js' class GpioCarbonMonoxide extends GpioInput { constructor (gpioAccessory, params = {}) { params.Service = gpioAccessory.Services.hap.CarbonMonoxideSensor super(gpioAccessory, params) this.addCharacteristicDelegate({ key: 'carbonMonoxideDetected', Characteristic: this.Characteristics.hap.CarbonMonoxideDetected }) this.addCharacteristicDelegate({ key: 'statusFault', Characteristic: this.Characteristics.hap.StatusFault, silent: true }) } update (value) { this.debug('gpio %d: %s', this.gpio, value ? 'high' : 'low') if (this.params.reversed) { value = !value } this.values.carbonMonoxideDetected = value ? this.Characteristics.hap.CarbonMonoxideDetected.CO_LEVELS_NORMAL : this.Characteristics.hap.CarbonMonoxideDetected.CO_LEVELS_ABNORMAL } } RpiService.GpioCarbonMonoxide = GpioCarbonMonoxide