@iobroker/dm-utils 0.1.2 → 0.1.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/README.md +4 -1
- package/build/DeviceManagement.d.ts +4 -4
- package/build/DeviceManagement.js +12 -11
- package/build/types/base.d.ts +1 -1
- package/build/types/common.d.ts +1 -1
- package/build/types/errorCodes.d.ts +14 -0
- package/build/types/errorCodes.js +18 -0
- package/build/types/index.d.ts +1 -0
- package/build/types/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -294,7 +294,10 @@ This method returns a promise that resolves to a `ProgressDialog` object.
|
|
|
294
294
|
### **WORK IN PROGRESS**
|
|
295
295
|
-->
|
|
296
296
|
## Changelog
|
|
297
|
-
### 0.1.
|
|
297
|
+
### 0.1.4 (2023-12-13)
|
|
298
|
+
* (bluefox) added error codes
|
|
299
|
+
|
|
300
|
+
### 0.1.3 (2023-12-10)
|
|
298
301
|
* (bluefox) added some fields to DeviceInfo interface
|
|
299
302
|
* (bluefox) added control possibilities
|
|
300
303
|
|
|
@@ -15,10 +15,10 @@ export declare abstract class DeviceManagement<T extends AdapterInstance = Adapt
|
|
|
15
15
|
protected getDeviceDetails(id: string): RetVal<DeviceDetails | null | {
|
|
16
16
|
error: string;
|
|
17
17
|
}>;
|
|
18
|
-
protected handleInstanceAction(actionId: string, context
|
|
19
|
-
protected handleDeviceAction(deviceId: string, actionId: string, context
|
|
20
|
-
protected handleDeviceControl(deviceId: string, controlId: string, newState: ControlState, context
|
|
21
|
-
protected handleDeviceControlState(deviceId: string, controlId: string, context
|
|
18
|
+
protected handleInstanceAction(actionId: string, context?: ActionContext): RetVal<ErrorResponse> | RetVal<RefreshResponse>;
|
|
19
|
+
protected handleDeviceAction(deviceId: string, actionId: string, context?: ActionContext): RetVal<ErrorResponse> | RetVal<RefreshResponse>;
|
|
20
|
+
protected handleDeviceControl(deviceId: string, controlId: string, newState: ControlState, context?: MessageContext): RetVal<ErrorResponse | ioBroker.State>;
|
|
21
|
+
protected handleDeviceControlState(deviceId: string, controlId: string, context?: MessageContext): RetVal<ErrorResponse | ioBroker.State>;
|
|
22
22
|
private onMessage;
|
|
23
23
|
private handleMessage;
|
|
24
24
|
private convertActions;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MessageContext = exports.DeviceManagement = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
4
5
|
class DeviceManagement {
|
|
5
6
|
constructor(adapter) {
|
|
6
7
|
this.adapter = adapter;
|
|
@@ -20,17 +21,17 @@ class DeviceManagement {
|
|
|
20
21
|
var _a;
|
|
21
22
|
if (!this.instanceInfo) {
|
|
22
23
|
this.log.warn(`Instance action ${actionId} was called before getInstanceInfo()`);
|
|
23
|
-
return { error: { code:
|
|
24
|
+
return { error: { code: types_1.ErrorCodes.E_INSTANCE_ACTION_NOT_INITIALIZED, message: `Instance action ${actionId} was called before getInstanceInfo()` } };
|
|
24
25
|
}
|
|
25
26
|
const action = (_a = this.instanceInfo.actions) === null || _a === void 0 ? void 0 : _a.find((a) => a.id === actionId);
|
|
26
27
|
if (!action) {
|
|
27
28
|
this.log.warn(`Instance action ${actionId} is unknown`);
|
|
28
|
-
return { error: { code:
|
|
29
|
+
return { error: { code: types_1.ErrorCodes.E_INSTANCE_ACTION_UNKNOWN, message: `Instance action ${actionId} is unknown` } };
|
|
29
30
|
}
|
|
30
31
|
if (!action.handler) {
|
|
31
32
|
this.log.warn(`Instance action ${actionId} is disabled because it has no handler`);
|
|
32
33
|
return {
|
|
33
|
-
error: { code:
|
|
34
|
+
error: { code: types_1.ErrorCodes.E_INSTANCE_ACTION_NO_HANDLER, message: `Instance action ${actionId} is disabled because it has no handler` },
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
37
|
return action.handler(context);
|
|
@@ -39,25 +40,25 @@ class DeviceManagement {
|
|
|
39
40
|
var _a;
|
|
40
41
|
if (!this.devices) {
|
|
41
42
|
this.log.warn(`Device action ${actionId} was called before listDevices()`);
|
|
42
|
-
return { error: { code:
|
|
43
|
+
return { error: { code: types_1.ErrorCodes.E_DEVICE_ACTION_NOT_INITIALIZED, message: `Device action ${actionId} was called before listDevices()` } };
|
|
43
44
|
}
|
|
44
45
|
const device = this.devices.get(deviceId);
|
|
45
46
|
if (!device) {
|
|
46
47
|
this.log.warn(`Device action ${actionId} was called on unknown device: ${deviceId}`);
|
|
47
48
|
return {
|
|
48
|
-
error: { code:
|
|
49
|
+
error: { code: types_1.ErrorCodes.E_DEVICE_ACTION_DEVICE_UNKNOWN, message: `Device action ${actionId} was called on unknown device: ${deviceId}` },
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
const action = (_a = device.actions) === null || _a === void 0 ? void 0 : _a.find((a) => a.id === actionId);
|
|
52
53
|
if (!action) {
|
|
53
54
|
this.log.warn(`Device action ${actionId} doesn't exist on device ${deviceId}`);
|
|
54
|
-
return { error: { code:
|
|
55
|
+
return { error: { code: types_1.ErrorCodes.E_DEVICE_ACTION_UNKNOWN, message: `Device action ${actionId} doesn't exist on device ${deviceId}` } };
|
|
55
56
|
}
|
|
56
57
|
if (!action.handler) {
|
|
57
58
|
this.log.warn(`Device action ${actionId} on ${deviceId} is disabled because it has no handler`);
|
|
58
59
|
return {
|
|
59
60
|
error: {
|
|
60
|
-
code:
|
|
61
|
+
code: types_1.ErrorCodes.E_DEVICE_ACTION_NO_HANDLER,
|
|
61
62
|
message: `Device action ${actionId} on ${deviceId} is disabled because it has no handler`,
|
|
62
63
|
},
|
|
63
64
|
};
|
|
@@ -68,25 +69,25 @@ class DeviceManagement {
|
|
|
68
69
|
var _a;
|
|
69
70
|
if (!this.devices) {
|
|
70
71
|
this.log.warn(`Device control ${controlId} was called before listDevices()`);
|
|
71
|
-
return { error: { code:
|
|
72
|
+
return { error: { code: types_1.ErrorCodes.E_DEVICE_CONTROL_NOT_INITIALIZED, message: `Device control ${controlId} was called before listDevices()` } };
|
|
72
73
|
}
|
|
73
74
|
const device = this.devices.get(deviceId);
|
|
74
75
|
if (!device) {
|
|
75
76
|
this.log.warn(`Device control ${controlId} was called on unknown device: ${deviceId}`);
|
|
76
77
|
return {
|
|
77
|
-
error: { code:
|
|
78
|
+
error: { code: types_1.ErrorCodes.E_DEVICE_CONTROL_DEVICE_UNKNOWN, message: `Device control ${controlId} was called on unknown device: ${deviceId}` },
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
const control = (_a = device.controls) === null || _a === void 0 ? void 0 : _a.find((a) => a.id === controlId);
|
|
81
82
|
if (!control) {
|
|
82
83
|
this.log.warn(`Device control ${controlId} doesn't exist on device ${deviceId}`);
|
|
83
|
-
return { error: { code:
|
|
84
|
+
return { error: { code: types_1.ErrorCodes.E_DEVICE_CONTROL_UNKNOWN, message: `Device control ${controlId} doesn't exist on device ${deviceId}` } };
|
|
84
85
|
}
|
|
85
86
|
if (!control.handler) {
|
|
86
87
|
this.log.warn(`Device control ${controlId} on ${deviceId} is disabled because it has no handler`);
|
|
87
88
|
return {
|
|
88
89
|
error: {
|
|
89
|
-
code:
|
|
90
|
+
code: types_1.ErrorCodes.E_DEVICE_CONTROL_NO_HANDLER,
|
|
90
91
|
message: `Device control ${controlId} on ${deviceId} is disabled because it has no handler`,
|
|
91
92
|
},
|
|
92
93
|
};
|
package/build/types/base.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface ControlBase {
|
|
|
36
36
|
color?: Color;
|
|
37
37
|
}[];
|
|
38
38
|
}
|
|
39
|
-
export interface DeviceControl<T extends ActionType = "api"> extends
|
|
39
|
+
export interface DeviceControl<T extends ActionType = "api"> extends ControlBase {
|
|
40
40
|
handler?: T extends "api" ? never : (deviceId: string, actionId: string, state: ControlState, context: MessageContext) => RetVal<ErrorResponse | ioBroker.State>;
|
|
41
41
|
getStateHandler?: T extends "api" ? never : (deviceId: string, actionId: string, context: MessageContext) => RetVal<ErrorResponse | ioBroker.State>;
|
|
42
42
|
}
|
package/build/types/common.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type DeviceStatus = "connected" | "disconnected" | {
|
|
|
5
5
|
*/
|
|
6
6
|
icon?: string;
|
|
7
7
|
battery?: number | boolean | "charging" | string;
|
|
8
|
-
connection
|
|
8
|
+
connection?: "connected" | "disconnected";
|
|
9
9
|
rssi?: number;
|
|
10
10
|
warning?: ioBroker.StringOrTranslated | boolean;
|
|
11
11
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare enum ErrorCodes {
|
|
2
|
+
E_INSTANCE_ACTION_NOT_INITIALIZED = 101,
|
|
3
|
+
E_INSTANCE_ACTION_UNKNOWN = 102,
|
|
4
|
+
E_INSTANCE_ACTION_NO_HANDLER = 103,
|
|
5
|
+
E_DEVICE_ACTION_NOT_INITIALIZED = 201,
|
|
6
|
+
E_DEVICE_ACTION_DEVICE_UNKNOWN = 202,
|
|
7
|
+
E_DEVICE_ACTION_UNKNOWN = 203,
|
|
8
|
+
E_DEVICE_ACTION_NO_HANDLER = 204,
|
|
9
|
+
E_DEVICE_CONTROL_NOT_INITIALIZED = 301,
|
|
10
|
+
E_DEVICE_CONTROL_DEVICE_UNKNOWN = 302,
|
|
11
|
+
E_DEVICE_CONTROL_UNKNOWN = 303,
|
|
12
|
+
E_DEVICE_CONTROL_NO_HANDLER = 304,
|
|
13
|
+
E_DEVICE_CONTROL_NO_STATE = 305
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorCodes = void 0;
|
|
4
|
+
var ErrorCodes;
|
|
5
|
+
(function (ErrorCodes) {
|
|
6
|
+
ErrorCodes[ErrorCodes["E_INSTANCE_ACTION_NOT_INITIALIZED"] = 101] = "E_INSTANCE_ACTION_NOT_INITIALIZED";
|
|
7
|
+
ErrorCodes[ErrorCodes["E_INSTANCE_ACTION_UNKNOWN"] = 102] = "E_INSTANCE_ACTION_UNKNOWN";
|
|
8
|
+
ErrorCodes[ErrorCodes["E_INSTANCE_ACTION_NO_HANDLER"] = 103] = "E_INSTANCE_ACTION_NO_HANDLER";
|
|
9
|
+
ErrorCodes[ErrorCodes["E_DEVICE_ACTION_NOT_INITIALIZED"] = 201] = "E_DEVICE_ACTION_NOT_INITIALIZED";
|
|
10
|
+
ErrorCodes[ErrorCodes["E_DEVICE_ACTION_DEVICE_UNKNOWN"] = 202] = "E_DEVICE_ACTION_DEVICE_UNKNOWN";
|
|
11
|
+
ErrorCodes[ErrorCodes["E_DEVICE_ACTION_UNKNOWN"] = 203] = "E_DEVICE_ACTION_UNKNOWN";
|
|
12
|
+
ErrorCodes[ErrorCodes["E_DEVICE_ACTION_NO_HANDLER"] = 204] = "E_DEVICE_ACTION_NO_HANDLER";
|
|
13
|
+
ErrorCodes[ErrorCodes["E_DEVICE_CONTROL_NOT_INITIALIZED"] = 301] = "E_DEVICE_CONTROL_NOT_INITIALIZED";
|
|
14
|
+
ErrorCodes[ErrorCodes["E_DEVICE_CONTROL_DEVICE_UNKNOWN"] = 302] = "E_DEVICE_CONTROL_DEVICE_UNKNOWN";
|
|
15
|
+
ErrorCodes[ErrorCodes["E_DEVICE_CONTROL_UNKNOWN"] = 303] = "E_DEVICE_CONTROL_UNKNOWN";
|
|
16
|
+
ErrorCodes[ErrorCodes["E_DEVICE_CONTROL_NO_HANDLER"] = 304] = "E_DEVICE_CONTROL_NO_HANDLER";
|
|
17
|
+
ErrorCodes[ErrorCodes["E_DEVICE_CONTROL_NO_STATE"] = 305] = "E_DEVICE_CONTROL_NO_STATE";
|
|
18
|
+
})(ErrorCodes || (exports.ErrorCodes = ErrorCodes = {}));
|
package/build/types/index.d.ts
CHANGED
package/build/types/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./adapter"), exports);
|
|
18
18
|
__exportStar(require("./common"), exports);
|
|
19
|
+
__exportStar(require("./errorCodes"), exports);
|