@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
59 lines • 2.55 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlatformAC = void 0;
const HeaterCooler_1 = __importDefault(require("./services/HeaterCooler"));
const ACLight_1 = __importDefault(require("./services/ACLight"));
const ACSpeed_1 = __importDefault(require("./services/ACSpeed"));
const EveHistory_1 = require("./services/EveHistory");
class PlatformAC {
get UUID() {
return this.accessory.UUID.toString();
}
get Mac() {
return this.accessory.context.data.mac;
}
updateDevice(newDevice) {
this.accessory.context.device = newDevice;
this.accessory.context.data = newDevice.FullInfo;
return this.accessory;
}
constructor(platform, accessory, log) {
this.platform = platform;
this.accessory = accessory;
this.log = log;
this.accessory
.getService(this.platform.Service.AccessoryInformation)
.setCharacteristic(this.platform.Characteristic.Manufacturer, this.platform.config.manufacturer || 'Gree')
.setCharacteristic(this.platform.Characteristic.Model, this.platform.config.manufacturer || 'Gree')
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.context.data.mac);
this.HC = new HeaterCooler_1.default(this.platform, this.accessory);
new ACSpeed_1.default(this.platform, this.accessory, this.HC.activeChar, this.HC.eventEmitter, this.HC.EVENT);
new ACLight_1.default(this.platform, this.accessory);
this.history = new EveHistory_1.EveHistory(this.accessory, this.platform.api, this.log);
this.history.readHistory((_, history) => {
const lastItem = history.pop();
if (lastItem) {
this.log.info(`History: last item: ${JSON.stringify(lastItem)}`);
this.HC.updateCurrentTemp(lastItem.currentTemp);
}
else {
this.log.info('History: no data');
}
});
}
updateProp(propName, value) {
if (propName === 'currentTemp') {
const temp = parseFloat(value);
this.HC.updateCurrentTemp(temp);
this.history.addEntry({
time: Math.round(new Date().valueOf() / 1000),
currentTemp: temp,
});
}
}
}
exports.PlatformAC = PlatformAC;
//# sourceMappingURL=PlatformAC.js.map