dt-common-device 8.0.3 → 8.0.5
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.
package/dist/constants/Event.js
CHANGED
|
@@ -253,7 +253,7 @@ exports.DT_EVENT_TYPES = {
|
|
|
253
253
|
OFFLINE: "heartbeat.hub.offline",
|
|
254
254
|
},
|
|
255
255
|
LOCK: {
|
|
256
|
-
|
|
256
|
+
LOCAL_CODES: "heartbeat.lock.local_codes",
|
|
257
257
|
CLOUD_CODES: "heartbeat.lock.cloud_codes",
|
|
258
258
|
MISSING_CODES: "heartbeat.lock.missing_codes",
|
|
259
259
|
ADDITIONAL_CODES: "heartbeat.lock.additional_codes",
|
|
@@ -215,7 +215,7 @@ let LocalDeviceService = (() => {
|
|
|
215
215
|
}
|
|
216
216
|
// If old state and new state are different
|
|
217
217
|
const oldState = (await this.getState(deviceId))?.state ?? {};
|
|
218
|
-
const changedKeys = Object.keys(newState).filter((key) => !(0, lodash_1.isEqual)(oldState[key]
|
|
218
|
+
const changedKeys = Object.keys(newState).filter((key) => !(0, lodash_1.isEqual)(oldState[key]?.value?.toLowerCase(), newState[key]?.value?.toLowerCase()));
|
|
219
219
|
if (changedKeys.length > 0) {
|
|
220
220
|
await this.deviceRepository.setState(deviceId, newState);
|
|
221
221
|
return await this.eventHandler.onStateChange(deviceId, newState, auditProperties, eventType);
|
|
@@ -372,40 +372,42 @@ let LocalDeviceService = (() => {
|
|
|
372
372
|
// Check if battery level has changed
|
|
373
373
|
const isDifferent = !(0, lodash_1.isEqual)(oldBatteryState?.value, batteryLevel);
|
|
374
374
|
if (isDifferent) {
|
|
375
|
-
// Check if current time is greater than or equal to last updated time (8-hour logic)
|
|
376
|
-
const shouldUpdate = this.shouldUpdateBatteryLevel(
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
375
|
+
// // Check if current time is greater than or equal to last updated time (8-hour logic)
|
|
376
|
+
// const shouldUpdate = this.shouldUpdateBatteryLevel(
|
|
377
|
+
// oldBatteryState?.lastUpdated
|
|
378
|
+
// );
|
|
379
|
+
// if (shouldUpdate) {
|
|
380
|
+
// Save the battery level in the device
|
|
381
|
+
await this.deviceRepository.setBatteryLevel(deviceId, batteryLevel);
|
|
382
|
+
await this.eventHandler.onBatteryLevelChange(deviceId, batteryLevel, auditBody);
|
|
383
|
+
if (oldBatteryState?.value < batteryLevel &&
|
|
384
|
+
batteryLevel - oldBatteryState?.value > 50) {
|
|
385
|
+
// Battery level has increased more than 50% (considering as battery has been replaced)
|
|
386
|
+
const batteryState = {
|
|
387
|
+
batteryState: {
|
|
388
|
+
value: "replaced",
|
|
389
|
+
lastUpdated: new Date().toISOString(),
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
await this.setState(deviceId, batteryState, auditBody);
|
|
393
|
+
await this.eventHandler.onBatteryReplaced(deviceId, batteryLevel, auditBody);
|
|
394
|
+
// Cancel any existing battery issue
|
|
395
|
+
await this.issueService.performIssueAction({
|
|
396
|
+
entityId: deviceId,
|
|
397
|
+
entityType: issue_types_1.EntityType.DEVICE,
|
|
398
|
+
type: issue_types_1.IssueType.BATTERY_LOW,
|
|
399
|
+
propertyId: device.propertyId,
|
|
400
|
+
zoneId: device.zoneId,
|
|
401
|
+
}, "resolve", source);
|
|
402
|
+
}
|
|
403
|
+
// Get property threshold
|
|
404
|
+
const propertyThreshold = await this.getPropertyBatteryThreshold(device.propertyId);
|
|
405
|
+
// Check if battery level is below threshold
|
|
406
|
+
if (batteryLevel < propertyThreshold) {
|
|
407
|
+
// Raise issue when the level is below threshold
|
|
408
|
+
await this.issueService.createDeviceBatteryIssue(device, batteryLevel, propertyThreshold, issue_types_1.IssuePriority.CRITICAL, source);
|
|
408
409
|
}
|
|
410
|
+
// }
|
|
409
411
|
}
|
|
410
412
|
}
|
|
411
413
|
shouldUpdateBatteryLevel(lastUpdated) {
|