@iobroker/dm-utils 0.1.9 → 0.2.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 ioBroker Community Developers
3
+ Copyright (c) 2023-2024 ioBroker Community Developers
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -294,6 +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.2.0 (2024-05-29)
298
+ * (bluefox) enhanced type exports
299
+ * (bluefox) added confirmation and input text options
300
+
297
301
  ### 0.1.9 (2023-12-25)
298
302
  * (foxriver76) enhanced type exports
299
303
 
@@ -316,7 +320,7 @@ This method returns a promise that resolves to a `ProgressDialog` object.
316
320
  ## License
317
321
  MIT License
318
322
 
319
- Copyright (c) 2023 ioBroker Community Developers
323
+ Copyright (c) 2023-2024 ioBroker Community Developers
320
324
 
321
325
  Permission is hereby granted, free of charge, to any person obtaining a copy
322
326
  of this software and associated documentation files (the "Software"), to deal
@@ -15,8 +15,14 @@ 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?: ActionContext): RetVal<ErrorResponse> | RetVal<RefreshResponse>;
19
- protected handleDeviceAction(deviceId: string, actionId: string, context?: ActionContext): RetVal<ErrorResponse> | RetVal<RefreshResponse>;
18
+ protected handleInstanceAction(actionId: string, context?: ActionContext, options?: {
19
+ value?: number | string | boolean;
20
+ [key: string]: any;
21
+ }): RetVal<ErrorResponse> | RetVal<RefreshResponse>;
22
+ protected handleDeviceAction(deviceId: string, actionId: string, context?: ActionContext, options?: {
23
+ value?: number | string | boolean;
24
+ [key: string]: any;
25
+ }): RetVal<ErrorResponse> | RetVal<RefreshResponse>;
20
26
  protected handleDeviceControl(deviceId: string, controlId: string, newState: ControlState, context?: MessageContext): RetVal<ErrorResponse | ioBroker.State>;
21
27
  protected handleDeviceControlState(deviceId: string, controlId: string, context?: MessageContext): RetVal<ErrorResponse | ioBroker.State>;
22
28
  private onMessage;
@@ -17,7 +17,7 @@ class DeviceManagement {
17
17
  getDeviceDetails(id) {
18
18
  return { id, schema: {} };
19
19
  }
20
- handleInstanceAction(actionId, context) {
20
+ handleInstanceAction(actionId, context, options) {
21
21
  var _a;
22
22
  if (!this.instanceInfo) {
23
23
  this.log.warn(`Instance action ${actionId} was called before getInstanceInfo()`);
@@ -34,9 +34,9 @@ class DeviceManagement {
34
34
  error: { code: types_1.ErrorCodes.E_INSTANCE_ACTION_NO_HANDLER, message: `Instance action ${actionId} is disabled because it has no handler` },
35
35
  };
36
36
  }
37
- return action.handler(context);
37
+ return action.handler(context, options);
38
38
  }
39
- handleDeviceAction(deviceId, actionId, context) {
39
+ handleDeviceAction(deviceId, actionId, context, options) {
40
40
  var _a;
41
41
  if (!this.devices) {
42
42
  this.log.warn(`Device action ${actionId} was called before listDevices()`);
@@ -63,7 +63,7 @@ class DeviceManagement {
63
63
  },
64
64
  };
65
65
  }
66
- return action.handler(deviceId, context);
66
+ return action.handler(deviceId, context, options);
67
67
  }
68
68
  handleDeviceControl(deviceId, controlId, newState, context) {
69
69
  var _a;
@@ -161,7 +161,7 @@ class DeviceManagement {
161
161
  const action = msg.message;
162
162
  const context = new MessageContext(msg, this.adapter);
163
163
  this.contexts.set(msg._id, context);
164
- const result = await this.handleInstanceAction(action.actionId, context);
164
+ const result = await this.handleInstanceAction(action.actionId, context, { value: action.value });
165
165
  this.contexts.delete(msg._id);
166
166
  context.sendFinalResult(result);
167
167
  return;
@@ -170,7 +170,7 @@ class DeviceManagement {
170
170
  const action = msg.message;
171
171
  const context = new MessageContext(msg, this.adapter);
172
172
  this.contexts.set(msg._id, context);
173
- const result = await this.handleDeviceAction(action.deviceId, action.actionId, context);
173
+ const result = await this.handleDeviceAction(action.deviceId, action.actionId, context, { value: action.value });
174
174
  this.contexts.delete(msg._id);
175
175
  context.sendFinalResult(result);
176
176
  return;
@@ -8,11 +8,35 @@ export interface ActionBase<T extends ActionType> {
8
8
  /**
9
9
  * This can either be base64 or the URL to an icon.
10
10
  */
11
- icon: string;
11
+ icon?: string;
12
12
  description?: ioBroker.StringOrTranslated;
13
13
  disabled?: T extends "api" ? boolean : never;
14
14
  color?: Color;
15
15
  backgroundColor?: Color;
16
+ /** If true, the user will be asked for confirmation before executing the action */
17
+ confirmation: boolean | ioBroker.StringOrTranslated;
18
+ /** If defined, before the action is triggered, the non-empty text or number or checkbox will be asked */
19
+ inputBefore: {
20
+ /** This label will be shown for the text input */
21
+ label: ioBroker.StringOrTranslated;
22
+ /** This type of input will be shown. Default is type */
23
+ type?: "text" | "number" | "checkbox" | "select" | "slider" | "color";
24
+ /** If a type is "select", the options must be defined */
25
+ options?: {
26
+ label: ioBroker.StringOrTranslated;
27
+ value: string;
28
+ }[];
29
+ /** Default value for the input */
30
+ defaultValue?: string | number | boolean;
31
+ /** If true, the input could be empty */
32
+ allowEmptyValue?: boolean;
33
+ /** Minimum value for the input (number or slider) */
34
+ min?: number;
35
+ /** Maximum value for the input (number or slider) */
36
+ max?: number;
37
+ /** Step value for the input (number or slider) */
38
+ step?: number;
39
+ };
16
40
  }
17
41
  export interface ChannelInfo {
18
42
  name: ioBroker.StringOrTranslated;
@@ -51,13 +75,13 @@ export interface DeviceControl<T extends ActionType = "api"> extends ControlBase
51
75
  getStateHandler?: T extends "api" ? never : (deviceId: string, actionId: string, context: MessageContext) => RetVal<ErrorResponse | ioBroker.State>;
52
76
  }
53
77
  export interface InstanceAction<T extends ActionType = "api"> extends ActionBase<T> {
54
- handler?: T extends "api" ? never : (context: ActionContext) => RetVal<{
78
+ handler?: T extends "api" ? never : (context: ActionContext, options?: Record<string, any>) => RetVal<{
55
79
  refresh: boolean;
56
80
  }>;
57
81
  title: ioBroker.StringOrTranslated;
58
82
  }
59
83
  export interface DeviceAction<T extends ActionType = "api"> extends ActionBase<T> {
60
- handler?: T extends "api" ? never : (deviceId: string, context: ActionContext) => RetVal<{
84
+ handler?: T extends "api" ? never : (deviceId: string, context: ActionContext, options?: Record<string, any>) => RetVal<{
61
85
  refresh: DeviceRefresh;
62
86
  }>;
63
87
  }
@@ -20,10 +20,81 @@ export type ErrorResponse = {
20
20
  };
21
21
  };
22
22
  export type RetVal<T> = T | Promise<T>;
23
- export type JsonFormSchema = Record<string, any>;
23
+ export type ConfigItemType = 'tabs' | 'panel' | 'text' | 'number' | 'color' | 'checkbox' | 'slider' | 'ip' | 'user' | 'room' | 'func' | 'select' | 'autocomplete' | 'image' | 'objectId' | 'password' | 'instance' | 'chips' | 'alive' | 'pattern' | 'sendto' | 'setState' | 'staticText' | 'staticLink' | 'staticImage' | 'table' | 'accordion' | 'jsonEditor' | 'language' | 'certificate' | 'certificates' | 'certCollection' | 'custom' | 'datePicker' | 'timePicker' | 'divider' | 'header' | 'cron' | 'fileSelector' | 'file' | 'imageSendTo' | 'selectSendTo' | 'autocompleteSendTo' | 'textSendTo' | 'coordinates' | 'interface' | 'license' | 'checkLicense' | 'uuid' | 'port' | 'deviceManager';
24
+ export interface ConfigItemConfirmData {
25
+ condition: string;
26
+ text?: ioBroker.StringOrTranslated;
27
+ title?: ioBroker.StringOrTranslated;
28
+ ok?: ioBroker.StringOrTranslated;
29
+ cancel?: ioBroker.StringOrTranslated;
30
+ type?: 'info' | 'warning' | 'error' | 'none';
31
+ alsoDependsOn?: string[];
32
+ }
33
+ type CustomCSSProperties = Record<string, any>;
34
+ export interface ConfigItem {
35
+ type: ConfigItemType;
36
+ sm?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
37
+ md?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
38
+ lg?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
39
+ xs?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
40
+ newLine?: boolean;
41
+ label?: ioBroker.StringOrTranslated;
42
+ /** @deprecated use label */
43
+ text?: ioBroker.StringOrTranslated;
44
+ hidden?: string | boolean;
45
+ hideOnlyControl?: boolean;
46
+ disabled?: string | boolean;
47
+ help?: ioBroker.StringOrTranslated;
48
+ helpLink?: string;
49
+ style?: CustomCSSProperties;
50
+ darkStyle?: CustomCSSProperties;
51
+ validator?: string;
52
+ validatorErrorText?: string;
53
+ validatorNoSaveOnError?: boolean;
54
+ tooltip?: ioBroker.StringOrTranslated;
55
+ default?: boolean | number | string;
56
+ defaultFunc?: string;
57
+ defaultSendTo?: string;
58
+ data?: string | number | boolean;
59
+ jsonData?: string;
60
+ button?: ioBroker.StringOrTranslated;
61
+ buttonTooltip?: ioBroker.StringOrTranslated;
62
+ buttonTooltipNoTranslation?: boolean;
63
+ placeholder?: ioBroker.StringOrTranslated;
64
+ noTranslation?: boolean;
65
+ onChange?: {
66
+ alsoDependsOn: string[];
67
+ calculateFunc: string;
68
+ ignoreOwnChanges?: boolean;
69
+ };
70
+ doNotSave?: boolean;
71
+ noMultiEdit?: boolean;
72
+ confirm?: ConfigItemConfirmData;
73
+ icon?: 'auth' | 'send' | 'web' | 'warning' | 'error' | 'info' | 'search' | 'book' | 'help' | 'upload' | string;
74
+ width?: string | number;
75
+ confirmDependsOn?: ConfigItemIndexed[];
76
+ onChangeDependsOn?: ConfigItemIndexed[];
77
+ hiddenDependsOn?: ConfigItemIndexed[];
78
+ labelDependsOn?: ConfigItemIndexed[];
79
+ helpDependsOn?: ConfigItemIndexed[];
80
+ }
81
+ interface ConfigItemIndexed extends ConfigItem {
82
+ attr?: string;
83
+ }
84
+ export interface ConfigItemPanel extends ConfigItem {
85
+ type: 'panel' | never;
86
+ label?: ioBroker.StringOrTranslated;
87
+ items: Record<string, ConfigItem>;
88
+ collapsable?: boolean;
89
+ color?: 'primary' | 'secondary';
90
+ innerStyle?: CustomCSSProperties;
91
+ i18n?: boolean | string | Record<string, Record<ioBroker.Languages, string>>;
92
+ }
93
+ export type JsonFormSchema = ConfigItemPanel;
24
94
  export type JsonFormData = Record<string, any>;
25
95
  export interface DeviceDetails {
26
96
  id: string;
27
97
  schema: JsonFormSchema;
28
98
  data?: JsonFormData;
29
99
  }
100
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/dm-utils",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "ioBroker Device Manager utilities for backend",
5
5
  "main": "build/index.js",
6
6
  "publishConfig": {
@@ -16,23 +16,23 @@
16
16
  "release-minor": "release-script minor --yes",
17
17
  "release-major": "release-script major --yes",
18
18
  "update-packages": "ncu --upgrade",
19
- "npm": "npm i"
19
+ "npm": "npm i -f"
20
20
  },
21
21
  "author": "UncleSamSwiss",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@iobroker/adapter-core": "^3.0.4"
24
+ "@iobroker/adapter-core": "^3.1.4"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@alcalzone/release-script": "^3.7.0",
28
28
  "@alcalzone/release-script-plugin-license": "^3.7.0",
29
- "@types/node": "^20.10.4",
30
- "@typescript-eslint/eslint-plugin": "^6.14.0",
31
- "@typescript-eslint/parser": "^6.14.0",
32
- "eslint": "^8.56.0",
29
+ "@types/node": "^20.12.12",
30
+ "@typescript-eslint/eslint-plugin": "^7.11.0",
31
+ "@typescript-eslint/parser": "^7.11.0",
32
+ "eslint": "^8.57.0",
33
33
  "eslint-config-prettier": "^9.1.0",
34
- "prettier": "^3.1.1",
35
- "typescript": "^5.3.3"
34
+ "prettier": "^3.2.5",
35
+ "typescript": "^5.4.5"
36
36
  },
37
37
  "files": [
38
38
  "LICENSE",