homebridge-rpi
Version:
Homebridge plugin for Raspberry Pi
40 lines (34 loc) • 1.21 kB
JavaScript
// homebridge-rpi/lib/RpiService/GpioInput/GpioRocker.js
// Copyright © 2019-2026 Erik Baauw. All rights reserved.
//
// Homebridge plugin for Raspberry Pi.
import { GpioInput } from '../GpioInput.js'
import { RpiService } from '../../RpiService.js'
class GpioRocker extends GpioInput {
constructor (gpioAccessory, params = {}) {
params.Service = gpioAccessory.Services.hap.StatelessProgrammableSwitch
params.subtype = params.index
super(gpioAccessory, params)
this.addCharacteristicDelegate({
key: 'buttonevent',
Characteristic: this.Characteristics.hap.ProgrammableSwitchEvent,
props: {
minValue: this.Characteristics.hap.ProgrammableSwitchEvent.SINGLE_PRESS,
maxValue: this.Characteristics.hap.ProgrammableSwitchEvent.SINGLE_PRESS
}
})
}
update (value, duration) {
if (duration == null) {
return
}
duration = Math.round(duration / 1000) // µs => ms
this.debug(
'gpio %d: rocker flipped to %s after %d ms', this.gpio,
value ? 'high' : 'low', duration
)
this.values.buttonevent =
this.Characteristics.hap.ProgrammableSwitchEvent.SINGLE_PRESS
}
}
RpiService.GpioRocker = GpioRocker