homebridge-loxone-proxy
Version:
Homebridge Dynamic Platform Plugin which exposes a Loxone System to Homekit.
71 lines • 3.07 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IrrigationSystem = void 0;
const BaseService_1 = require("./BaseService");
const Valve_1 = require("./Valve");
class IrrigationSystem extends BaseService_1.BaseService {
constructor() {
super(...arguments);
this.zoneValves = new Map();
this.durationUpdateInterval = null;
}
setupService() {
this.service =
this.accessory.getService(this.platform.Service.IrrigationSystem) ||
this.accessory.addService(this.platform.Service.IrrigationSystem);
this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
this.service.setCharacteristic(this.platform.Characteristic.ProgramMode, this.platform.Characteristic.ProgramMode.NO_PROGRAM_SCHEDULED);
}
updateService(message) {
switch (message.state) {
case 'zones': {
try {
const zones = typeof message.value === 'string' ? JSON.parse(message.value) : message.value;
if (!Array.isArray(zones)) {
this.platform.log.warn(`[${this.device.name}] zones is not an array`);
break;
}
this.platform.log.info(`[${this.device.name}] Setting up ${zones.length} zones`);
this.setupZones(zones);
this.startRemainingDurationUpdater();
}
catch (err) {
this.platform.log.warn(`[${this.device.name}] Invalid zone data: ${message.value}`);
}
break;
}
case 'currentZone': {
const now = Date.now();
const currentId = message.value;
this.zoneValves.forEach((valve) => {
valve.updateFromLoxone(currentId, now);
});
break;
}
default:
this.platform.log.debug(`[${this.device.name}] Unhandled irrigation state: ${message.state}`);
}
this.platform.log.debug(`[${this.device.name}] State update: ${message.state} = ${message.value}`);
}
setupZones(zones) {
zones.forEach((zone) => {
const valve = new Valve_1.Valve(this.platform, this.accessory, zone, (command) => this.sendCommand(command));
this.zoneValves.set(zone.id, valve);
});
}
startRemainingDurationUpdater() {
if (this.durationUpdateInterval) {
return;
}
this.durationUpdateInterval = setInterval(() => {
const now = Date.now();
this.zoneValves.forEach((valve) => valve.tick(now));
}, 1000);
}
sendCommand(command) {
this.platform.log.debug(`[${this.device.name}] Sending command to Loxone: ${command}`);
this.platform.LoxoneHandler.sendCommand(this.device.uuidAction, command);
}
}
exports.IrrigationSystem = IrrigationSystem;
//# sourceMappingURL=IrrigationSystem.js.map