UNPKG

homebridge-loxone-proxy

Version:

Homebridge Dynamic Platform Plugin which exposes a Loxone System to Homekit.

79 lines 4.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Window = void 0; const BaseService_1 = require("./BaseService"); class Window extends BaseService_1.BaseService { constructor() { super(...arguments); this.State = { CurrentPosition: 0, PositionState: 2, TargetPosition: 0, }; } setupService() { this.service = this.accessory.getService(this.platform.Service.Window) || this.accessory.addService(this.platform.Service.Window); this.service.getCharacteristic(this.platform.Characteristic.CurrentPosition) .onGet(() => this.handleCurrentPosition()); this.service.getCharacteristic(this.platform.Characteristic.TargetPosition) .onGet(() => this.handleTargetPositionGet()) .onSet((value) => this.handleTargetPositionSet(value)); this.service.getCharacteristic(this.platform.Characteristic.PositionState) .onGet(() => this.handlePositionState()); } updateService(message) { var _a, _b, _c, _d, _e, _f; this.platform.log.debug(`[${this.device.name}] Full Callback Message:`, message); switch (message.state) { case 'direction': switch (message.value) { case -1: this.State.PositionState = this.platform.Characteristic.PositionState.DECREASING; break; case 0: this.State.PositionState = this.platform.Characteristic.PositionState.STOPPED; break; case 1: this.State.PositionState = this.platform.Characteristic.PositionState.INCREASING; break; } this.platform.log.debug(`[${this.device.name}] Updated PositionState: ${this.State.PositionState}`); (_b = (_a = this.service) === null || _a === void 0 ? void 0 : _a.getCharacteristic(this.platform.Characteristic.PositionState)) === null || _b === void 0 ? void 0 : _b.updateValue(this.State.PositionState); break; case 'position': this.State.CurrentPosition = Math.round(message.value * 100); this.platform.log.debug(`[${this.device.name}] Updated CurrentPosition: ${this.State.CurrentPosition}`); (_d = (_c = this.service) === null || _c === void 0 ? void 0 : _c.getCharacteristic(this.platform.Characteristic.CurrentPosition)) === null || _d === void 0 ? void 0 : _d.updateValue(this.State.CurrentPosition); break; case 'targetPosition': this.State.TargetPosition = Math.round(message.value * 100); this.platform.log.debug(`[${this.device.name}] Updated TargetPosition: ${this.State.TargetPosition}`); (_f = (_e = this.service) === null || _e === void 0 ? void 0 : _e.getCharacteristic(this.platform.Characteristic.TargetPosition)) === null || _f === void 0 ? void 0 : _f.updateValue(this.State.TargetPosition); break; default: this.platform.log.warn(`[${this.device.name}] Unknown state received: ${message.state}`); break; } } handleCurrentPosition() { this.platform.log.debug('Triggered GET handleCurrentPosition'); return this.State.CurrentPosition; } handleTargetPositionGet() { this.platform.log.debug('Triggered GET handleTargetPosition'); return this.State.TargetPosition; } handleTargetPositionSet(value) { this.platform.log.debug(`[${this.device.name}] Triggered SET TargetPosition:` + value); const command = `moveToPosition/${value}`; this.platform.LoxoneHandler.sendCommand(this.device.uuidAction, command); } handlePositionState() { this.platform.log.debug('Triggered GET handlePositionState'); return this.State.PositionState; } } exports.Window = Window; //# sourceMappingURL=Window.js.map