@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
60 lines • 2.35 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.EveHistory = void 0;
const fakegato_history_1 = __importDefault(require("fakegato-history"));
class EveHistory {
constructor(accessory, api, logger) {
this.accessory = accessory;
this.api = api;
this.logger = logger;
const FakeGatoHistoryService = (0, fakegato_history_1.default)(api);
this.historyService = new FakeGatoHistoryService("thermo", this.accessory, {
storage: "fs",
log: this.logger,
});
}
getService() {
return this.historyService;
}
addEntry(entry) {
this.historyService.addEntry(entry);
}
readHistory(lastEntryHandler) {
const storage = this.api
.globalFakeGatoStorage;
if (!storage) {
this.logger.debug("Failed to access globalFakeGatoStorage");
return;
}
this.logger.debug("Reading data from globalFakeGatoStorage ...");
const thisAccessory = this.accessory;
const aThis = this;
storage.read({
service: this.historyService,
callback: function (err, data) {
if (!err) {
if (data) {
try {
const accessoryName = "name" in thisAccessory ? thisAccessory["name"] : thisAccessory;
aThis.logger.debug("read data from", accessoryName);
const jsonFile = typeof data === "object" ? data : JSON.parse(data);
lastEntryHandler(jsonFile.lastEntry, jsonFile.history);
}
catch (e) {
aThis.logger.debug("**ERROR fetching persisting data restart from zero - invalid JSON**", e);
}
}
}
else {
// file don't exists
aThis.logger.debug("**ERROR fetching persisting data: file dont exists", err);
}
}.bind(this),
});
}
}
exports.EveHistory = EveHistory;
//# sourceMappingURL=EveHistory.js.map