dt-common-device 9.0.1 → 9.1.0
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/audit/AuditUtils.d.ts +0 -1
- package/dist/audit/AuditUtils.js +3 -15
- package/dist/audit/IAuditProperties.d.ts +0 -1
- package/dist/entities/device/local/services/Device.service.js +34 -20
- package/dist/issues/issue.types.d.ts +1 -1
- package/dist/issues/issue.types.js +1 -1
- package/package.json +1 -1
package/dist/audit/AuditUtils.js
CHANGED
|
@@ -162,7 +162,9 @@ let AuditUtils = (() => {
|
|
|
162
162
|
if (userId && !userName)
|
|
163
163
|
audit.userName = await this.getUserName(userId);
|
|
164
164
|
if (guestId && !guestName)
|
|
165
|
-
audit.guestName =
|
|
165
|
+
audit.guestName = "Guest";
|
|
166
|
+
if (guestName)
|
|
167
|
+
audit.guestName = "Guest";
|
|
166
168
|
if (deviceId && !deviceName) {
|
|
167
169
|
audit.deviceName = await this.getDeviceName(deviceId);
|
|
168
170
|
}
|
|
@@ -254,20 +256,6 @@ let AuditUtils = (() => {
|
|
|
254
256
|
return "";
|
|
255
257
|
}
|
|
256
258
|
}
|
|
257
|
-
async getGuestName(guestId) {
|
|
258
|
-
try {
|
|
259
|
-
return await this.getCachedEntityData("guest", guestId, async () => {
|
|
260
|
-
const guest = await typedi_1.default.get(pms_1.PmsService).getGuest(guestId);
|
|
261
|
-
if (!guest)
|
|
262
|
-
return "";
|
|
263
|
-
return `${guest?.firstName || ""} ${guest?.lastName || ""}`.trim();
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
catch (error) {
|
|
267
|
-
(0, config_1.getLogger)().error(`Error in getGuestName: ${error instanceof Error ? error.message : error}`);
|
|
268
|
-
return "";
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
259
|
async getDeviceName(deviceId) {
|
|
272
260
|
try {
|
|
273
261
|
return await this.getCachedEntityData("device", deviceId, async () => {
|
|
@@ -236,27 +236,37 @@ let LocalDeviceService = (() => {
|
|
|
236
236
|
throw new Error("Device ID and new status are required");
|
|
237
237
|
}
|
|
238
238
|
const device = await this.getDevice(deviceId);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
239
|
+
//NOTE: Baseline logic only apply for device type of LOCK
|
|
240
|
+
if (device?.deviceType?.type === "LOCK") {
|
|
241
|
+
const oldStatus = device.status;
|
|
242
|
+
const currentTime = new Date().toISOString();
|
|
243
|
+
// Determine if the new status is ONLINE or OFFLINE
|
|
244
|
+
const isNewStatusOnline = newStatus?.liveStatus === "ONLINE";
|
|
245
|
+
const isNewStatusOffline = newStatus?.liveStatus === "OFFLINE";
|
|
246
|
+
if (isNewStatusOffline) {
|
|
247
|
+
// New Status = OFFLINE
|
|
248
|
+
await this.handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime);
|
|
249
|
+
}
|
|
250
|
+
else if (isNewStatusOnline) {
|
|
251
|
+
// New Status = ONLINE
|
|
252
|
+
await this.handleOnlineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// For any other status, just update normally
|
|
256
|
+
await this.deviceRepository.setStatus(deviceId, newStatus);
|
|
257
|
+
await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody, constants_1.DT_EVENT_TYPES.DEVICE.STATUS.UNKNOWN);
|
|
258
|
+
}
|
|
251
259
|
}
|
|
252
260
|
else {
|
|
253
|
-
// For
|
|
261
|
+
// For DeviceTypes other than LOCK, just update normally (HUB, THERMOSTATS)
|
|
262
|
+
const eventType = newStatus.online
|
|
263
|
+
? constants_1.DT_EVENT_TYPES.DEVICE.STATUS.ONLINE
|
|
264
|
+
: constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE;
|
|
254
265
|
await this.deviceRepository.setStatus(deviceId, newStatus);
|
|
255
|
-
await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody,
|
|
266
|
+
await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody, eventType);
|
|
256
267
|
}
|
|
257
268
|
}
|
|
258
269
|
async setStatusMany(query, newStatus, source, auditBody) {
|
|
259
|
-
//TODO: Compare old and new if different then update
|
|
260
270
|
if (!query || !newStatus) {
|
|
261
271
|
throw new Error("Query and new status are required");
|
|
262
272
|
}
|
|
@@ -266,15 +276,19 @@ let LocalDeviceService = (() => {
|
|
|
266
276
|
: constants_1.DT_EVENT_TYPES.DEVICE.STATUS.OFFLINE;
|
|
267
277
|
const devices = await this.deviceRepository.queryDevices(query);
|
|
268
278
|
for (const device of devices) {
|
|
269
|
-
if (
|
|
270
|
-
|
|
279
|
+
if (device?.deviceType?.type === "LOCK") {
|
|
280
|
+
if (newStatus.online) {
|
|
281
|
+
await this.handleOnlineStatus(device, device.status, newStatus, source, auditBody);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
await this.handleOfflineStatus(device, device.status, newStatus, source, auditBody);
|
|
285
|
+
}
|
|
271
286
|
}
|
|
272
287
|
else {
|
|
273
|
-
await this.
|
|
288
|
+
await this.deviceRepository.setStatus(device.deviceId, newStatus);
|
|
289
|
+
await this.eventHandler.onStatusChange(device.deviceId, newStatus, auditBody, eventType);
|
|
274
290
|
}
|
|
275
291
|
}
|
|
276
|
-
await this.deviceRepository.setStatusMany(query, newStatus);
|
|
277
|
-
await this.eventHandler.onStatusChangeMany(query, newStatus, auditBody, eventType);
|
|
278
292
|
}
|
|
279
293
|
async handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime) {
|
|
280
294
|
currentTime = currentTime ?? new Date().toISOString();
|
|
@@ -40,7 +40,7 @@ var EntitySubType;
|
|
|
40
40
|
EntitySubType["SKYTOUCH"] = "SKYTOUCH";
|
|
41
41
|
// DEVICE PROVIDERS
|
|
42
42
|
EntitySubType["SMARTTHINGS"] = "SMARTTHINGS";
|
|
43
|
-
EntitySubType["
|
|
43
|
+
EntitySubType["TTLOCK"] = "TTLOCK";
|
|
44
44
|
EntitySubType["TUYA"] = "TUYA";
|
|
45
45
|
EntitySubType["VERDANT"] = "VERDANT";
|
|
46
46
|
EntitySubType["SENSIBO"] = "SENSIBO";
|