UNPKG

homebridge-rinnai-touch-platform

Version:

Homebridge Plugin to control heating/cooling via a Rinnai Touch WiFi Module

68 lines 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Fan = void 0; const AccessoryBase_1 = require("./AccessoryBase"); const RinnaiService_1 = require("../rinnai/RinnaiService"); const debounce = require("debounce"); class Fan extends AccessoryBase_1.AccessoryBase { constructor(platform, platformAccessory) { var _a; super(platform, platformAccessory); this.service = (_a = this.platformAccessory.getService(this.platform.Service.Fan)) !== null && _a !== void 0 ? _a : this.platformAccessory.addService(this.platform.Service.Fan, platformAccessory.displayName); this.setEventHandlers(); } setEventHandlers() { this.platform.log.debug(this.constructor.name, 'setEventHandlers'); super.setEventHandlers(); this.service .getCharacteristic(this.platform.Characteristic.On) .onGet(this.getCharacteristicValue.bind(this, this.getFanOn.bind(this), 'On')) .onSet(debounce(this.setCharacteristicValue.bind(this, this.setFanOn.bind(this), 'On'), 1000)); this.service .getCharacteristic(this.platform.Characteristic.RotationSpeed) .onGet(this.getCharacteristicValue.bind(this, this.getFanRotationSpeed.bind(this), 'RotationSpeed')) .onSet(debounce(this.setCharacteristicValue.bind(this, this.setFanRotationSpeed.bind(this), 'RotationSpeed'), 1000)); } getFanOn() { this.platform.log.debug(this.constructor.name, 'getFanOn'); return this.platform.service.getFanState(); } getFanRotationSpeed() { this.platform.log.debug(this.constructor.name, 'getFanRotationSpeed'); return this.platform.service.getFanSpeed() / 16.0 * 100.0; } async setFanOn(value) { this.platform.log.debug(this.constructor.name, 'setFanOn', value); // If turning fan on then ensure HEAT/COOL is off or EVAP is on if (value) { if (this.platform.service.getOperatingMode() !== RinnaiService_1.OperatingModes.EVAPORATIVE_COOLING) { await this.platform.service.setPowerState(false); } else { await this.platform.service.setPowerState(true); await this.platform.service.setControlMode(RinnaiService_1.ControlModes.MANUAL); } } await this.platform.service.setFanState(value); } async setFanRotationSpeed(value) { this.platform.log.debug(this.constructor.name, 'setFanRotationSpeed', value); const speed = Math.round(value / 100.0 * 16.0); await this.setFanOn(true); await this.platform.service.setFanSpeed(speed); } updateValues() { this.platform.log.debug(this.constructor.name, 'updateValues'); this.service .getCharacteristic(this.platform.Characteristic.On) .updateValue(this.getFanOn()); this.service .getCharacteristic(this.platform.Characteristic.RotationSpeed) .updateValue(this.getFanRotationSpeed()); this.service .getCharacteristic(this.platform.Characteristic.RotationDirection) .updateValue(this.platform.Characteristic.RotationDirection.CLOCKWISE); } } exports.Fan = Fan; //# sourceMappingURL=Fan.js.map