UNPKG

@homebridge-plugins/homebridge-rainbird

Version:

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

45 lines 2.06 kB
import { DeviceBase } from './DeviceBase.js'; export class TestZoneSwitch extends DeviceBase { platform; testZoneSwitch; constructor(platform, accessory, device, rainbird) { super(platform, accessory, device, rainbird); this.platform = platform; // Test Zone Switch Service this.debugLog(`Load Switch Service for ${accessory.displayName}`); this.testZoneSwitch = { service: this.accessory.getService(this.hap.Service.Switch) ?? this.accessory.addService(this.hap.Service.Switch), state: false, }; // Add Switch's Characteristics this.testZoneSwitch.service .setCharacteristic(this.hap.Characteristic.On, false) .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName); this.testZoneSwitch.service .getCharacteristic(this.hap.Characteristic.On) .onGet(() => { return this.testZoneSwitch.state; }) .onSet(this.setOn.bind(this)); } async setOn(value) { this.debugLog(`${this.constructor.name}: ${this.accessory.displayName}, Set On: ${value}`); this.testZoneSwitch.state = value; if (value) { try { await this.rainbird.testZone(this.accessory.context.zoneId); this.debugLog(`${this.constructor.name}: ${this.accessory.displayName}, testZone(${this.accessory.context.zoneId}) completed`); } catch (e) { this.errorLog(`${this.constructor.name}: ${this.accessory.displayName}, testZone failed: ${e.message}`); } // Auto-turn off after test completes setTimeout(() => { this.testZoneSwitch.state = false; this.testZoneSwitch.service.updateCharacteristic(this.hap.Characteristic.On, false); this.debugLog(`${this.constructor.name}: ${this.accessory.displayName}, Auto-off after test`); }, 500); } } } //# sourceMappingURL=TestZoneSwitch.js.map