@iobroker/dm-utils 2.0.1 → 3.0.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/README.md +197 -123
- package/build/ActionContext.d.ts +2 -6
- package/build/DeviceManagement.d.ts +25 -29
- package/build/DeviceManagement.js +190 -106
- package/build/ProgressDialog.d.ts +2 -6
- package/build/types/adapter.d.ts +4 -3
- package/build/types/api.d.ts +58 -0
- package/build/types/base.d.ts +42 -27
- package/build/types/common.d.ts +108 -106
- package/build/types/index.d.ts +1 -1
- package/build/types/index.js +1 -1
- package/package.json +10 -6
package/build/types/api.d.ts
CHANGED
|
@@ -1,7 +1,65 @@
|
|
|
1
1
|
import type * as base from './base';
|
|
2
|
+
import type { ActionButton, DeviceId, ErrorResponse, JsonFormSchema, ProgressUpdate } from './common';
|
|
2
3
|
export type ActionBase = base.ActionBase<'api'>;
|
|
3
4
|
export type InstanceAction = base.InstanceAction<'api'>;
|
|
4
5
|
export type DeviceAction = base.DeviceAction<'api'>;
|
|
5
6
|
export type InstanceDetails = base.InstanceDetails<'api'>;
|
|
6
7
|
export type DeviceInfo = base.DeviceInfo<'api'>;
|
|
7
8
|
export type DeviceControl = base.DeviceControl<'api'>;
|
|
9
|
+
export type DeviceRefreshResponse = base.DeviceRefreshResponse<'api'>;
|
|
10
|
+
export type InstanceRefreshResponse = base.InstanceRefreshResponse;
|
|
11
|
+
export type DeviceLoadIncrement = {
|
|
12
|
+
add: DeviceInfo[];
|
|
13
|
+
total?: number;
|
|
14
|
+
next?: {
|
|
15
|
+
origin: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type DmResponseBase = {
|
|
19
|
+
origin: number;
|
|
20
|
+
};
|
|
21
|
+
export type DmControlResponse = DmResponseBase & {
|
|
22
|
+
type: 'result';
|
|
23
|
+
result: {
|
|
24
|
+
deviceId: DeviceId;
|
|
25
|
+
controlId: string;
|
|
26
|
+
} & (ErrorResponse | {
|
|
27
|
+
state: ioBroker.State;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export type DmActionResultResponse = DmResponseBase & {
|
|
31
|
+
type: 'result';
|
|
32
|
+
result: ErrorResponse | DeviceRefreshResponse | InstanceRefreshResponse;
|
|
33
|
+
};
|
|
34
|
+
export type DmActionMessageResponse = DmResponseBase & {
|
|
35
|
+
type: 'message';
|
|
36
|
+
message: ioBroker.StringOrTranslated;
|
|
37
|
+
};
|
|
38
|
+
export type DmActionConfirmResponse = DmResponseBase & {
|
|
39
|
+
type: 'confirm';
|
|
40
|
+
confirm: ioBroker.StringOrTranslated;
|
|
41
|
+
};
|
|
42
|
+
export interface CommunicationForm {
|
|
43
|
+
title?: ioBroker.StringOrTranslated | null | undefined;
|
|
44
|
+
label?: ioBroker.StringOrTranslated | null | undefined;
|
|
45
|
+
noTranslation?: boolean;
|
|
46
|
+
schema: JsonFormSchema;
|
|
47
|
+
data?: Record<string, any>;
|
|
48
|
+
buttons?: (ActionButton | 'apply' | 'cancel' | 'close')[];
|
|
49
|
+
maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
50
|
+
/** Minimal width of the dialog */
|
|
51
|
+
minWidth?: number;
|
|
52
|
+
/** Always allow the apply button. Even when nothing was changed */
|
|
53
|
+
ignoreApplyDisabled?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export type DmActionFormResponse = DmResponseBase & {
|
|
56
|
+
type: 'form';
|
|
57
|
+
form: CommunicationForm;
|
|
58
|
+
};
|
|
59
|
+
export type DmActionProgressResponse = DmResponseBase & {
|
|
60
|
+
type: 'progress';
|
|
61
|
+
progress: ProgressUpdate & {
|
|
62
|
+
open?: boolean;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export type DmActionResponse = DmActionResultResponse | DmActionMessageResponse | DmActionConfirmResponse | DmActionFormResponse | DmActionProgressResponse;
|
package/build/types/base.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ActionContext, ConfigConnectionType, ErrorResponse, MessageContext, ValueOrObject, ValueOrState, ValueOrStateOrObject } from '..';
|
|
2
|
-
import type { ApiVersion,
|
|
2
|
+
import type { ApiVersion, DeviceId, DeviceStatus, RetVal } from './common';
|
|
3
3
|
type ActionType = 'api' | 'adapter';
|
|
4
4
|
export type Color = 'primary' | 'secondary' | (string & {});
|
|
5
5
|
export type ControlState = string | number | boolean | null;
|
|
@@ -16,7 +16,7 @@ export interface ActionBase<T extends ActionType> {
|
|
|
16
16
|
/**
|
|
17
17
|
* This can either be base64 or the URL to an icon.
|
|
18
18
|
*/
|
|
19
|
-
icon?: 'edit' | 'rename' | 'delete' | 'refresh' | 'newDevice' | 'new' | 'add' | 'discover' | 'search' | 'unpairDevice' | 'pairDevice' | 'identify' | 'play' | 'stop' | 'pause' | 'forward' | 'next' | 'rewind' | 'previous' | 'lamp' | 'light' | 'backlight' | 'dimmer' | 'socket' | 'settings' | 'users' | 'group' | 'user' | string;
|
|
19
|
+
icon?: 'edit' | 'rename' | 'delete' | 'refresh' | 'newDevice' | 'new' | 'add' | 'discover' | 'search' | 'unpairDevice' | 'pairDevice' | 'identify' | 'play' | 'stop' | 'pause' | 'forward' | 'next' | 'rewind' | 'previous' | 'lamp' | 'light' | 'backlight' | 'dimmer' | 'socket' | 'settings' | 'users' | 'group' | 'user' | 'info' | (string & {});
|
|
20
20
|
description?: ioBroker.StringOrTranslated;
|
|
21
21
|
disabled?: T extends 'api' ? boolean : never;
|
|
22
22
|
color?: Color;
|
|
@@ -81,31 +81,46 @@ export interface ControlBase {
|
|
|
81
81
|
}[];
|
|
82
82
|
channel?: ChannelInfo;
|
|
83
83
|
}
|
|
84
|
-
export interface DeviceControl<
|
|
85
|
-
handler?:
|
|
86
|
-
getStateHandler?:
|
|
84
|
+
export interface DeviceControl<TType extends ActionType = 'api', TId extends DeviceId = DeviceId> extends ControlBase {
|
|
85
|
+
handler?: TType extends 'api' ? never : (deviceId: TId, actionId: string, state: ControlState, context: MessageContext<TId>) => RetVal<ErrorResponse | ioBroker.State>;
|
|
86
|
+
getStateHandler?: TType extends 'api' ? never : (deviceId: TId, actionId: string, context: MessageContext<TId>) => RetVal<ErrorResponse | ioBroker.State>;
|
|
87
87
|
}
|
|
88
|
-
export
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
export type InstanceRefreshResponse = {
|
|
89
|
+
refresh: boolean;
|
|
90
|
+
};
|
|
91
|
+
export type WithHandlerOrUrl<TType extends ActionType, THandler> = {
|
|
92
|
+
handler?: TType extends 'api' ? never : THandler;
|
|
93
|
+
} | {
|
|
94
|
+
url: ioBroker.StringOrTranslated;
|
|
95
|
+
};
|
|
96
|
+
export type InstanceAction<T extends ActionType = 'api'> = ActionBase<T> & WithHandlerOrUrl<T, (context: ActionContext, options?: Record<string, any>) => RetVal<InstanceRefreshResponse>> & {
|
|
92
97
|
title: ioBroker.StringOrTranslated;
|
|
93
|
-
}
|
|
94
|
-
export
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
};
|
|
99
|
+
export type DeviceUpdate<T extends ActionType = 'api', TId extends DeviceId = DeviceId> = {
|
|
100
|
+
update: DeviceInfo<T, TId>;
|
|
101
|
+
};
|
|
102
|
+
export type DeviceDelete<TId extends DeviceId = DeviceId> = {
|
|
103
|
+
delete: TId;
|
|
104
|
+
};
|
|
105
|
+
export type DeviceRefresh = 'all' | 'devices' | 'instance' | 'none';
|
|
106
|
+
export type DeviceRefreshResponse<T extends ActionType = 'api', TId extends DeviceId = DeviceId> = {
|
|
107
|
+
refresh: DeviceRefresh;
|
|
108
|
+
} | DeviceUpdate<T, TId> | DeviceDelete<TId>;
|
|
109
|
+
export type DeviceAction<T extends ActionType = 'api', TId extends DeviceId = DeviceId> = ActionBase<T> & WithHandlerOrUrl<T, (deviceId: TId, context: ActionContext, options?: Record<string, any>) => RetVal<DeviceRefreshResponse<'adapter', TId>>>;
|
|
99
110
|
export interface InstanceDetails<T extends ActionType = 'api'> {
|
|
100
111
|
/** API Version: 1 - till 2025 (including), 2 - from 2026 */
|
|
101
112
|
apiVersion: ApiVersion;
|
|
102
113
|
actions?: InstanceAction<T>[];
|
|
103
114
|
/** ID of state used for communication with GUI */
|
|
104
115
|
communicationStateId?: string;
|
|
116
|
+
/** Human-readable label next to the identifier */
|
|
117
|
+
identifierLabel?: ioBroker.StringOrTranslated;
|
|
105
118
|
}
|
|
106
|
-
export interface DeviceInfo<T extends ActionType = 'api'> {
|
|
107
|
-
/** ID of the
|
|
108
|
-
id:
|
|
119
|
+
export interface DeviceInfo<T extends ActionType = 'api', TId extends DeviceId = DeviceId> {
|
|
120
|
+
/** ID of the device. Must be unique only in one adapter. Other adapters could have same IDs */
|
|
121
|
+
id: TId;
|
|
122
|
+
/** Human-readable identifier of the device */
|
|
123
|
+
identifier?: ValueOrObject<string>;
|
|
109
124
|
/** Name of the device. It will be shown in the card header */
|
|
110
125
|
name: ValueOrObject<ioBroker.StringOrTranslated>;
|
|
111
126
|
/** base64 or url icon for device card */
|
|
@@ -122,9 +137,9 @@ export interface DeviceInfo<T extends ActionType = 'api'> {
|
|
|
122
137
|
/** If this flag is true or false, the according indication will be shown. Additionally, if ACTIONS.ENABLE_DISABLE is implemented, this action will be sent to backend by clicking on this indication */
|
|
123
138
|
enabled?: ValueOrState<boolean>;
|
|
124
139
|
/** List of actions on the card */
|
|
125
|
-
actions?: DeviceAction<T>[];
|
|
140
|
+
actions?: DeviceAction<T, TId>[];
|
|
126
141
|
/** List of controls on the card. The difference of controls and actions is that the controls can show status (e.g. on/off) and can work directly with states */
|
|
127
|
-
controls?: DeviceControl<T>[];
|
|
142
|
+
controls?: DeviceControl<T, TId>[];
|
|
128
143
|
/** If true, the button `more` will be shown on the card and called `dm:deviceDetails` action to get the details */
|
|
129
144
|
hasDetails?: ValueOrStateOrObject<boolean>;
|
|
130
145
|
/** Device type for grouping */
|
|
@@ -134,30 +149,30 @@ export interface DeviceInfo<T extends ActionType = 'api'> {
|
|
|
134
149
|
icon?: string;
|
|
135
150
|
};
|
|
136
151
|
}
|
|
137
|
-
export interface BackendToGuiCommandDeviceInfoUpdate {
|
|
152
|
+
export interface BackendToGuiCommandDeviceInfoUpdate<TId extends DeviceId = DeviceId> {
|
|
138
153
|
/** Used for updating and for adding new device */
|
|
139
154
|
command: 'infoUpdate';
|
|
140
155
|
/** Device ID */
|
|
141
|
-
deviceId:
|
|
156
|
+
deviceId: TId;
|
|
142
157
|
/** Backend can send directly new information about device to avoid extra request from GUI */
|
|
143
158
|
info?: DeviceInfo;
|
|
144
159
|
}
|
|
145
|
-
export interface BackendToGuiCommandDeviceStatusUpdate {
|
|
160
|
+
export interface BackendToGuiCommandDeviceStatusUpdate<TId extends DeviceId = DeviceId> {
|
|
146
161
|
/** Status of device was updated */
|
|
147
162
|
command: 'statusUpdate';
|
|
148
163
|
/** Device ID */
|
|
149
|
-
deviceId:
|
|
164
|
+
deviceId: TId;
|
|
150
165
|
/** Backend can send directly new status to avoid extra request from GUI */
|
|
151
166
|
status?: DeviceStatus;
|
|
152
167
|
}
|
|
153
|
-
export interface BackendToGuiCommandDeviceDelete {
|
|
168
|
+
export interface BackendToGuiCommandDeviceDelete<TId extends DeviceId = DeviceId> {
|
|
154
169
|
/** Device was deleted */
|
|
155
170
|
command: 'delete';
|
|
156
|
-
deviceId:
|
|
171
|
+
deviceId: TId;
|
|
157
172
|
}
|
|
158
173
|
export interface BackendToGuiCommandAllUpdate {
|
|
159
174
|
/** Read ALL information about all devices anew */
|
|
160
175
|
command: 'all';
|
|
161
176
|
}
|
|
162
|
-
export type BackendToGuiCommand = BackendToGuiCommandDeviceInfoUpdate | BackendToGuiCommandDeviceStatusUpdate | BackendToGuiCommandDeviceDelete | BackendToGuiCommandAllUpdate;
|
|
177
|
+
export type BackendToGuiCommand<TId extends DeviceId = DeviceId> = BackendToGuiCommandDeviceInfoUpdate<TId> | BackendToGuiCommandDeviceStatusUpdate<TId> | BackendToGuiCommandDeviceDelete<TId> | BackendToGuiCommandAllUpdate;
|
|
163
178
|
export {};
|