homebridge-wideq
Version:
WideQ for Homebridge
52 lines (51 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var DeviceUtil = /** @class */ (function () {
function DeviceUtil() {
this.devices = {};
}
DeviceUtil.prototype.getBySid = function (sid) {
return (sid in this.devices) ? this.devices[sid] : null;
};
DeviceUtil.prototype.add = function (sid, device) {
this.devices[sid] = device;
return device;
};
DeviceUtil.prototype.update = function (sid, newDevice) {
var device = this.getBySid(sid);
if (null != device) {
for (var item in newDevice) {
device[item] = newDevice[item];
}
}
return device;
};
DeviceUtil.prototype.addOrUpdate = function (sid, newDevice) {
var device = this.getBySid(sid);
if (null == device) {
return this.add(sid, newDevice);
}
else {
return this.update(sid, newDevice);
}
};
DeviceUtil.prototype.remove = function (sid) {
delete this.devices[sid];
};
DeviceUtil.prototype.getAutoRemoveDevice = function (threshold) {
var r = {};
var nowTime = Date.now();
for (var sid in this.devices) {
var device = this.getBySid(sid);
if ((nowTime - device.lastUpdateTime) > threshold) {
r[sid] = device;
}
}
return r;
};
DeviceUtil.prototype.getAll = function () {
return this.devices;
};
return DeviceUtil;
}());
exports.default = DeviceUtil;