dt-common-device 4.0.3 → 4.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/connection/IConnection.d.ts +6 -1
- package/dist/connection/IConnection.js +5 -0
- package/dist/constants/ConnectionProviders.d.ts +3 -0
- package/dist/constants/ConnectionProviders.js +5 -0
- package/dist/device/local/interfaces/IDevice.d.ts +9 -0
- package/dist/device/local/repository/Device.repository.d.ts +2 -1
- package/dist/device/local/repository/Device.repository.js +13 -0
- package/dist/device/local/services/Device.service.d.ts +2 -1
- package/dist/device/local/services/Device.service.js +8 -0
- package/dist/events/EventHandler.d.ts +2 -0
- package/dist/events/EventHandler.js +26 -3
- package/dist/events/InternalEventSubscription.js +0 -2
- package/dist/property/Property.repository.d.ts +1 -1
- package/dist/property/Property.repository.js +16 -2
- package/dist/property/Property.service.d.ts +1 -1
- package/dist/property/Property.service.js +37 -8
- package/package.json +1 -1
|
@@ -22,5 +22,10 @@ export declare enum ConnectionProvider {
|
|
|
22
22
|
Schlage = "Schlage",
|
|
23
23
|
YaleWifi = "YaleWifi",
|
|
24
24
|
Sensibo = "Sensibo",
|
|
25
|
-
Devicethread = "Devicethread"
|
|
25
|
+
Devicethread = "Devicethread",
|
|
26
|
+
Yanolja = "Yanolja",
|
|
27
|
+
Cloudbeds = "Cloudbeds",
|
|
28
|
+
StayNTouch = "StayNTouch",
|
|
29
|
+
Dormakaba = "Dormakaba",
|
|
30
|
+
Dusaw = "Dusaw"
|
|
26
31
|
}
|
|
@@ -11,4 +11,9 @@ var ConnectionProvider;
|
|
|
11
11
|
ConnectionProvider["YaleWifi"] = "YaleWifi";
|
|
12
12
|
ConnectionProvider["Sensibo"] = "Sensibo";
|
|
13
13
|
ConnectionProvider["Devicethread"] = "Devicethread";
|
|
14
|
+
ConnectionProvider["Yanolja"] = "Yanolja";
|
|
15
|
+
ConnectionProvider["Cloudbeds"] = "Cloudbeds";
|
|
16
|
+
ConnectionProvider["StayNTouch"] = "StayNTouch";
|
|
17
|
+
ConnectionProvider["Dormakaba"] = "Dormakaba";
|
|
18
|
+
ConnectionProvider["Dusaw"] = "Dusaw";
|
|
14
19
|
})(ConnectionProvider || (exports.ConnectionProvider = ConnectionProvider = {}));
|
|
@@ -3,6 +3,7 @@ export declare const CONNECTION_PROVIDERS: {
|
|
|
3
3
|
readonly CLOUDBEDS: "Cloudbeds";
|
|
4
4
|
readonly STAYNTOUCH: "Stayntouch";
|
|
5
5
|
readonly HOTELKEY: "Hotelkey";
|
|
6
|
+
readonly YANOLJA: "Yanolja";
|
|
6
7
|
readonly SALTOKS: "SaltoKS";
|
|
7
8
|
readonly SCHLAGE: "Schlage";
|
|
8
9
|
readonly SENSIBO: "Sensibo";
|
|
@@ -11,4 +12,6 @@ export declare const CONNECTION_PROVIDERS: {
|
|
|
11
12
|
readonly TUYA: "Tuya";
|
|
12
13
|
readonly VERDANT: "Verdant";
|
|
13
14
|
readonly YALEWIFI: "YaleWifi";
|
|
15
|
+
readonly DORMAKABA: "Dormakaba";
|
|
16
|
+
readonly DUSAW: "Dusaw";
|
|
14
17
|
};
|
|
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CONNECTION_PROVIDERS = void 0;
|
|
4
4
|
exports.CONNECTION_PROVIDERS = {
|
|
5
5
|
DEVICETHREAD: "Devicethread",
|
|
6
|
+
// PMS
|
|
6
7
|
CLOUDBEDS: "Cloudbeds",
|
|
7
8
|
STAYNTOUCH: "Stayntouch",
|
|
8
9
|
HOTELKEY: "Hotelkey",
|
|
10
|
+
YANOLJA: "Yanolja",
|
|
11
|
+
// DEVICE
|
|
9
12
|
SALTOKS: "SaltoKS",
|
|
10
13
|
SCHLAGE: "Schlage",
|
|
11
14
|
SENSIBO: "Sensibo",
|
|
@@ -14,4 +17,6 @@ exports.CONNECTION_PROVIDERS = {
|
|
|
14
17
|
TUYA: "Tuya",
|
|
15
18
|
VERDANT: "Verdant",
|
|
16
19
|
YALEWIFI: "YaleWifi",
|
|
20
|
+
DORMAKABA: "Dormakaba",
|
|
21
|
+
DUSAW: "Dusaw",
|
|
17
22
|
};
|
|
@@ -57,3 +57,12 @@ export declare class IStatus {
|
|
|
57
57
|
};
|
|
58
58
|
lastUpdated?: string;
|
|
59
59
|
}
|
|
60
|
+
export interface IStatusQuery {
|
|
61
|
+
deviceIds?: string[];
|
|
62
|
+
zoneId?: string;
|
|
63
|
+
propertyId?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface IStatusUpdateRequest {
|
|
66
|
+
query: IStatusQuery;
|
|
67
|
+
status: IStatus;
|
|
68
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDevice, IStatus } from "../interfaces/IDevice";
|
|
1
|
+
import { IDevice, IStatus, IStatusQuery } from "../interfaces/IDevice";
|
|
2
2
|
import { IDtDevice } from "../interfaces/IDtDevice";
|
|
3
3
|
export declare class DeviceRepository {
|
|
4
4
|
private readonly postgres;
|
|
@@ -15,6 +15,7 @@ export declare class DeviceRepository {
|
|
|
15
15
|
setState(deviceId: string, state: any): Promise<any>;
|
|
16
16
|
getStatus(deviceId: string): Promise<Record<string, any>>;
|
|
17
17
|
setStatus(deviceId: string, newStatus: IStatus): Promise<any>;
|
|
18
|
+
setStatusMany(query: IStatusQuery, newStatus: IStatus): Promise<any>;
|
|
18
19
|
getBatteryLevel(deviceId: string): Promise<Record<string, any>>;
|
|
19
20
|
setBatteryLevel(deviceId: string, newBatteryLevel: any): Promise<any>;
|
|
20
21
|
getMetaData(deviceId: string): Promise<any>;
|
|
@@ -169,6 +169,19 @@ let DeviceRepository = (() => {
|
|
|
169
169
|
throw new Error(`Failed to set device status: ${error.message || "Unknown error"}`);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
+
async setStatusMany(query, newStatus) {
|
|
173
|
+
try {
|
|
174
|
+
const response = await this.axiosInstance.put(`/devices/statusMany`, {
|
|
175
|
+
query,
|
|
176
|
+
status: newStatus,
|
|
177
|
+
});
|
|
178
|
+
return response.data;
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
(0, config_1.getConfig)().LOGGER.error(`Failed to set status for multiple devices: ${error.message}`);
|
|
182
|
+
throw new Error(`Failed to set status for multiple devices: ${error.message}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
172
185
|
async getBatteryLevel(deviceId) {
|
|
173
186
|
try {
|
|
174
187
|
const response = await this.axiosInstance.get(`/devices/${deviceId}/battery-level`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IDevice, IStatus } from "../interfaces";
|
|
1
|
+
import { IDevice, IStatus, IStatusQuery } from "../interfaces";
|
|
2
2
|
import { Source } from "../../../constants/Service";
|
|
3
3
|
import { AuditProperties } from "../../../audit/AuditProperties";
|
|
4
4
|
export declare class LocalDeviceService {
|
|
@@ -19,6 +19,7 @@ export declare class LocalDeviceService {
|
|
|
19
19
|
setState(deviceId: string, newState: any, auditProperties: AuditProperties): Promise<void>;
|
|
20
20
|
getStatus(deviceId: string): Promise<Record<string, any>>;
|
|
21
21
|
setStatus(deviceId: string, newStatus: IStatus, source: Source, auditBody: AuditProperties, reason?: string): Promise<void>;
|
|
22
|
+
setStatusMany(query: IStatusQuery, newStatus: IStatus, source: Source, auditBody: AuditProperties): Promise<void>;
|
|
22
23
|
private handleOfflineStatus;
|
|
23
24
|
private handleOnlineStatus;
|
|
24
25
|
private getDeviceBaseline;
|
|
@@ -155,6 +155,14 @@ let LocalDeviceService = (() => {
|
|
|
155
155
|
await this.eventHandler.onStatusChange(deviceId, newStatus, auditBody);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
+
async setStatusMany(query, newStatus, source, auditBody) {
|
|
159
|
+
if (!query || !newStatus) {
|
|
160
|
+
throw new Error("Query and new status are required");
|
|
161
|
+
}
|
|
162
|
+
newStatus.lastUpdated = new Date().toISOString();
|
|
163
|
+
await this.deviceRepository.setStatusMany(query, newStatus);
|
|
164
|
+
await this.eventHandler.onStatusChangeMany(query, newStatus, auditBody);
|
|
165
|
+
}
|
|
158
166
|
async handleOfflineStatus(device, oldStatus, newStatus, source, auditBody, reason, currentTime) {
|
|
159
167
|
const isExistingStatusOnline = oldStatus?.online === true;
|
|
160
168
|
const isExistingStatusOffline = oldStatus?.online === false;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AuditProperties } from "../audit/AuditProperties";
|
|
2
|
+
import { IStatus, IStatusQuery } from "../device/local/interfaces";
|
|
2
3
|
export declare class EventHandler {
|
|
3
4
|
private readonly source;
|
|
4
5
|
constructor();
|
|
@@ -7,6 +8,7 @@ export declare class EventHandler {
|
|
|
7
8
|
onDeviceDelete(deviceId: string, auditBody: AuditProperties): Promise<void>;
|
|
8
9
|
onStateChange(deviceId: string, state: any, auditProperties: AuditProperties): Promise<void>;
|
|
9
10
|
onStatusChange(deviceId: string, status: any, auditProperties: AuditProperties): Promise<void>;
|
|
11
|
+
onStatusChangeMany(query: IStatusQuery, status: IStatus, auditProperties: AuditProperties): Promise<void>;
|
|
10
12
|
onBatteryLevelChange(deviceId: string, batteryLevel: number, auditProperties: AuditProperties): Promise<void>;
|
|
11
13
|
onDeviceMetaChange(deviceId: string, metaData: Record<string, any>, auditProperties: AuditProperties): Promise<void>;
|
|
12
14
|
}
|
|
@@ -77,14 +77,33 @@ let EventHandler = (() => {
|
|
|
77
77
|
async onStateChange(deviceId, state, auditProperties) {
|
|
78
78
|
const payload = {
|
|
79
79
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.STATE.SET,
|
|
80
|
-
properties: (0, AuditUtils_1.buildAuditProperties)({
|
|
80
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({
|
|
81
|
+
...auditProperties,
|
|
82
|
+
deviceId,
|
|
83
|
+
...state,
|
|
84
|
+
}),
|
|
81
85
|
};
|
|
82
86
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
83
87
|
}
|
|
84
88
|
async onStatusChange(deviceId, status, auditProperties) {
|
|
85
89
|
const payload = {
|
|
86
90
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.STATUS.SET,
|
|
87
|
-
properties: (0, AuditUtils_1.buildAuditProperties)({
|
|
91
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({
|
|
92
|
+
...auditProperties,
|
|
93
|
+
deviceId,
|
|
94
|
+
...status,
|
|
95
|
+
}),
|
|
96
|
+
};
|
|
97
|
+
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
98
|
+
}
|
|
99
|
+
async onStatusChangeMany(query, status, auditProperties) {
|
|
100
|
+
const payload = {
|
|
101
|
+
eventType: Event_1.DT_EVENT_TYPES.DEVICE.STATUS.UPDATED,
|
|
102
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({
|
|
103
|
+
...auditProperties,
|
|
104
|
+
...query,
|
|
105
|
+
...status,
|
|
106
|
+
}),
|
|
88
107
|
};
|
|
89
108
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
90
109
|
}
|
|
@@ -102,7 +121,11 @@ let EventHandler = (() => {
|
|
|
102
121
|
async onDeviceMetaChange(deviceId, metaData, auditProperties) {
|
|
103
122
|
const payload = {
|
|
104
123
|
eventType: Event_1.DT_EVENT_TYPES.DEVICE.META_DATA.SET,
|
|
105
|
-
properties: (0, AuditUtils_1.buildAuditProperties)({
|
|
124
|
+
properties: (0, AuditUtils_1.buildAuditProperties)({
|
|
125
|
+
...auditProperties,
|
|
126
|
+
deviceId,
|
|
127
|
+
metaData,
|
|
128
|
+
}),
|
|
106
129
|
};
|
|
107
130
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
108
131
|
}
|
|
@@ -43,8 +43,6 @@ class InternalEventSubscription {
|
|
|
43
43
|
await this.safeCallHandler(() => this.internalEventHandler.onServiceDown(eventData));
|
|
44
44
|
break;
|
|
45
45
|
default:
|
|
46
|
-
this.logger.warn(`Unknown event type: ${eventType} ${eventData}`);
|
|
47
|
-
this.logger.info(`Calling onServiceSpecificEvent for event type: ${eventType} ${eventData}`);
|
|
48
46
|
await this.safeCallHandler(() => this.internalEventHandler.onServiceSpecificEvent(eventType, eventData));
|
|
49
47
|
break;
|
|
50
48
|
}
|
|
@@ -2,7 +2,7 @@ import { IProperty, IPropertySettings } from "./IProperty";
|
|
|
2
2
|
export declare class PropertyRepository {
|
|
3
3
|
private readonly postgres;
|
|
4
4
|
constructor();
|
|
5
|
-
getPropertyPreferences(propertyId: string): Promise<IPropertySettings | null>;
|
|
5
|
+
getPropertyPreferences(propertyId: string, keys?: string[]): Promise<IPropertySettings | null>;
|
|
6
6
|
getProperty(propertyId: string): Promise<IProperty | null>;
|
|
7
7
|
getAllProperties(): Promise<any[]>;
|
|
8
8
|
}
|
|
@@ -50,16 +50,30 @@ let PropertyRepository = (() => {
|
|
|
50
50
|
constructor() {
|
|
51
51
|
this.postgres = (0, db_1.getPostgresClient)();
|
|
52
52
|
}
|
|
53
|
-
async getPropertyPreferences(propertyId) {
|
|
53
|
+
async getPropertyPreferences(propertyId, keys) {
|
|
54
54
|
try {
|
|
55
55
|
const propertyPreferences = await this.postgres.query(`SELECT * FROM dt_property_settings WHERE "propertyId" = $1`, [propertyId]);
|
|
56
56
|
if (propertyPreferences.rows.length > 0) {
|
|
57
|
+
if (keys && keys.length > 0) {
|
|
58
|
+
const settings = propertyPreferences.rows[0].settings;
|
|
59
|
+
const filteredSettings = {};
|
|
60
|
+
// Only include the requested keys from settings
|
|
61
|
+
keys.forEach((key) => {
|
|
62
|
+
if (settings && settings[key] !== undefined) {
|
|
63
|
+
filteredSettings[key] = settings[key];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
...propertyPreferences.rows[0],
|
|
68
|
+
settings: filteredSettings,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
57
71
|
return propertyPreferences.rows[0];
|
|
58
72
|
}
|
|
59
73
|
return null;
|
|
60
74
|
}
|
|
61
75
|
catch (error) {
|
|
62
|
-
console.
|
|
76
|
+
console.error("Error in getPropertyPreferences:", error);
|
|
63
77
|
throw new Error("Failed to get property preferences");
|
|
64
78
|
}
|
|
65
79
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare class LocalPropertyService {
|
|
2
2
|
private readonly propertyRepository;
|
|
3
3
|
constructor();
|
|
4
|
-
getPropertyPreferences(propertyId: string): Promise<import("./IProperty").IPropertySettings | null>;
|
|
4
|
+
getPropertyPreferences(propertyId: string, keys?: string[]): Promise<import("./IProperty").IPropertySettings | null>;
|
|
5
5
|
getProperty(propertyId: string): Promise<import("./IProperty").IProperty | null>;
|
|
6
6
|
getPropertyTimeZone(propertyId: string): Promise<string>;
|
|
7
7
|
getAllProperties(): Promise<any[]>;
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
2
18
|
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
19
|
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
20
|
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
@@ -33,20 +49,33 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
33
49
|
}
|
|
34
50
|
return useValue ? value : void 0;
|
|
35
51
|
};
|
|
52
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
53
|
+
var ownKeys = function(o) {
|
|
54
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
55
|
+
var ar = [];
|
|
56
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
57
|
+
return ar;
|
|
58
|
+
};
|
|
59
|
+
return ownKeys(o);
|
|
60
|
+
};
|
|
61
|
+
return function (mod) {
|
|
62
|
+
if (mod && mod.__esModule) return mod;
|
|
63
|
+
var result = {};
|
|
64
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
65
|
+
__setModuleDefault(result, mod);
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
})();
|
|
36
69
|
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
70
|
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
71
|
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
72
|
};
|
|
40
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
-
};
|
|
43
73
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
74
|
exports.LocalPropertyService = void 0;
|
|
45
75
|
const Property_repository_1 = require("./Property.repository");
|
|
46
|
-
const typedi_1 =
|
|
47
|
-
const typedi_2 = require("typedi");
|
|
76
|
+
const typedi_1 = __importStar(require("typedi"));
|
|
48
77
|
let LocalPropertyService = (() => {
|
|
49
|
-
let _classDecorators = [(0,
|
|
78
|
+
let _classDecorators = [(0, typedi_1.Service)()];
|
|
50
79
|
let _classDescriptor;
|
|
51
80
|
let _classExtraInitializers = [];
|
|
52
81
|
let _classThis;
|
|
@@ -55,11 +84,11 @@ let LocalPropertyService = (() => {
|
|
|
55
84
|
// Use dependency injection instead of creating new instance
|
|
56
85
|
this.propertyRepository = typedi_1.default.get(Property_repository_1.PropertyRepository);
|
|
57
86
|
}
|
|
58
|
-
async getPropertyPreferences(propertyId) {
|
|
87
|
+
async getPropertyPreferences(propertyId, keys) {
|
|
59
88
|
if (!propertyId) {
|
|
60
89
|
throw new Error("Property ID is required");
|
|
61
90
|
}
|
|
62
|
-
return await this.propertyRepository.getPropertyPreferences(propertyId);
|
|
91
|
+
return await this.propertyRepository.getPropertyPreferences(propertyId, keys);
|
|
63
92
|
}
|
|
64
93
|
async getProperty(propertyId) {
|
|
65
94
|
if (!propertyId) {
|