UNPKG

homebridge-rpi

Version:
48 lines (42 loc) 1.41 kB
// homebridge-rpi/lib/RpiService/GpioInput/GpioContact.js // Copyright © 2019-2025 Erik Baauw. All rights reserved. // // Homebridge plugin for Raspberry Pi. import { GpioInput } from '../GpioInput.js' import { RpiService } from '../../RpiService.js' class GpioContact extends GpioInput { constructor (gpioAccessory, params = {}) { params.Service = gpioAccessory.Services.hap.ContactSensor super(gpioAccessory, params) this.addCharacteristicDelegate({ key: 'contact', Characteristic: this.Characteristics.hap.ContactSensorState }) this.addCharacteristicDelegate({ key: 'timesOpened', Characteristic: this.Characteristics.eve.TimesOpened, value: 0 // silent: true }) this.addCharacteristicDelegate({ key: 'lastActivation', Characteristic: this.Characteristics.eve.LastActivation // silent: true }) 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.contact = value ? this.Characteristics.hap.ContactSensorState.CONTACT_NOT_DETECTED : this.Characteristics.hap.ContactSensorState.CONTACT_DETECTED } } RpiService.GpioContact = GpioContact