@iobroker/dm-utils 1.0.16 → 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 +226 -105
- package/build/ActionContext.d.ts +2 -6
- package/build/DeviceManagement.d.ts +27 -28
- package/build/DeviceManagement.js +229 -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 +74 -30
- package/build/types/common.d.ts +117 -102
- package/build/types/index.d.ts +1 -1
- package/build/types/index.js +1 -1
- package/package.json +10 -6
package/build/types/adapter.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type * as base from './base';
|
|
2
|
+
import type { DeviceId } from './common';
|
|
2
3
|
export type ActionBase = base.ActionBase<'adapter'>;
|
|
3
4
|
export type InstanceAction = base.InstanceAction<'adapter'>;
|
|
4
|
-
export type DeviceAction = base.DeviceAction<'adapter'>;
|
|
5
|
+
export type DeviceAction<TId extends DeviceId> = base.DeviceAction<'adapter', TId>;
|
|
5
6
|
export type InstanceDetails = base.InstanceDetails<'adapter'>;
|
|
6
|
-
export type DeviceInfo = base.DeviceInfo<'adapter'>;
|
|
7
|
-
export type DeviceControl = base.DeviceControl<'adapter'>;
|
|
7
|
+
export type DeviceInfo<TId extends DeviceId> = base.DeviceInfo<'adapter', TId>;
|
|
8
|
+
export type DeviceControl<TId extends DeviceId> = base.DeviceControl<'adapter', TId>;
|
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
|
-
import type { ActionContext, ConfigConnectionType, ErrorResponse, MessageContext } from '..';
|
|
2
|
-
import type { ApiVersion,
|
|
1
|
+
import type { ActionContext, ConfigConnectionType, ErrorResponse, MessageContext, ValueOrObject, ValueOrState, ValueOrStateOrObject } from '..';
|
|
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,49 +81,67 @@ 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'> {
|
|
111
|
+
/** API Version: 1 - till 2025 (including), 2 - from 2026 */
|
|
100
112
|
apiVersion: ApiVersion;
|
|
101
113
|
actions?: InstanceAction<T>[];
|
|
114
|
+
/** ID of state used for communication with GUI */
|
|
115
|
+
communicationStateId?: string;
|
|
116
|
+
/** Human-readable label next to the identifier */
|
|
117
|
+
identifierLabel?: ioBroker.StringOrTranslated;
|
|
102
118
|
}
|
|
103
|
-
export interface DeviceInfo<T extends ActionType = 'api'> {
|
|
104
|
-
/** ID of the
|
|
105
|
-
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>;
|
|
106
124
|
/** Name of the device. It will be shown in the card header */
|
|
107
|
-
name: ioBroker.StringOrTranslated
|
|
125
|
+
name: ValueOrObject<ioBroker.StringOrTranslated>;
|
|
108
126
|
/** base64 or url icon for device card */
|
|
109
|
-
icon?: string
|
|
110
|
-
manufacturer?: ioBroker.StringOrTranslated
|
|
111
|
-
model?: ioBroker.StringOrTranslated
|
|
127
|
+
icon?: ValueOrState<string>;
|
|
128
|
+
manufacturer?: ValueOrStateOrObject<ioBroker.StringOrTranslated>;
|
|
129
|
+
model?: ValueOrStateOrObject<ioBroker.StringOrTranslated>;
|
|
112
130
|
/** Color or 'primary', 'secondary' for the text in the card header */
|
|
113
|
-
color?: Color
|
|
131
|
+
color?: ValueOrState<Color>;
|
|
114
132
|
/** Background color of card header (you can use primary, secondary or color rgb value or hex) */
|
|
115
|
-
backgroundColor?: Color
|
|
133
|
+
backgroundColor?: ValueOrState<Color>;
|
|
116
134
|
status?: DeviceStatus | DeviceStatus[];
|
|
117
135
|
/** Connection type, how the device is connected */
|
|
118
|
-
connectionType?: ConfigConnectionType
|
|
136
|
+
connectionType?: ValueOrStateOrObject<ConfigConnectionType>;
|
|
119
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 */
|
|
120
|
-
enabled?: boolean
|
|
138
|
+
enabled?: ValueOrState<boolean>;
|
|
121
139
|
/** List of actions on the card */
|
|
122
|
-
actions?: DeviceAction<T>[];
|
|
140
|
+
actions?: DeviceAction<T, TId>[];
|
|
123
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 */
|
|
124
|
-
controls?: DeviceControl<T>[];
|
|
142
|
+
controls?: DeviceControl<T, TId>[];
|
|
125
143
|
/** If true, the button `more` will be shown on the card and called `dm:deviceDetails` action to get the details */
|
|
126
|
-
hasDetails?: boolean
|
|
144
|
+
hasDetails?: ValueOrStateOrObject<boolean>;
|
|
127
145
|
/** Device type for grouping */
|
|
128
146
|
group?: {
|
|
129
147
|
key: string;
|
|
@@ -131,4 +149,30 @@ export interface DeviceInfo<T extends ActionType = 'api'> {
|
|
|
131
149
|
icon?: string;
|
|
132
150
|
};
|
|
133
151
|
}
|
|
152
|
+
export interface BackendToGuiCommandDeviceInfoUpdate<TId extends DeviceId = DeviceId> {
|
|
153
|
+
/** Used for updating and for adding new device */
|
|
154
|
+
command: 'infoUpdate';
|
|
155
|
+
/** Device ID */
|
|
156
|
+
deviceId: TId;
|
|
157
|
+
/** Backend can send directly new information about device to avoid extra request from GUI */
|
|
158
|
+
info?: DeviceInfo;
|
|
159
|
+
}
|
|
160
|
+
export interface BackendToGuiCommandDeviceStatusUpdate<TId extends DeviceId = DeviceId> {
|
|
161
|
+
/** Status of device was updated */
|
|
162
|
+
command: 'statusUpdate';
|
|
163
|
+
/** Device ID */
|
|
164
|
+
deviceId: TId;
|
|
165
|
+
/** Backend can send directly new status to avoid extra request from GUI */
|
|
166
|
+
status?: DeviceStatus;
|
|
167
|
+
}
|
|
168
|
+
export interface BackendToGuiCommandDeviceDelete<TId extends DeviceId = DeviceId> {
|
|
169
|
+
/** Device was deleted */
|
|
170
|
+
command: 'delete';
|
|
171
|
+
deviceId: TId;
|
|
172
|
+
}
|
|
173
|
+
export interface BackendToGuiCommandAllUpdate {
|
|
174
|
+
/** Read ALL information about all devices anew */
|
|
175
|
+
command: 'all';
|
|
176
|
+
}
|
|
177
|
+
export type BackendToGuiCommand<TId extends DeviceId = DeviceId> = BackendToGuiCommandDeviceInfoUpdate<TId> | BackendToGuiCommandDeviceStatusUpdate<TId> | BackendToGuiCommandDeviceDelete<TId> | BackendToGuiCommandAllUpdate;
|
|
134
178
|
export {};
|