dt-common-device 1.2.2 → 1.2.4
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/device/cloud/entities/CloudDevice.d.ts +1 -1
- package/dist/device/cloud/entities/CloudDeviceService.d.ts +1 -1
- package/dist/device/cloud/entities/index.d.ts +0 -1
- package/dist/device/cloud/entities/index.js +0 -1
- package/dist/device/cloud/interfaces/ICloudDeviceService.d.ts +1 -1
- package/dist/device/cloud/interfaces/index.d.ts +1 -1
- package/dist/device/cloud/interfaces/index.js +1 -1
- package/dist/device/cloud/types.d.ts +1 -0
- package/dist/device/local/events/EventHandler.d.ts +1 -0
- package/dist/device/local/events/EventHandler.js +11 -0
- package/dist/device/local/interfaces/IConnection.d.ts +12 -2
- package/dist/device/local/interfaces/IConnection.js +12 -0
- package/dist/device/local/interfaces/IProperty.d.ts +5 -0
- package/dist/device/local/interfaces/ISchedule.d.ts +25 -0
- package/dist/device/local/interfaces/ISchedule.js +2 -0
- package/dist/device/local/repository/Connection.repository.d.ts +2 -1
- package/dist/device/local/repository/Connection.repository.js +15 -0
- package/dist/device/local/repository/Hub.repository.d.ts +1 -1
- package/dist/device/local/repository/Property.repository.d.ts +2 -6
- package/dist/device/local/repository/Property.repository.js +1 -5
- package/dist/device/local/repository/Schedule.repository.d.ts +8 -0
- package/dist/device/local/repository/Schedule.repository.js +102 -0
- package/dist/device/local/services/Connection.service.d.ts +3 -2
- package/dist/device/local/services/Connection.service.js +15 -0
- package/dist/device/local/services/Device.service.d.ts +0 -1
- package/dist/device/local/services/Device.service.js +46 -13
- package/dist/device/local/services/Hub.service.d.ts +1 -1
- package/dist/device/local/services/Hub.service.js +18 -0
- package/dist/device/local/services/Property.service.d.ts +1 -5
- package/dist/device/local/services/Property.service.js +9 -0
- package/dist/device/local/services/Schedule.service.d.ts +8 -0
- package/dist/device/local/services/Schedule.service.js +23 -0
- package/dist/device/local/services/index.d.ts +1 -0
- package/dist/device/local/services/index.js +3 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +3 -4
- package/package.json +4 -4
- package/src/device/cloud/entities/CloudDevice.ts +1 -1
- package/src/device/cloud/entities/CloudDeviceService.ts +1 -1
- package/src/device/cloud/entities/index.ts +0 -1
- package/src/device/cloud/interfaces/ICloudDeviceService.ts +1 -1
- package/src/device/cloud/interfaces/index.ts +1 -1
- package/src/device/local/events/EventHandler.ts +16 -0
- package/src/device/local/interfaces/IConnection.ts +27 -0
- package/src/device/local/interfaces/IProperty.ts +6 -0
- package/src/device/local/interfaces/ISchedule.ts +40 -0
- package/src/device/local/repository/Connection.repository.ts +21 -1
- package/src/device/local/repository/Hub.repository.ts +1 -1
- package/src/device/local/repository/Property.repository.ts +3 -7
- package/src/device/local/repository/Schedule.repository.ts +56 -0
- package/src/device/local/services/Connection.service.ts +23 -2
- package/src/device/local/services/Device.service.ts +47 -25
- package/src/device/local/services/Hub.service.ts +20 -1
- package/src/device/local/services/Property.service.ts +9 -0
- package/src/device/local/services/Schedule.service.ts +22 -0
- package/src/device/local/services/index.ts +1 -0
- package/src/index.ts +2 -3
- package/src/device/cloud/entities/CloudConnection.ts +0 -13
- package/src/device/cloud/interfaces/ICloudConnection.ts +0 -6
- package/src/device/cloud/types.ts +0 -57
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IDevice } from "../../local/interfaces";
|
|
2
2
|
import { ICloudDevice } from "../interfaces/ICloudDevice";
|
|
3
3
|
import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
|
|
4
|
-
import { IConnection } from "
|
|
4
|
+
import { IConnection } from "../../local/interfaces/IConnection";
|
|
5
5
|
export declare abstract class CloudDevice implements ICloudDevice {
|
|
6
6
|
deviceId: string;
|
|
7
7
|
localDevice?: IDevice;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ICloudDeviceService } from "../interfaces/ICloudDeviceService";
|
|
2
|
-
import { IConnection } from "
|
|
2
|
+
import { IConnection } from "../../local/interfaces/IConnection";
|
|
3
3
|
export declare class CloudDeviceService implements ICloudDeviceService {
|
|
4
4
|
getConnection(deviceId: string): Promise<IConnection>;
|
|
5
5
|
}
|
|
@@ -16,5 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./CloudDevice"), exports);
|
|
18
18
|
__exportStar(require("./DeviceFactory"), exports);
|
|
19
|
-
__exportStar(require("./CloudConnection"), exports);
|
|
20
19
|
__exportStar(require("./CloudDeviceService"), exports);
|
|
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./ICloudConnection"), exports);
|
|
18
17
|
__exportStar(require("./ICloudDevice"), exports);
|
|
19
18
|
__exportStar(require("./ICloudDeviceService"), exports);
|
|
19
|
+
__exportStar(require("./IDeviceFactory"), exports);
|
|
@@ -7,4 +7,5 @@ export declare class EventHandler {
|
|
|
7
7
|
onStateChange(deviceId: string, state: any): Promise<void>;
|
|
8
8
|
onStatusChange(deviceId: string, status: any): Promise<void>;
|
|
9
9
|
onBatteryLevelChange(deviceId: string, batteryLevel: number): Promise<void>;
|
|
10
|
+
onDeviceMetaChange(deviceId: string, metaData: Record<string, any>): Promise<void>;
|
|
10
11
|
}
|
|
@@ -71,5 +71,16 @@ class EventHandler {
|
|
|
71
71
|
};
|
|
72
72
|
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
73
73
|
}
|
|
74
|
+
async onDeviceMetaChange(deviceId, metaData) {
|
|
75
|
+
await dt_pub_sub_1.eventDispatcher.publishEvent(Events_1.DeviceEvents.DEVICE_META_DATA_SET, { deviceId, metaData }, this.source);
|
|
76
|
+
const payload = {
|
|
77
|
+
eventType: Events_1.DeviceEvents.DEVICE_META_DATA_SET,
|
|
78
|
+
properties: {
|
|
79
|
+
deviceId,
|
|
80
|
+
metaData,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
84
|
+
}
|
|
74
85
|
}
|
|
75
86
|
exports.EventHandler = EventHandler;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ConnectionProvider } from "../../cloud/types";
|
|
2
1
|
export interface IConnection {
|
|
3
2
|
id?: string;
|
|
4
3
|
createdAt?: Date;
|
|
@@ -9,8 +8,19 @@ export interface IConnection {
|
|
|
9
8
|
propertyId: string;
|
|
10
9
|
connectionProvider: ConnectionProvider;
|
|
11
10
|
accessToken?: string;
|
|
11
|
+
refreshToken?: string;
|
|
12
12
|
clientId?: string;
|
|
13
|
-
clientSecret
|
|
13
|
+
clientSecret: string;
|
|
14
14
|
isActive?: boolean;
|
|
15
15
|
metaData?: any;
|
|
16
16
|
}
|
|
17
|
+
export declare enum ConnectionProvider {
|
|
18
|
+
Smartthings = "Smartthings",
|
|
19
|
+
SaltoKS = "SaltoKS",
|
|
20
|
+
TTLock = "TTLock",
|
|
21
|
+
Tuya = "Tuya",
|
|
22
|
+
Schlage = "Schlage",
|
|
23
|
+
YaleWifi = "YaleWifi",
|
|
24
|
+
Sensibo = "Sensibo",
|
|
25
|
+
Devicethread = "Devicethread"
|
|
26
|
+
}
|
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionProvider = void 0;
|
|
4
|
+
var ConnectionProvider;
|
|
5
|
+
(function (ConnectionProvider) {
|
|
6
|
+
ConnectionProvider["Smartthings"] = "Smartthings";
|
|
7
|
+
ConnectionProvider["SaltoKS"] = "SaltoKS";
|
|
8
|
+
ConnectionProvider["TTLock"] = "TTLock";
|
|
9
|
+
ConnectionProvider["Tuya"] = "Tuya";
|
|
10
|
+
ConnectionProvider["Schlage"] = "Schlage";
|
|
11
|
+
ConnectionProvider["YaleWifi"] = "YaleWifi";
|
|
12
|
+
ConnectionProvider["Sensibo"] = "Sensibo";
|
|
13
|
+
ConnectionProvider["Devicethread"] = "Devicethread";
|
|
14
|
+
})(ConnectionProvider || (exports.ConnectionProvider = ConnectionProvider = {}));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface ISchedule {
|
|
2
|
+
id?: string;
|
|
3
|
+
name: string;
|
|
4
|
+
deviceId: string;
|
|
5
|
+
scheduleId: string | null;
|
|
6
|
+
state: {
|
|
7
|
+
targetTemperature?: number;
|
|
8
|
+
temperatureUnit?: "C" | "F";
|
|
9
|
+
mode?: "cool" | "heat" | "fan" | "dry" | "auto";
|
|
10
|
+
swing?: "stopped" | "rangeFull" | "fixedTop" | "fixedMiddleTop" | "fixedMiddle" | "fixedMiddleBottom" | "fixedBottom";
|
|
11
|
+
fanLevel?: "auto" | "low" | "medium" | "high";
|
|
12
|
+
};
|
|
13
|
+
startTime: string;
|
|
14
|
+
endTime: string;
|
|
15
|
+
recurringDays: ("Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday")[];
|
|
16
|
+
createTime?: string;
|
|
17
|
+
nextTime?: string;
|
|
18
|
+
nextTimeSecondsFromNow?: number;
|
|
19
|
+
targetTimeLocal: string;
|
|
20
|
+
timezone: string;
|
|
21
|
+
scheduleInheritedFrom: "zone" | "device";
|
|
22
|
+
zoneId: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
status?: "SET" | "UNSET";
|
|
25
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IConnection } from "
|
|
1
|
+
import { IConnection } from "../interfaces/IConnection";
|
|
2
2
|
export declare class ConnectionRepository {
|
|
3
3
|
private readonly pool;
|
|
4
4
|
constructor();
|
|
5
|
+
createConnection(data: Partial<IConnection>): Promise<IConnection>;
|
|
5
6
|
getConnectionById(connectionId: string): Promise<IConnection>;
|
|
6
7
|
updateConnection(connectionId: string, data: Partial<IConnection>): Promise<any>;
|
|
7
8
|
}
|
|
@@ -50,6 +50,21 @@ let ConnectionRepository = (() => {
|
|
|
50
50
|
constructor() {
|
|
51
51
|
this.pool = (0, db_1.getPostgresClient)();
|
|
52
52
|
}
|
|
53
|
+
async createConnection(data) {
|
|
54
|
+
const result = await this.pool.query("INSERT INTO dt_connections (connectionName, connectionRefId, propertyId, connectionProvider, accessToken, refreshToken, clientId, clientSecret, isActive, metaData) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *", [
|
|
55
|
+
data.connectionName,
|
|
56
|
+
data.connectionRefId,
|
|
57
|
+
data.propertyId,
|
|
58
|
+
data.connectionProvider,
|
|
59
|
+
data.accessToken,
|
|
60
|
+
data.refreshToken,
|
|
61
|
+
data.clientId,
|
|
62
|
+
data.clientSecret,
|
|
63
|
+
data.isActive,
|
|
64
|
+
data.metaData,
|
|
65
|
+
]);
|
|
66
|
+
return result.rows[0];
|
|
67
|
+
}
|
|
53
68
|
async getConnectionById(connectionId) {
|
|
54
69
|
const result = await this.pool.query("SELECT * FROM dt_connections WHERE id = $1", [connectionId]);
|
|
55
70
|
return result.rows[0];
|
|
@@ -3,7 +3,7 @@ export declare class HubRepository {
|
|
|
3
3
|
private readonly baseUrl;
|
|
4
4
|
private readonly postgres;
|
|
5
5
|
constructor();
|
|
6
|
-
addHub(body:
|
|
6
|
+
addHub(body: Partial<IDevice>): Promise<IDevice>;
|
|
7
7
|
getHubs(hubIds: string[]): Promise<IDevice[]>;
|
|
8
8
|
getHub(hubId: string): Promise<IDevice>;
|
|
9
9
|
updateHub(hubId: string, body: any): Promise<IDevice>;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { IProperty } from "../interfaces/IProperty";
|
|
1
|
+
import { IProperty, IPropertySettings } from "../interfaces/IProperty";
|
|
2
2
|
export declare class PropertyRepository {
|
|
3
3
|
private readonly postgres;
|
|
4
4
|
constructor();
|
|
5
|
-
getPropertyPreferences(propertyId: string): Promise<
|
|
6
|
-
id: string;
|
|
7
|
-
propertyId: string;
|
|
8
|
-
settings: string;
|
|
9
|
-
} | null>;
|
|
5
|
+
getPropertyPreferences(propertyId: string): Promise<IPropertySettings | null>;
|
|
10
6
|
getProperty(propertyId: string): Promise<IProperty | null>;
|
|
11
7
|
}
|
|
@@ -54,11 +54,7 @@ let PropertyRepository = (() => {
|
|
|
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
|
-
return
|
|
58
|
-
id: propertyPreferences.rows[0].id,
|
|
59
|
-
propertyId: propertyPreferences.rows[0].propertyId,
|
|
60
|
-
settings: JSON.parse(propertyPreferences.rows[0].settings),
|
|
61
|
-
};
|
|
57
|
+
return propertyPreferences.rows[0];
|
|
62
58
|
}
|
|
63
59
|
return null;
|
|
64
60
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ISchedule } from "../interfaces/ISchedule";
|
|
2
|
+
export declare class ScheduleRepository {
|
|
3
|
+
private readonly baseUrl;
|
|
4
|
+
constructor();
|
|
5
|
+
getSchedule(scheduleId: string): Promise<any>;
|
|
6
|
+
getScheduleByZone(zoneId: string): Promise<any>;
|
|
7
|
+
setSchedule(scheduleId: string, schedule: ISchedule): Promise<any>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
37
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
38
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
39
|
+
};
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.ScheduleRepository = void 0;
|
|
45
|
+
const typedi_1 = require("typedi");
|
|
46
|
+
const config_1 = require("../../../config/config");
|
|
47
|
+
const axios_1 = __importDefault(require("axios"));
|
|
48
|
+
let ScheduleRepository = (() => {
|
|
49
|
+
let _classDecorators = [(0, typedi_1.Service)()];
|
|
50
|
+
let _classDescriptor;
|
|
51
|
+
let _classExtraInitializers = [];
|
|
52
|
+
let _classThis;
|
|
53
|
+
var ScheduleRepository = _classThis = class {
|
|
54
|
+
constructor() {
|
|
55
|
+
const { DEVICE_SERVICE } = (0, config_1.getConfig)();
|
|
56
|
+
if (!DEVICE_SERVICE) {
|
|
57
|
+
throw new Error("DEVICE_SERVICE is not configured. Call initialize() first with DEVICE_SERVICE.");
|
|
58
|
+
}
|
|
59
|
+
this.baseUrl = DEVICE_SERVICE;
|
|
60
|
+
}
|
|
61
|
+
async getSchedule(scheduleId) {
|
|
62
|
+
try {
|
|
63
|
+
const response = await axios_1.default.get(`${this.baseUrl}/devices/schedule?id=${scheduleId}`);
|
|
64
|
+
return response.data;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.log(error);
|
|
68
|
+
throw new Error(`Failed to get schedule: ${error.response.data.message}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async getScheduleByZone(zoneId) {
|
|
72
|
+
try {
|
|
73
|
+
const response = await axios_1.default.get(`${this.baseUrl}/devices/schedules?zoneId=${zoneId}`);
|
|
74
|
+
return response.data;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.log(error);
|
|
78
|
+
throw new Error(`Failed to get schedule: ${error.response.data.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async setSchedule(scheduleId, schedule) {
|
|
82
|
+
try {
|
|
83
|
+
const response = await axios_1.default.put(`${this.baseUrl}/devices/schedules/${scheduleId}`, schedule);
|
|
84
|
+
return response.data;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.log(error);
|
|
88
|
+
throw new Error(`Failed to update schedule: ${error.response.data.message}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
__setFunctionName(_classThis, "ScheduleRepository");
|
|
93
|
+
(() => {
|
|
94
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
95
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
96
|
+
ScheduleRepository = _classThis = _classDescriptor.value;
|
|
97
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
98
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
99
|
+
})();
|
|
100
|
+
return ScheduleRepository = _classThis;
|
|
101
|
+
})();
|
|
102
|
+
exports.ScheduleRepository = ScheduleRepository;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IConnection } from "
|
|
1
|
+
import { IConnection } from "../interfaces/IConnection";
|
|
2
2
|
export declare class LocalConnectionService {
|
|
3
3
|
private readonly connectionRepository;
|
|
4
4
|
constructor();
|
|
5
|
+
createConnection(data: Partial<IConnection>): Promise<IConnection>;
|
|
5
6
|
getConnection(connectionId: string): Promise<IConnection>;
|
|
6
|
-
updateConnection(connectionId: string, data:
|
|
7
|
+
updateConnection(connectionId: string, data: Partial<IConnection>): Promise<IConnection>;
|
|
7
8
|
}
|
|
@@ -7,10 +7,25 @@ class LocalConnectionService {
|
|
|
7
7
|
constructor() {
|
|
8
8
|
this.connectionRepository = typedi_1.Container.get(Connection_repository_1.ConnectionRepository);
|
|
9
9
|
}
|
|
10
|
+
async createConnection(data) {
|
|
11
|
+
if (!data.connectionName ||
|
|
12
|
+
!data.connectionRefId ||
|
|
13
|
+
!data.propertyId ||
|
|
14
|
+
!data.connectionProvider) {
|
|
15
|
+
throw new Error("Missing required fields");
|
|
16
|
+
}
|
|
17
|
+
return await this.connectionRepository.createConnection(data);
|
|
18
|
+
}
|
|
10
19
|
async getConnection(connectionId) {
|
|
20
|
+
if (!connectionId) {
|
|
21
|
+
throw new Error("Connection ID is required");
|
|
22
|
+
}
|
|
11
23
|
return await this.connectionRepository.getConnectionById(connectionId);
|
|
12
24
|
}
|
|
13
25
|
async updateConnection(connectionId, data) {
|
|
26
|
+
if (!connectionId) {
|
|
27
|
+
throw new Error("Connection ID is required");
|
|
28
|
+
}
|
|
14
29
|
return await this.connectionRepository.updateConnection(connectionId, data);
|
|
15
30
|
}
|
|
16
31
|
}
|
|
@@ -5,8 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.LocalDeviceService = void 0;
|
|
7
7
|
const config_1 = require("../../../config/config");
|
|
8
|
-
const dt_pub_sub_1 = require("dt-pub-sub");
|
|
9
|
-
const dt_audit_library_1 = require("dt-audit-library");
|
|
10
8
|
const EventHandler_1 = require("../events/EventHandler");
|
|
11
9
|
const lodash_1 = require("lodash");
|
|
12
10
|
const Alert_service_1 = require("./Alert.service");
|
|
@@ -14,8 +12,6 @@ const Device_repository_1 = require("../repository/Device.repository");
|
|
|
14
12
|
const typedi_1 = __importDefault(require("typedi"));
|
|
15
13
|
class LocalDeviceService {
|
|
16
14
|
constructor() {
|
|
17
|
-
this.source = "dt-common-device";
|
|
18
|
-
// this.redis = getRedisClient();
|
|
19
15
|
(0, config_1.checkAwsEnv)();
|
|
20
16
|
(0, config_1.ensureAuditInitialized)();
|
|
21
17
|
this.eventHandler = new EventHandler_1.EventHandler();
|
|
@@ -26,24 +22,45 @@ class LocalDeviceService {
|
|
|
26
22
|
return await this.eventHandler.onDeviceCreate(body);
|
|
27
23
|
}
|
|
28
24
|
async getDevice(deviceId, withHubDetails = false) {
|
|
25
|
+
if (!deviceId) {
|
|
26
|
+
throw new Error("Device ID is required");
|
|
27
|
+
}
|
|
29
28
|
return await this.deviceRepository.getDevice(deviceId, withHubDetails);
|
|
30
29
|
}
|
|
31
30
|
async getDevices(deviceIds, withHubDetails = false) {
|
|
31
|
+
if (!deviceIds.length) {
|
|
32
|
+
throw new Error("At least one device ID is required");
|
|
33
|
+
}
|
|
32
34
|
return await this.deviceRepository.getDevices(deviceIds, withHubDetails);
|
|
33
35
|
}
|
|
34
36
|
async getPropertyDevices(propertyId, withHubDetails = false) {
|
|
37
|
+
if (!propertyId) {
|
|
38
|
+
throw new Error("Property ID is required");
|
|
39
|
+
}
|
|
35
40
|
return await this.deviceRepository.getPropertyDevices(propertyId, withHubDetails);
|
|
36
41
|
}
|
|
37
42
|
async updateDevice(deviceId, body) {
|
|
43
|
+
if (!deviceId) {
|
|
44
|
+
throw new Error("Device ID is required");
|
|
45
|
+
}
|
|
38
46
|
return await this.eventHandler.onDeviceUpdate(deviceId, body);
|
|
39
47
|
}
|
|
40
48
|
async deleteDevice(deviceId) {
|
|
49
|
+
if (!deviceId) {
|
|
50
|
+
throw new Error("Device ID is required");
|
|
51
|
+
}
|
|
41
52
|
return await this.eventHandler.onDeviceDelete(deviceId);
|
|
42
53
|
}
|
|
43
54
|
async getState(deviceId) {
|
|
55
|
+
if (!deviceId) {
|
|
56
|
+
throw new Error("Device ID is required");
|
|
57
|
+
}
|
|
44
58
|
return await this.deviceRepository.getState(deviceId);
|
|
45
59
|
}
|
|
46
60
|
async setState(deviceId, newState) {
|
|
61
|
+
if (!deviceId || !newState) {
|
|
62
|
+
throw new Error("Device ID and new state are required");
|
|
63
|
+
}
|
|
47
64
|
// If old state and new state are different
|
|
48
65
|
const oldState = (await this.getState(deviceId))?.data?.state || {};
|
|
49
66
|
const changedKeys = Object.keys(newState).filter((key) => !(0, lodash_1.isEqual)(oldState[key], newState[key]));
|
|
@@ -52,9 +69,15 @@ class LocalDeviceService {
|
|
|
52
69
|
}
|
|
53
70
|
}
|
|
54
71
|
async getStatus(deviceId) {
|
|
72
|
+
if (!deviceId) {
|
|
73
|
+
throw new Error("Device ID is required");
|
|
74
|
+
}
|
|
55
75
|
return await this.deviceRepository.getStatus(deviceId);
|
|
56
76
|
}
|
|
57
77
|
async setStatus(deviceId, newStatus) {
|
|
78
|
+
if (!deviceId || !newStatus) {
|
|
79
|
+
throw new Error("Device ID and new status are required");
|
|
80
|
+
}
|
|
58
81
|
// If old status and new status are different
|
|
59
82
|
const oldStatus = await this.getStatus(deviceId);
|
|
60
83
|
const changedKeys = Object.keys(newStatus).filter((key) => !(0, lodash_1.isEqual)(oldStatus?.data?.[key], newStatus?.[key]));
|
|
@@ -75,9 +98,15 @@ class LocalDeviceService {
|
|
|
75
98
|
}
|
|
76
99
|
}
|
|
77
100
|
async getBatteryLevel(deviceId) {
|
|
101
|
+
if (!deviceId) {
|
|
102
|
+
throw new Error("Device ID is required");
|
|
103
|
+
}
|
|
78
104
|
return await this.deviceRepository.getBatteryLevel(deviceId);
|
|
79
105
|
}
|
|
80
106
|
async setBatteryLevel(deviceId, newBatteryLevel) {
|
|
107
|
+
if (!deviceId || !newBatteryLevel) {
|
|
108
|
+
throw new Error("Device ID and new battery level are required");
|
|
109
|
+
}
|
|
81
110
|
// If old battery level and new battery level are different
|
|
82
111
|
const oldBatteryLevel = await this.getBatteryLevel(deviceId);
|
|
83
112
|
const changedKeys = Object.keys(newBatteryLevel).filter((key) => !(0, lodash_1.isEqual)(oldBatteryLevel?.data?.[key], newBatteryLevel?.[key]));
|
|
@@ -94,23 +123,27 @@ class LocalDeviceService {
|
|
|
94
123
|
}
|
|
95
124
|
}
|
|
96
125
|
async getMetaData(deviceId) {
|
|
126
|
+
if (!deviceId) {
|
|
127
|
+
throw new Error("Device ID is required");
|
|
128
|
+
}
|
|
97
129
|
return await this.deviceRepository.getMetaData(deviceId);
|
|
98
130
|
}
|
|
99
131
|
async setMetaData(deviceId, metaData) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
deviceId,
|
|
105
|
-
metaData,
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
await (0, dt_audit_library_1.publishAudit)(payload);
|
|
132
|
+
if (!deviceId || !metaData) {
|
|
133
|
+
throw new Error("Device ID and meta data are required");
|
|
134
|
+
}
|
|
135
|
+
return await this.eventHandler.onDeviceMetaChange(deviceId, metaData);
|
|
109
136
|
}
|
|
110
137
|
async getDevicesByZone(zoneId) {
|
|
138
|
+
if (!zoneId) {
|
|
139
|
+
throw new Error("Zone ID is required");
|
|
140
|
+
}
|
|
111
141
|
return await this.deviceRepository.getDevicesByZone(zoneId);
|
|
112
142
|
}
|
|
113
143
|
async getDevicesByAccessGroup(accessGroupId) {
|
|
144
|
+
if (!accessGroupId) {
|
|
145
|
+
throw new Error("Access Group ID is required");
|
|
146
|
+
}
|
|
114
147
|
return await this.deviceRepository.getDevicesByAccessGroup(accessGroupId);
|
|
115
148
|
}
|
|
116
149
|
}
|
|
@@ -2,7 +2,7 @@ import { IDevice } from "../interfaces";
|
|
|
2
2
|
export declare class LocalHubService {
|
|
3
3
|
private readonly hubRepository;
|
|
4
4
|
constructor();
|
|
5
|
-
addHub(body: IDevice): Promise<IDevice>;
|
|
5
|
+
addHub(body: Partial<IDevice>): Promise<IDevice>;
|
|
6
6
|
getHubs(hubIds: string[]): Promise<IDevice[]>;
|
|
7
7
|
getHub(hubId: string): Promise<IDevice>;
|
|
8
8
|
updateHub(hubId: string, body: Partial<IDevice>): Promise<IDevice>;
|
|
@@ -14,21 +14,39 @@ class LocalHubService {
|
|
|
14
14
|
return await this.hubRepository.addHub(body);
|
|
15
15
|
}
|
|
16
16
|
async getHubs(hubIds) {
|
|
17
|
+
if (!hubIds.length) {
|
|
18
|
+
throw new Error("At least one hub ID is required");
|
|
19
|
+
}
|
|
17
20
|
return await this.hubRepository.getHubs(hubIds);
|
|
18
21
|
}
|
|
19
22
|
async getHub(hubId) {
|
|
23
|
+
if (!hubId) {
|
|
24
|
+
throw new Error("Hub ID is required");
|
|
25
|
+
}
|
|
20
26
|
return await this.hubRepository.getHub(hubId);
|
|
21
27
|
}
|
|
22
28
|
async updateHub(hubId, body) {
|
|
29
|
+
if (!hubId) {
|
|
30
|
+
throw new Error("Hub ID is required");
|
|
31
|
+
}
|
|
23
32
|
return await this.hubRepository.updateHub(hubId, body);
|
|
24
33
|
}
|
|
25
34
|
async getStatus(hubId) {
|
|
35
|
+
if (!hubId) {
|
|
36
|
+
throw new Error("Hub ID is required");
|
|
37
|
+
}
|
|
26
38
|
return await this.hubRepository.getStatus(hubId);
|
|
27
39
|
}
|
|
28
40
|
async deleteHub(hubId) {
|
|
41
|
+
if (!hubId) {
|
|
42
|
+
throw new Error("Hub ID is required");
|
|
43
|
+
}
|
|
29
44
|
return await this.hubRepository.deleteHub(hubId);
|
|
30
45
|
}
|
|
31
46
|
async deleteAllHubs(hubIds) {
|
|
47
|
+
if (!hubIds.length) {
|
|
48
|
+
throw new Error("At least one hub ID is required");
|
|
49
|
+
}
|
|
32
50
|
return await this.hubRepository.deleteAllHubs(hubIds);
|
|
33
51
|
}
|
|
34
52
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
export declare class LocalPropertyService {
|
|
2
2
|
private readonly propertyRepository;
|
|
3
3
|
constructor();
|
|
4
|
-
getPropertyPreferences(propertyId: string): Promise<
|
|
5
|
-
id: string;
|
|
6
|
-
propertyId: string;
|
|
7
|
-
settings: string;
|
|
8
|
-
} | null>;
|
|
4
|
+
getPropertyPreferences(propertyId: string): Promise<import("../interfaces/IProperty").IPropertySettings | null>;
|
|
9
5
|
getProperty(propertyId: string): Promise<import("../interfaces/IProperty").IProperty | null>;
|
|
10
6
|
getPropertyTimeZone(propertyId: string): Promise<string>;
|
|
11
7
|
}
|
|
@@ -7,12 +7,21 @@ class LocalPropertyService {
|
|
|
7
7
|
this.propertyRepository = new Property_repository_1.PropertyRepository();
|
|
8
8
|
}
|
|
9
9
|
async getPropertyPreferences(propertyId) {
|
|
10
|
+
if (!propertyId) {
|
|
11
|
+
throw new Error("Property ID is required");
|
|
12
|
+
}
|
|
10
13
|
return await this.propertyRepository.getPropertyPreferences(propertyId);
|
|
11
14
|
}
|
|
12
15
|
async getProperty(propertyId) {
|
|
16
|
+
if (!propertyId) {
|
|
17
|
+
throw new Error("Property ID is required");
|
|
18
|
+
}
|
|
13
19
|
return await this.propertyRepository.getProperty(propertyId);
|
|
14
20
|
}
|
|
15
21
|
async getPropertyTimeZone(propertyId) {
|
|
22
|
+
if (!propertyId) {
|
|
23
|
+
throw new Error("Property ID is required");
|
|
24
|
+
}
|
|
16
25
|
const property = await this.propertyRepository.getProperty(propertyId);
|
|
17
26
|
if (!property) {
|
|
18
27
|
throw new Error("Property not found");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ISchedule } from "../interfaces/ISchedule";
|
|
2
|
+
export declare class LocalScheduleService {
|
|
3
|
+
private readonly scheduleRepository;
|
|
4
|
+
constructor();
|
|
5
|
+
getSchedule(scheduleId: string): Promise<any>;
|
|
6
|
+
setSchedule(scheduleId: string, schedule: ISchedule): Promise<any>;
|
|
7
|
+
getScheduleByZone(zoneId: string): Promise<any>;
|
|
8
|
+
}
|