@pst-on-npm/homebridge-enocean
Version:
Integrate EnOcean® devices into Homebridge.
42 lines • 1.45 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatusActiveWrapper = void 0;
class StatusActiveWrapper {
log;
displayName;
timeout_ms;
_statusActive;
_timeoutId;
constructor(log, displayName, timeout_ms = (55 * 60 * 1000), // t = 55 minutes
initialState = false) {
this.log = log;
this.displayName = displayName;
this.timeout_ms = timeout_ms;
this._statusActive = initialState;
}
get statusActive() {
return this._statusActive;
}
statusActiveChanged;
update() {
if (this._timeoutId !== undefined) {
clearTimeout(this._timeoutId);
}
if (this._statusActive === false) {
this._statusActive = true;
this.log.info(`${this.displayName}: ACTIVE (ONLINE)`);
if (this.statusActiveChanged !== undefined) {
this.statusActiveChanged(this._statusActive);
}
}
this._timeoutId = setTimeout(() => {
this.log.warn(`${this.displayName}: NOT ACTIVE (TIMEOUT ${Math.floor(this.timeout_ms / 1000)} s)`);
this._statusActive = false;
if (this.statusActiveChanged !== undefined) {
this.statusActiveChanged(this._statusActive);
}
}, this.timeout_ms);
}
}
exports.StatusActiveWrapper = StatusActiveWrapper;
//# sourceMappingURL=StatusActiveWrapper.js.map