@iobroker/dm-utils 2.0.1 → 3.0.2

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.
@@ -1,7 +1,72 @@
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 type DmActionUrlResponse = DmResponseBase & {
43
+ type: 'url';
44
+ data: {
45
+ url: string;
46
+ target: string;
47
+ };
48
+ };
49
+ export interface CommunicationForm {
50
+ title?: ioBroker.StringOrTranslated | null | undefined;
51
+ label?: ioBroker.StringOrTranslated | null | undefined;
52
+ noTranslation?: boolean;
53
+ schema: JsonFormSchema;
54
+ data?: Record<string, any>;
55
+ buttons?: (ActionButton | 'apply' | 'cancel' | 'close')[];
56
+ maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
57
+ /** Minimal width of the dialog */
58
+ minWidth?: number;
59
+ /** Always allow the Apply button. Even when nothing was changed */
60
+ ignoreApplyDisabled?: boolean;
61
+ }
62
+ export type DmActionFormResponse = DmResponseBase & {
63
+ type: 'form';
64
+ form: CommunicationForm;
65
+ };
66
+ export type DmActionProgressResponse = DmResponseBase & {
67
+ type: 'progress';
68
+ progress: ProgressUpdate & {
69
+ open?: boolean;
70
+ };
71
+ };
72
+ export type DmActionResponse = DmActionResultResponse | DmActionMessageResponse | DmActionConfirmResponse | DmActionUrlResponse | DmActionFormResponse | DmActionProgressResponse;
@@ -1,13 +1,13 @@
1
1
  import type { ActionContext, ConfigConnectionType, ErrorResponse, MessageContext, ValueOrObject, ValueOrState, ValueOrStateOrObject } from '..';
2
- import type { ApiVersion, DeviceRefresh, DeviceStatus, RetVal } from './common';
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;
6
6
  /** Reserved action names */
7
7
  export declare const ACTIONS: {
8
- /** This action will be called when user clicks on connection icon */
8
+ /** This action will be called when the user clicks on the connection icon */
9
9
  STATUS: string;
10
- /** This action will be called when the user clicks on enabled/disabled icon. The enabled/disabled icon will be shown only if the node status has "enabled" flag set to false or true */
10
+ /** This action will be called when the user clicks on the enabled / disabled icon. The enabled/disabled icon will be shown only if the node status has the "enabled" flag set to false or true */
11
11
  ENABLE_DISABLE: string;
12
12
  };
13
13
  export interface ActionBase<T extends ActionType> {
@@ -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<T extends ActionType = 'api'> extends ControlBase {
85
- handler?: T extends 'api' ? never : (deviceId: string, actionId: string, state: ControlState, context: MessageContext) => RetVal<ErrorResponse | ioBroker.State>;
86
- getStateHandler?: T extends 'api' ? never : (deviceId: string, actionId: string, context: MessageContext) => RetVal<ErrorResponse | ioBroker.State>;
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 interface InstanceAction<T extends ActionType = 'api'> extends ActionBase<T> {
89
- handler?: T extends 'api' ? never : (context: ActionContext, options?: Record<string, any>) => RetVal<{
90
- refresh: boolean;
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 interface DeviceAction<T extends ActionType = 'api'> extends ActionBase<T> {
95
- handler?: T extends 'api' ? never : (deviceId: string, context: ActionContext, options?: Record<string, any>) => RetVal<{
96
- refresh: DeviceRefresh;
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 action. Should be unique only in one adapter. Other adapters could have same names */
108
- id: string;
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 the 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 */
@@ -119,12 +134,12 @@ export interface DeviceInfo<T extends ActionType = 'api'> {
119
134
  status?: DeviceStatus | DeviceStatus[];
120
135
  /** Connection type, how the device is connected */
121
136
  connectionType?: ValueOrStateOrObject<ConfigConnectionType>;
122
- /** 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 */
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 the 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 {
138
- /** Used for updating and for adding new device */
152
+ export interface BackendToGuiCommandDeviceInfoUpdate<TId extends DeviceId = DeviceId> {
153
+ /** Used for updating and for adding a new device */
139
154
  command: 'infoUpdate';
140
155
  /** Device ID */
141
- deviceId: string;
142
- /** Backend can send directly new information about device to avoid extra request from GUI */
156
+ deviceId: TId;
157
+ /** Backend can directly send new information about a device to avoid extra request from GUI */
143
158
  info?: DeviceInfo;
144
159
  }
145
- export interface BackendToGuiCommandDeviceStatusUpdate {
146
- /** Status of device was updated */
160
+ export interface BackendToGuiCommandDeviceStatusUpdate<TId extends DeviceId = DeviceId> {
161
+ /** Status of a device was updated */
147
162
  command: 'statusUpdate';
148
163
  /** Device ID */
149
- deviceId: string;
150
- /** Backend can send directly new status to avoid extra request from GUI */
164
+ deviceId: TId;
165
+ /** Backend can directly send 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: string;
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 {};
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ACTIONS = void 0;
4
4
  /** Reserved action names */
5
5
  exports.ACTIONS = {
6
- /** This action will be called when user clicks on connection icon */
6
+ /** This action will be called when the user clicks on the connection icon */
7
7
  STATUS: 'status',
8
- /** This action will be called when the user clicks on enabled/disabled icon. The enabled/disabled icon will be shown only if the node status has "enabled" flag set to false or true */
8
+ /** This action will be called when the user clicks on the enabled / disabled icon. The enabled/disabled icon will be shown only if the node status has the "enabled" flag set to false or true */
9
9
  ENABLE_DISABLE: 'enable/disable',
10
10
  };