@petro-kushchak/homebridge-ch-gree-ac-eve-platform
Version:
Cooper&Hunter (based on Gree AC API) AC plugin for Homebridge (Homekit) with Web Hook/MQTT Data Sharing
125 lines • 4.32 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const acStatus_1 = __importDefault(require("../utils/acStatus"));
const acSender_1 = __importDefault(require("../utils/acSender"));
class ACSpeed {
constructor(platform, accessory, activeChar, eventEmitter, event) {
this.platform = platform;
this.accessory = accessory;
this.activeChar = activeChar;
this.speedLevels = {
three: 4,
five: 6
};
eventEmitter.on(event, this.onACAction.bind(this));
this.service =
this.accessory.getService(this.platform.Service.Fan) ||
this.accessory.addService(this.platform.Service.Fan);
this.getStatus = (0, acStatus_1.default)(this.accessory.context.device);
this.sendData = (0, acSender_1.default)(this.accessory.context.device);
this.fanActiveChar = this.service
.getCharacteristic(this.platform.Characteristic.On)
.onGet(this.handleOnGet.bind(this))
.onSet(this.handleOnSet.bind(this));
this.fanSpeedChar = this.service
.getCharacteristic(this.platform.Characteristic.RotationSpeed)
.onGet(this.handleRotationSpeedGet.bind(this))
.setProps({
minStep: 1,
minValue: 0,
maxValue: this.platform.config.threeSpeedUnit
? this.speedLevels.three
: this.speedLevels.five
})
.onSet(this.handleRotationSpeedSet.bind(this));
}
onACAction() {
const updatePower = async () => {
const power = await this.handleOnGet();
this.fanActiveChar.updateValue(power);
};
const updateSpeed = async () => {
const speed = await this.handleRotationSpeedGet();
this.fanSpeedChar.updateValue(speed);
};
updatePower();
updateSpeed();
}
async handleOnGet() {
const status = await this.getStatus();
return status.Pow === 1;
}
async handleOnSet(value) {
await this.sendData({
Pow: value ? 1 : 0
});
this.activeChar.updateValue(value);
}
async handleRotationSpeedGet() {
const status = await this.getStatus();
let rotationSpeed = 0;
if (this.platform.config.threeSpeedUnit) {
switch (parseInt(status.WdSpd.toString())) {
case 1:
rotationSpeed = 1;
break;
case 3:
rotationSpeed = 2;
break;
case 5:
rotationSpeed = 3;
break;
default:
rotationSpeed = 0;
break;
}
}
else {
rotationSpeed = parseInt(status.WdSpd.toString());
}
if (status.Tur) {
rotationSpeed = this.platform.config.threeSpeedUnit
? this.speedLevels.three
: this.speedLevels.five;
}
return rotationSpeed;
}
async handleRotationSpeedSet(value) {
const speedLevel = parseInt(value.toString());
let realSpeedLevel = speedLevel;
let isTurbo = 0;
if (this.platform.config.threeSpeedUnit) {
switch (speedLevel) {
case 1:
realSpeedLevel = 1;
break;
case 2:
realSpeedLevel = 3;
break;
case 3:
case 4:
realSpeedLevel = 5;
break;
default:
realSpeedLevel = 0;
break;
}
}
if (speedLevel >=
(this.platform.config.threeSpeedUnit
? this.speedLevels.three
: this.speedLevels.five)) {
isTurbo = 1;
}
await this.sendData({
WdSpd: realSpeedLevel,
Tur: isTurbo
});
this.activeChar.updateValue(1);
}
}
exports.default = ACSpeed;
//# sourceMappingURL=ACSpeed.js.map