dt-common-device 9.1.8 → 9.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -294,43 +294,52 @@ let LocalDeviceService = (() => {
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
async handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime) {
|
|
297
|
+
// if deviceProfile is active, only then use baseline for the device, if its calibrating or inactive mark device offline immediately
|
|
298
|
+
const preferences = await this.localPropertyService.getPropertyPreferences(device.propertyId, ["deviceProfile"]);
|
|
299
|
+
const deviceProfile = preferences?.settings?.deviceProfile?.value || "calibrating";
|
|
297
300
|
currentTime = currentTime ?? new Date().toISOString();
|
|
298
301
|
const isExistingStatusOnline = oldStatus?.liveStatus === "ONLINE";
|
|
299
302
|
const isExistingStatusOffline = oldStatus?.liveStatus === "OFFLINE";
|
|
300
|
-
if (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
newStatus.lastUpdated = currentTime;
|
|
305
|
-
newStatus.error = {
|
|
306
|
-
type: "offline",
|
|
307
|
-
message: reason || "Device went offline",
|
|
308
|
-
default: {},
|
|
309
|
-
};
|
|
310
|
-
await this.deviceRepository.setStatus(device.deviceId, newStatus);
|
|
311
|
-
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE);
|
|
312
|
-
}
|
|
313
|
-
else if (isExistingStatusOffline) {
|
|
314
|
-
// Existing status is Offline
|
|
315
|
-
const timeLapsed = oldStatus?.lastUpdated
|
|
316
|
-
? Date.now() - new Date(oldStatus.lastUpdated).getTime()
|
|
317
|
-
: 0;
|
|
318
|
-
const baselineTime = await this.getDeviceBaseline(device.deviceId);
|
|
319
|
-
if (timeLapsed > baselineTime) {
|
|
320
|
-
// When the time lapsed is higher than the baseline time
|
|
321
|
-
newStatus.online = false;
|
|
303
|
+
if (deviceProfile === "active") {
|
|
304
|
+
if (isExistingStatusOnline) {
|
|
305
|
+
// Existing status is Online
|
|
306
|
+
newStatus.online = true;
|
|
322
307
|
newStatus.liveStatus = "OFFLINE";
|
|
323
308
|
newStatus.lastUpdated = currentTime;
|
|
324
309
|
newStatus.error = {
|
|
325
310
|
type: "offline",
|
|
326
|
-
message: reason || "Device
|
|
311
|
+
message: reason || "Device went offline",
|
|
327
312
|
default: {},
|
|
328
313
|
};
|
|
329
314
|
await this.deviceRepository.setStatus(device.deviceId, newStatus);
|
|
330
315
|
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE);
|
|
331
|
-
// Raise issue when the device goes offline if longer than the baseline (OPERATIONAL only)
|
|
332
|
-
await this.issueService.createDeviceOfflineIssue(device, source, reason);
|
|
333
316
|
}
|
|
317
|
+
else if (isExistingStatusOffline) {
|
|
318
|
+
// Existing status is Offline
|
|
319
|
+
const timeLapsed = oldStatus?.lastUpdated
|
|
320
|
+
? Date.now() - new Date(oldStatus.lastUpdated).getTime()
|
|
321
|
+
: 0;
|
|
322
|
+
const baselineTime = await this.getDeviceBaseline(device.deviceId);
|
|
323
|
+
if (timeLapsed > baselineTime) {
|
|
324
|
+
// When the time lapsed is higher than the baseline time
|
|
325
|
+
newStatus.online = false;
|
|
326
|
+
newStatus.liveStatus = "OFFLINE";
|
|
327
|
+
newStatus.lastUpdated = currentTime;
|
|
328
|
+
newStatus.error = {
|
|
329
|
+
type: "offline",
|
|
330
|
+
message: reason || "Device has been offline for longer than baseline",
|
|
331
|
+
default: {},
|
|
332
|
+
};
|
|
333
|
+
await this.deviceRepository.setStatus(device.deviceId, newStatus);
|
|
334
|
+
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE);
|
|
335
|
+
// Raise issue when the device goes offline if longer than the baseline (OPERATIONAL only)
|
|
336
|
+
await this.issueService.createDeviceOfflineIssue(device, source, reason);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
await this.deviceRepository.setStatus(device.deviceId, newStatus);
|
|
342
|
+
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE);
|
|
334
343
|
}
|
|
335
344
|
}
|
|
336
345
|
async handleOnlineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime) {
|