UNPKG

homebridge-tahoma-fork

Version:

Sample Platform plugin for TaHoma and Cozytouch services (Somfy,Atlantic,Thermor,Sauter): https://github.com/Stuard40/homebridge-tahoma

223 lines 10.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const Platform_1 = require("../../Platform"); const overkiz_client_1 = require("overkiz-client"); const HeatingSystem_1 = __importDefault(require("../HeatingSystem")); class HitachiAirToAirHeatPump extends HeatingSystem_1.default { constructor() { super(...arguments); this.MIN_TEMP = 16; this.MAX_TEMP = 30; this.MIN_STEP = 1; this.TARGET_MODES = [ Platform_1.Characteristics.TargetHeatingCoolingState.HEAT, Platform_1.Characteristics.TargetHeatingCoolingState.COOL, Platform_1.Characteristics.TargetHeatingCoolingState.OFF, ]; this.fanDebounceTimer = null; } registerServices() { const services = super.registerServices(); const fanService = this.registerService(Platform_1.Services.Fan, 'Fan'); this.fanService = fanService; fanService.setCharacteristic(Platform_1.Characteristics.Name, this.device.label + ' Fan'); this.fanOn = fanService.getCharacteristic(Platform_1.Characteristics.On); this.fanOn.onSet(async (value) => { var _a; if (value === ((_a = this.fanOn) === null || _a === void 0 ? void 0 : _a.value)) { return; } const targetState = value ? Platform_1.Characteristics.TargetHeatingCoolingState.COOL : Platform_1.Characteristics.TargetHeatingCoolingState.OFF; await this.setTargetState(targetState); }); this.rotationSpeed = fanService.getCharacteristic(Platform_1.Characteristics.RotationSpeed); this.rotationSpeed.updateValue(100); this.rotationSpeed.setProps({ minValue: 0, maxValue: 100, minStep: 20, }); this.rotationSpeed.onSet(this.debounceFan(this.setRotationSpeed)); services.push(fanService); return services; } debounceFan(task) { return async (value) => { if (this.fanDebounceTimer !== null) { clearTimeout(this.fanDebounceTimer); } this.fanDebounceTimer = setTimeout(async () => { this.fanDebounceTimer = null; task.bind(this, value)().catch(() => null); }, 500); }; } async setRotationSpeed(value) { var _a, _b; let fanMode = 'auto'; const speed = Math.round(value / 20) * 20; switch (speed) { case 0: case 20: fanMode = 'silent'; break; case 40: fanMode = 'lo'; break; case 60: fanMode = 'med'; break; case 80: fanMode = 'hi'; break; case 100: fanMode = 'auto'; break; } const commands = this.getCommandsWithFanMode((_a = this.targetState) === null || _a === void 0 ? void 0 : _a.value, (_b = this.targetTemperature) === null || _b === void 0 ? void 0 : _b.value, fanMode); await this.executeCommands(commands); } getTargetStateCommands(value) { var _a; return this.getCommands(value, (_a = this.targetTemperature) === null || _a === void 0 ? void 0 : _a.value); } getTargetTemperatureCommands(value) { var _a; return this.getCommands((_a = this.targetState) === null || _a === void 0 ? void 0 : _a.value, value); } onStateChanged(name, value) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; switch (name) { case 'ovp:ModeChangeState': case 'ovp:MainOperationState': if (this.device.get('ovp:MainOperationState') === 'Off' || this.device.get('ovp:MainOperationState') === 'off') { (_a = this.currentState) === null || _a === void 0 ? void 0 : _a.updateValue(Platform_1.Characteristics.CurrentHeatingCoolingState.OFF); (_b = this.targetState) === null || _b === void 0 ? void 0 : _b.updateValue(Platform_1.Characteristics.TargetHeatingCoolingState.OFF); (_c = this.fanOn) === null || _c === void 0 ? void 0 : _c.updateValue(false); } else { (_d = this.fanOn) === null || _d === void 0 ? void 0 : _d.updateValue(true); switch ((_e = this.device.get('ovp:ModeChangeState')) === null || _e === void 0 ? void 0 : _e.toLowerCase()) { case 'auto cooling': (_f = this.currentState) === null || _f === void 0 ? void 0 : _f.updateValue(Platform_1.Characteristics.CurrentHeatingCoolingState.COOL); (_g = this.targetState) === null || _g === void 0 ? void 0 : _g.updateValue(Platform_1.Characteristics.TargetHeatingCoolingState.COOL); break; case 'auto heating': (_h = this.currentState) === null || _h === void 0 ? void 0 : _h.updateValue(Platform_1.Characteristics.CurrentHeatingCoolingState.HEAT); (_j = this.targetState) === null || _j === void 0 ? void 0 : _j.updateValue(Platform_1.Characteristics.TargetHeatingCoolingState.HEAT); break; case 'cooling': (_k = this.currentState) === null || _k === void 0 ? void 0 : _k.updateValue(Platform_1.Characteristics.CurrentHeatingCoolingState.COOL); (_l = this.targetState) === null || _l === void 0 ? void 0 : _l.updateValue(Platform_1.Characteristics.TargetHeatingCoolingState.COOL); break; case 'heating': (_m = this.currentState) === null || _m === void 0 ? void 0 : _m.updateValue(Platform_1.Characteristics.CurrentHeatingCoolingState.HEAT); (_o = this.targetState) === null || _o === void 0 ? void 0 : _o.updateValue(Platform_1.Characteristics.TargetHeatingCoolingState.HEAT); break; } } break; case 'ovp:RoomTemperatureState': this.onTemperatureUpdate(value); break; case 'core:TargetTemperatureState': (_p = this.targetTemperature) === null || _p === void 0 ? void 0 : _p.updateValue(value); break; case 'ovp:FanSpeedState': let speed = 100; switch (value === null || value === void 0 ? void 0 : value.toLowerCase()) { case 'silent': speed = 20; break; case 'low': case 'lo': speed = 40; break; case 'medium': case 'med': speed = 60; break; case 'high': case 'hi': speed = 80; break; case 'auto': speed = 100; break; } (_q = this.rotationSpeed) === null || _q === void 0 ? void 0 : _q.updateValue(speed); break; } } getCommands(state, temperature) { let fanMode = 'auto'; if (this.rotationSpeed) { const value = Number(this.rotationSpeed.value); const speed = Math.round(value / 20) * 20; switch (speed) { case 0: case 20: fanMode = 'silent'; break; case 40: fanMode = 'lo'; break; case 60: fanMode = 'med'; break; case 80: fanMode = 'hi'; break; case 100: fanMode = 'auto'; break; } } return this.getCommandsWithFanMode(state, temperature, fanMode); } getCommandsWithFanMode(state, temperature, fanMode) { const currentState = this.currentState ? this.currentState.value : 0; const currentTemperature = this.currentTemperature && this.currentTemperature.value !== null ? this.currentTemperature.value : 0; let onOff = 'on'; const progMode = 'manu'; let heatMode = 'auto'; const autoTemp = Math.trunc(Math.max(Math.min(temperature - parseInt(currentTemperature.toString()), 5), -5)); switch (state) { case Platform_1.Characteristics.TargetHeatingCoolingState.OFF: onOff = 'off'; switch (currentState) { case Platform_1.Characteristics.CurrentHeatingCoolingState.HEAT: heatMode = 'heating'; break; case Platform_1.Characteristics.CurrentHeatingCoolingState.COOL: heatMode = 'cooling'; break; default: temperature = autoTemp; break; } break; case Platform_1.Characteristics.TargetHeatingCoolingState.HEAT: heatMode = 'heating'; break; case Platform_1.Characteristics.TargetHeatingCoolingState.COOL: heatMode = 'cooling'; break; case Platform_1.Characteristics.TargetHeatingCoolingState.AUTO: heatMode = 'auto'; temperature = autoTemp; break; default: temperature = autoTemp; break; } temperature = Math.round(temperature); this.debug('FROM ' + currentState + '/' + currentTemperature + ' TO ' + state + '/' + temperature + ' with fan ' + fanMode); return new overkiz_client_1.Command('globalControl', [onOff, temperature, fanMode, heatMode, progMode]); } } exports.default = HitachiAirToAirHeatPump; //# sourceMappingURL=HitachiAirToAirHeatPump.js.map