UNPKG

@homebridge-plugins/homebridge-rainbird

Version:

The Rainbird plugin allows you to access your Rainbird device(s) from HomeKit.

45 lines 2.01 kB
import { DeviceBase } from './DeviceBase.js'; export class DelayIrrigationSwitch extends DeviceBase { platform; // Service service; constructor(platform, accessory, device, rainbird) { super(platform, accessory, device, rainbird); this.platform = platform; // Delay Irrigation Switch Service this.debugLog(`Load Switch Service for ${accessory.displayName}`); this.service = this.accessory.getService(this.hap.Service.Switch) ?? this.accessory.addService(this.hap.Service.Switch); // Add Switch's Characteristics this.service .setCharacteristic(this.hap.Characteristic.On, false) .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName); this.service .getCharacteristic(this.hap.Characteristic.On) .onGet(async () => { const state = await this.rainbird.getIrrigationDelay() > 0; this.debugLog(`${this.constructor.name}: ${this.accessory.displayName} On: ${state}`); return state; }) .onSet(async (value) => { this.debugLog(`${this.constructor.name}: ${this.accessory.displayName}, Set On: ${value}`); if (value) { await this.rainbird.setIrrigationDelay(this.device.irrigationDelay); } else { await this.rainbird.setIrrigationDelay(0); } }); setInterval(async () => { await this.updateHomeKitCharacteristics(); }, 3600000); // every hour } /** * Updates the status for each of the HomeKit Characteristics */ async updateHomeKitCharacteristics() { const state = await this.rainbird.getIrrigationDelay() > 0; this.service.updateCharacteristic(this.hap.Characteristic.On, state); this.debugLog(`${this.constructor.name}: ${this.accessory.displayName} updateCharacteristic On: ${state}`); } } //# sourceMappingURL=DelayIrrigationSwitch.js.map