@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
47 lines • 1.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const async_lock_1 = __importDefault(require("async-lock"));
const lock = new async_lock_1.default();
const defaults = {
Pow: 0,
Mod: 0,
SetTem: 0,
WdSpd: 0,
Air: 0,
Blo: 0,
Health: 0,
SwhSlp: 0,
Lig: 0,
SwingLfRig: 0,
SwUpDn: 0,
Quiet: 0,
Tur: 0,
StHt: 0,
TemUn: 0,
HeatCoolType: 0,
TemRec: 0,
SvSt: 0
};
const cache = {};
const getStatus = (device) => async () => {
return lock.acquire(`get-status-${device.FullInfo.id}`, async () => {
if (!cache[device.FullInfo.id.toString()]) {
cache[device.FullInfo.id.toString()] = {
values: defaults,
setAt: 0
};
}
if (Date.now() - cache[device.FullInfo.id.toString()].setAt < 150) {
return cache[device.FullInfo.id.toString()].values;
}
const status = (await device.sendCommand('STATUS'));
cache[device.FullInfo.id.toString()].values = status;
cache[device.FullInfo.id.toString()].setAt = Date.now();
return cache[device.FullInfo.id.toString()].values;
});
};
exports.default = getStatus;
//# sourceMappingURL=acStatus.js.map