dt-common-device 2.0.5 → 2.0.7
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/interfaces/IRawDataTransformer.d.ts +1 -1
- package/dist/device/local/repository/Device.repository.d.ts +2 -0
- package/dist/device/local/repository/Device.repository.js +19 -0
- package/dist/device/local/services/Device.service.js +2 -0
- package/package.json +1 -1
- package/src/device/cloud/interfaces/IRawDataTransformer.ts +1 -1
- package/src/device/local/repository/Device.repository.ts +26 -0
- package/src/device/local/services/Device.service.ts +4 -0
|
@@ -6,6 +6,8 @@ export declare class DeviceRepository {
|
|
|
6
6
|
constructor();
|
|
7
7
|
createDevice(body: IDevice): Promise<IDevice>;
|
|
8
8
|
getDevice(deviceId: string, withHubDetails?: boolean): Promise<IDevice>;
|
|
9
|
+
updateDevice(deviceId: string, body: any): Promise<IDevice>;
|
|
10
|
+
deleteDevice(deviceId: string): Promise<void>;
|
|
9
11
|
getDevices(deviceIds: string[], withHubDetails?: boolean): Promise<IDevice[]>;
|
|
10
12
|
getPropertyDevices(propertyId: string, selectDeviceId?: boolean, type?: string, withHubDetails?: boolean): Promise<IDevice[]>;
|
|
11
13
|
getPropertyDeviceIds(propertyId: string, selectDeviceId: boolean | undefined, manufacturer: string): Promise<any>;
|
|
@@ -73,6 +73,25 @@ let DeviceRepository = (() => {
|
|
|
73
73
|
throw new Error(`Failed to get device: ${error.message || "Unknown error"}`);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
async updateDevice(deviceId, body) {
|
|
77
|
+
try {
|
|
78
|
+
const response = await this.axiosInstance.put(`/devices/${deviceId}`, body);
|
|
79
|
+
return response.data;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
(0, config_1.getConfig)().LOGGER.error(`Failed to update device ${deviceId}:`, error);
|
|
83
|
+
throw new Error(`Failed to update device: ${error.message || "Unknown error"}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async deleteDevice(deviceId) {
|
|
87
|
+
try {
|
|
88
|
+
await this.axiosInstance.delete(`/devices/${deviceId}`);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
(0, config_1.getConfig)().LOGGER.error(`Failed to delete device ${deviceId}:`, error);
|
|
92
|
+
throw new Error(`Failed to delete device: ${error.message || "Unknown error"}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
76
95
|
async getDevices(deviceIds, withHubDetails = false) {
|
|
77
96
|
try {
|
|
78
97
|
const response = await this.axiosInstance.get(`/devices`, {
|
|
@@ -46,12 +46,14 @@ class LocalDeviceService {
|
|
|
46
46
|
if (!deviceId) {
|
|
47
47
|
throw new Error("Device ID is required");
|
|
48
48
|
}
|
|
49
|
+
await this.deviceRepository.updateDevice(deviceId, body);
|
|
49
50
|
return await this.eventHandler.onDeviceUpdate(deviceId, body);
|
|
50
51
|
}
|
|
51
52
|
async deleteDevice(deviceId) {
|
|
52
53
|
if (!deviceId) {
|
|
53
54
|
throw new Error("Device ID is required");
|
|
54
55
|
}
|
|
56
|
+
await this.deviceRepository.deleteDevice(deviceId);
|
|
55
57
|
return await this.eventHandler.onDeviceDelete(deviceId);
|
|
56
58
|
}
|
|
57
59
|
async getState(deviceId) {
|
package/package.json
CHANGED
|
@@ -44,6 +44,32 @@ export class DeviceRepository {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
async updateDevice(deviceId: string, body: any): Promise<IDevice> {
|
|
48
|
+
try {
|
|
49
|
+
const response = await this.axiosInstance.put(
|
|
50
|
+
`/devices/${deviceId}`,
|
|
51
|
+
body
|
|
52
|
+
);
|
|
53
|
+
return response.data;
|
|
54
|
+
} catch (error: any) {
|
|
55
|
+
getConfig().LOGGER.error(`Failed to update device ${deviceId}:`, error);
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Failed to update device: ${error.message || "Unknown error"}`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async deleteDevice(deviceId: string): Promise<void> {
|
|
63
|
+
try {
|
|
64
|
+
await this.axiosInstance.delete(`/devices/${deviceId}`);
|
|
65
|
+
} catch (error: any) {
|
|
66
|
+
getConfig().LOGGER.error(`Failed to delete device ${deviceId}:`, error);
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Failed to delete device: ${error.message || "Unknown error"}`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
47
73
|
async getDevices(
|
|
48
74
|
deviceIds: string[],
|
|
49
75
|
withHubDetails: boolean = false
|
|
@@ -74,6 +74,8 @@ export class LocalDeviceService {
|
|
|
74
74
|
if (!deviceId) {
|
|
75
75
|
throw new Error("Device ID is required");
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
await this.deviceRepository.updateDevice(deviceId, body);
|
|
77
79
|
return await this.eventHandler.onDeviceUpdate(deviceId, body);
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -81,6 +83,8 @@ export class LocalDeviceService {
|
|
|
81
83
|
if (!deviceId) {
|
|
82
84
|
throw new Error("Device ID is required");
|
|
83
85
|
}
|
|
86
|
+
|
|
87
|
+
await this.deviceRepository.deleteDevice(deviceId);
|
|
84
88
|
return await this.eventHandler.onDeviceDelete(deviceId);
|
|
85
89
|
}
|
|
86
90
|
|