iobroker.javascript 8.9.2 → 9.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 +7 -3
- package/admin/assets/{createSvgIcon-BdRvDw53.js → createSvgIcon-BQT-7-GS.js} +1 -1
- package/admin/assets/{docs-6na4NFtj.js → docs-BrInh2Pn.js} +2 -2
- package/admin/assets/index-B0RKH_iG.js +1329 -0
- package/admin/assets/index-CfuHVX2B.js +193 -0
- package/admin/assets/index-CuCs5aLs.js +5 -0
- package/admin/assets/index-tExaxF69.js +930 -0
- package/admin/assets/inheritsLoose--KnFDOw1.js +36 -0
- package/admin/assets/{useTheme-Cl1QmYFL.js → useTheme-DF6qfrtI.js} +1 -1
- package/admin/custom/assets/{Components-ChpTW7sE.js → Components-D9kRsHNY.js} +1 -1
- package/admin/custom/assets/{DefaultPropsProvider-CHpMCMgA.js → DefaultPropsProvider-9qubdy-V.js} +2 -2
- package/admin/custom/assets/{FilledInput-CtcQVKyj.js → FilledInput-BpuM_GyB.js} +1 -1
- package/admin/custom/assets/Tabs-CvEv0KOT.js +138 -0
- package/admin/custom/assets/ThemeProvider-DZTpMR8n.js +29 -0
- package/admin/custom/assets/{createSvgIcon-C_vAELFU.js → createSvgIcon-BQThUM-f.js} +1 -1
- package/admin/custom/assets/hostInit-CrAs5YZS.js +1 -1
- package/admin/custom/assets/{index-DwsbskQy.js → index-DIWNdd4a.js} +1 -1
- package/admin/custom/assets/index-DZqbj5K4.js +55 -0
- package/admin/custom/assets/{index-D5apCzjJ.js → index-Dbe-II7_.js} +6 -6
- package/admin/custom/assets/index-az76fZMP.js +904 -0
- package/admin/custom/assets/index-sawv1cUe.js +1399 -0
- package/admin/custom/assets/{virtualExposes-BPncCdUy.js → virtualExposes-BMKIjWrE.js} +2 -2
- package/admin/custom/customComponents.js +2 -2
- package/admin/custom/i18n/de.json +29 -29
- package/admin/custom/i18n/es.json +29 -29
- package/admin/custom/i18n/fr.json +29 -29
- package/admin/custom/i18n/it.json +29 -29
- package/admin/custom/i18n/nl.json +29 -29
- package/admin/custom/i18n/pl.json +29 -29
- package/admin/custom/i18n/pt.json +29 -29
- package/admin/custom/i18n/ru.json +29 -29
- package/admin/custom/i18n/uk.json +29 -29
- package/admin/custom/i18n/zh-cn.json +29 -29
- package/admin/google-blockly/blockly_compressed.js +875 -887
- package/admin/google-blockly/blocks_compressed.js +38 -41
- package/admin/google-blockly/javascript_compressed.js +19 -54
- package/admin/google-blockly/media/delete-icon.svg +1 -0
- package/admin/google-blockly/media/foldout-icon.svg +1 -0
- package/admin/google-blockly/media/resize-handle.svg +3 -0
- package/admin/jsonConfig.json +2 -0
- package/admin/mf-manifest.json +1 -1
- package/admin/remoteEntry.js +2 -2
- package/admin/tab.html +4 -4
- package/admin/vsFont/README.md +1 -1
- package/admin/vsFont/createJson.js +1 -1
- package/build-backend/lib/consts.js +346 -0
- package/build-backend/lib/consts.js.map +1 -0
- package/build-backend/lib/convert.js +120 -0
- package/build-backend/lib/convert.js.map +1 -0
- package/build-backend/lib/debug.js +163 -0
- package/build-backend/lib/debug.js.map +1 -0
- package/{lib → build-backend/lib}/debugger.js +261 -232
- package/build-backend/lib/debugger.js.map +1 -0
- package/build-backend/lib/eventObj.js +177 -0
- package/build-backend/lib/eventObj.js.map +1 -0
- package/build-backend/lib/inspect.js +728 -0
- package/build-backend/lib/inspect.js.map +1 -0
- package/build-backend/lib/javascript.d.ts +1972 -0
- package/{lib → build-backend/lib}/mirror.js +185 -182
- package/build-backend/lib/mirror.js.map +1 -0
- package/build-backend/lib/nodeModulesManagement.js +25 -0
- package/build-backend/lib/nodeModulesManagement.js.map +1 -0
- package/build-backend/lib/patternCompareFunctions.js +321 -0
- package/build-backend/lib/patternCompareFunctions.js.map +1 -0
- package/build-backend/lib/protectFs.js +477 -0
- package/build-backend/lib/protectFs.js.map +1 -0
- package/build-backend/lib/request.js +89 -0
- package/build-backend/lib/request.js.map +1 -0
- package/{lib → build-backend/lib}/sandbox.js +2046 -1852
- package/build-backend/lib/sandbox.js.map +1 -0
- package/build-backend/lib/scheduler.js +553 -0
- package/build-backend/lib/scheduler.js.map +1 -0
- package/build-backend/lib/tools.js +183 -0
- package/build-backend/lib/tools.js.map +1 -0
- package/build-backend/lib/typescriptSettings.js +39 -0
- package/build-backend/lib/typescriptSettings.js.map +1 -0
- package/build-backend/lib/typescriptTools.js +435 -0
- package/build-backend/lib/typescriptTools.js.map +1 -0
- package/build-backend/lib/utils.js +66 -0
- package/build-backend/lib/utils.js.map +1 -0
- package/{lib → build-backend/lib}/words.js +23 -30
- package/build-backend/lib/words.js.map +1 -0
- package/build-backend/main.js +2671 -0
- package/build-backend/main.js.map +1 -0
- package/build-backend/types.d.ts +742 -0
- package/docs/de/README.md +1 -1
- package/docs/en/README.md +1 -1
- package/docs/en/javascript.md +10 -6
- package/docs/ru/README.md +1 -1
- package/install/installTypings.js +34 -47
- package/io-package.json +14 -14
- package/package.json +14 -14
- package/admin/assets/index-DCkkMRRa.js +0 -1335
- package/admin/assets/index-DJfSBoBB.js +0 -192
- package/admin/assets/index-DTiA4WdK.js +0 -930
- package/admin/assets/index-qABB1JVe.js +0 -5
- package/admin/assets/inheritsLoose-BW-3V39H.js +0 -36
- package/admin/custom/assets/Tabs-C1KOyWRi.js +0 -137
- package/admin/custom/assets/ThemeProvider-Buvx5nSd.js +0 -29
- package/admin/custom/assets/index-BGCRznKh.js +0 -904
- package/admin/custom/assets/index-DfBPYXqA.js +0 -55
- package/admin/custom/assets/index-jIr6kOLK.js +0 -1398
- package/lib/adapter-config.d.ts +0 -16
- package/lib/consts.js +0 -83
- package/lib/convert.js +0 -106
- package/lib/debug.js +0 -154
- package/lib/eventObj.js +0 -201
- package/lib/inspect.js +0 -688
- package/lib/javascript.d.ts +0 -1858
- package/lib/nodeModulesManagement.js +0 -26
- package/lib/patternCompareFunctions.js +0 -391
- package/lib/protectFs.js +0 -401
- package/lib/request.js +0 -72
- package/lib/scheduler.js +0 -447
- package/lib/tools.js +0 -192
- package/lib/typescriptSettings.js +0 -44
- package/lib/typescriptTools.js +0 -529
- package/lib/utils.js +0 -87
- package/main.js +0 -2653
|
@@ -0,0 +1,1972 @@
|
|
|
1
|
+
// import all modules that are available in the sandbox
|
|
2
|
+
// this has a nice side effect that we may augment the global scope
|
|
3
|
+
import type * as os from 'node:os';
|
|
4
|
+
import type { ChildProcess, ExecException } from 'node:child_process';
|
|
5
|
+
import type { SubscribeObject } from '../types';
|
|
6
|
+
|
|
7
|
+
type EmptyCallback = () => void | Promise<void>;
|
|
8
|
+
type ErrorCallback = (err?: Error) => void | Promise<void>;
|
|
9
|
+
type GenericCallback<T> = (err?: Error | null, result?: T) => void | Promise<void>;
|
|
10
|
+
type SimpleCallback<T> = (result?: T) => void | Promise<void>;
|
|
11
|
+
type MessageCallback<T> = (data: T, callback: iobJS.MessageCallback) => void | Promise<void>;
|
|
12
|
+
|
|
13
|
+
type SecondParameterOf<T extends (...args: any[]) => any> = T extends (arg0: any, arg1: infer R, ...args: any[]) => any
|
|
14
|
+
? R
|
|
15
|
+
: never;
|
|
16
|
+
/** Infers the return type from a callback-style API and strips out null and undefined */
|
|
17
|
+
type NonNullCallbackReturnTypeOf<T extends (...args: any[]) => any> = Exclude<SecondParameterOf<T>, null | undefined>;
|
|
18
|
+
/** Infers the return type from a callback-style API and leaves null and undefined in */
|
|
19
|
+
type CallbackReturnTypeOf<T extends (...args: any[]) => any> = SecondParameterOf<T>;
|
|
20
|
+
|
|
21
|
+
/** Returns a type that requires at least one of the properties from the given type */
|
|
22
|
+
type AtLeastOne<T, U = { [K in keyof T]-?: T[K] }> = { [K in keyof U]: { [P in K]: U[P] } }[keyof U];
|
|
23
|
+
|
|
24
|
+
/** Returns all possible keys of a union of objects */
|
|
25
|
+
type AllKeys<T> = T extends any ? keyof T : never;
|
|
26
|
+
/** Simplifies mapped types to their basic forms */
|
|
27
|
+
type Simplify<U> = U extends infer O ? { [K in keyof O]: O[K] } : never;
|
|
28
|
+
|
|
29
|
+
/** Takes an object type and adds all missing properties from the Keys union with the type `never` */
|
|
30
|
+
type AddMissingNever<T, Keys extends string | number | symbol> = {
|
|
31
|
+
[K in Keys]: K extends keyof T ? T[K] : never;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Takes a union of objects and returns an object type
|
|
36
|
+
* which has all properties that exist on at least one of the objects.
|
|
37
|
+
*
|
|
38
|
+
* E.g. CombineObjectUnion<{a: 1} | {b: 2}> = {a: 1; b: 2};
|
|
39
|
+
*/
|
|
40
|
+
type CombineObjectUnion<
|
|
41
|
+
T,
|
|
42
|
+
Keys extends string | number | symbol = AllKeys<T>,
|
|
43
|
+
O = T extends any ? AddMissingNever<T, Keys> : never,
|
|
44
|
+
> = Simplify<{ [K in Keys]: K extends keyof O ? O[K] : never }>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Takes a union of ioBroker Object types and returns a combined object type
|
|
48
|
+
* which has all properties that could exist on at least one of the objects.
|
|
49
|
+
*
|
|
50
|
+
* Note: This is not entirely sound to work with, but better for JS and working with read objects
|
|
51
|
+
*/
|
|
52
|
+
type AnyOf<
|
|
53
|
+
T,
|
|
54
|
+
Keys extends string | number | symbol = AllKeys<T>,
|
|
55
|
+
O = T extends any ? AddMissingNever<T, Keys> : never,
|
|
56
|
+
> = Simplify<{
|
|
57
|
+
[K in Keys]: K extends keyof O
|
|
58
|
+
? O[K] extends any[]
|
|
59
|
+
? O[K]
|
|
60
|
+
: O[K] extends Record<any, any>
|
|
61
|
+
? CombineObjectUnion<O[K]>
|
|
62
|
+
: O[K]
|
|
63
|
+
: never;
|
|
64
|
+
}>;
|
|
65
|
+
|
|
66
|
+
// tslint:disable:no-namespace
|
|
67
|
+
declare global {
|
|
68
|
+
namespace iobJS {
|
|
69
|
+
enum StateQuality {
|
|
70
|
+
good = 0x00, // or undefined or null
|
|
71
|
+
bad = 0x01,
|
|
72
|
+
general_device_problem = 0x41,
|
|
73
|
+
general_sensor_problem = 0x81,
|
|
74
|
+
device_not_connected = 0x42,
|
|
75
|
+
sensor_not_connected = 0x82,
|
|
76
|
+
device_reports_error = 0x44,
|
|
77
|
+
sensor_reports_error = 0x84,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
type SettableState = AtLeastOne<ioBroker.State>;
|
|
81
|
+
|
|
82
|
+
interface TypedState<T extends ioBroker.StateValue = any> extends ioBroker.State {
|
|
83
|
+
val: T;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface AbsentState extends Omit<ioBroker.State, 'ack' | 'from' | 'ts' | 'lc'> {
|
|
87
|
+
val: null;
|
|
88
|
+
notExist: true;
|
|
89
|
+
|
|
90
|
+
ack: undefined;
|
|
91
|
+
ts: undefined;
|
|
92
|
+
lc: undefined;
|
|
93
|
+
from: undefined;
|
|
94
|
+
expire: undefined;
|
|
95
|
+
q: undefined;
|
|
96
|
+
c: undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
type Languages = 'en' | 'de' | 'ru' | 'pt' | 'nl' | 'fr' | 'it' | 'es' | 'pl' | 'uk' | 'zh-cn';
|
|
100
|
+
type StringOrTranslated = string | { [lang in Languages]?: string };
|
|
101
|
+
type CommonType = 'number' | 'string' | 'boolean' | 'array' | 'object' | 'mixed' | 'file';
|
|
102
|
+
|
|
103
|
+
/** Defines access rights for a single object type */
|
|
104
|
+
interface ObjectOperationPermissions {
|
|
105
|
+
/** Whether a user may enumerate objects of this type */
|
|
106
|
+
list: boolean;
|
|
107
|
+
/** Whether a user may read objects of this type */
|
|
108
|
+
read: boolean;
|
|
109
|
+
/** Whether a user may write objects of this type */
|
|
110
|
+
write: boolean;
|
|
111
|
+
/** Whether a user may create objects of this type */
|
|
112
|
+
create: boolean;
|
|
113
|
+
/** Whether a user may delete objects of this type */
|
|
114
|
+
delete: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Defines the rights a user or group has to change objects */
|
|
118
|
+
interface ObjectPermissions {
|
|
119
|
+
/** The access rights for files */
|
|
120
|
+
file: ObjectOperationPermissions;
|
|
121
|
+
/** The access rights for objects */
|
|
122
|
+
object: ObjectOperationPermissions;
|
|
123
|
+
/** The access rights for users/groups */
|
|
124
|
+
users: ObjectOperationPermissions;
|
|
125
|
+
/** The access rights for states */
|
|
126
|
+
state?: ObjectOperationPermissions;
|
|
127
|
+
}
|
|
128
|
+
/** Defined the complete set of access rights a user has */
|
|
129
|
+
interface PermissionSet extends ObjectPermissions {
|
|
130
|
+
/** The name of the user this ACL is for */
|
|
131
|
+
user: string;
|
|
132
|
+
/** The name of the groups this ACL was merged from */
|
|
133
|
+
groups: string[];
|
|
134
|
+
/** The access rights for certain commands */
|
|
135
|
+
other: {
|
|
136
|
+
execute: boolean;
|
|
137
|
+
http: boolean;
|
|
138
|
+
sendto: boolean;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
interface ObjectACL {
|
|
143
|
+
/** Full name of the user who owns this object, e.g. "system.user.admin" */
|
|
144
|
+
owner: string;
|
|
145
|
+
/** Full name of the group who owns this object, e.g. "system.group.administrator" */
|
|
146
|
+
ownerGroup: string;
|
|
147
|
+
/** Linux-type permissions defining access to this object */
|
|
148
|
+
object: number;
|
|
149
|
+
}
|
|
150
|
+
/** Defines access rights for a single state object */
|
|
151
|
+
interface StateACL extends ObjectACL {
|
|
152
|
+
/** Linux-type permissions defining access to this state */
|
|
153
|
+
state: number;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Defines the existing object types in ioBroker */
|
|
157
|
+
type ObjectType =
|
|
158
|
+
| 'state'
|
|
159
|
+
| 'channel'
|
|
160
|
+
| 'device'
|
|
161
|
+
| 'folder'
|
|
162
|
+
| 'enum'
|
|
163
|
+
| 'adapter'
|
|
164
|
+
| 'config'
|
|
165
|
+
| 'group'
|
|
166
|
+
| 'host'
|
|
167
|
+
| 'instance'
|
|
168
|
+
| 'meta'
|
|
169
|
+
| 'script'
|
|
170
|
+
| 'user'
|
|
171
|
+
| 'chart';
|
|
172
|
+
|
|
173
|
+
// Define the naming schemes for objects, so we can provide more specific types for get/setObject
|
|
174
|
+
namespace ObjectIDs {
|
|
175
|
+
// Guaranteed meta objects
|
|
176
|
+
type Meta =
|
|
177
|
+
| `${string}.${number}`
|
|
178
|
+
| `${string}.${'meta' | 'admin'}`
|
|
179
|
+
| `${string}.meta.${string}`
|
|
180
|
+
| `${string}.${number}.meta.${string}`;
|
|
181
|
+
|
|
182
|
+
// Unsure, can be folder, device, channel or state
|
|
183
|
+
// --> We need this match to avoid matching the more specific types below
|
|
184
|
+
type Misc = `system.host.${string}.${string}` | `0_userdata.0.${string}`;
|
|
185
|
+
|
|
186
|
+
// Guaranteed channel objects
|
|
187
|
+
type Channel = `script.js.${'common' | 'global'}` | `${string}.${number}.info`;
|
|
188
|
+
// Either script or channel object
|
|
189
|
+
type ScriptOrChannel = `script.js.${string}`;
|
|
190
|
+
// Guaranteed state objects
|
|
191
|
+
type State = `system.adapter.${string}.${number}.${string}`;
|
|
192
|
+
// Guaranteed enum objects
|
|
193
|
+
type Enum = `enum.${string}`;
|
|
194
|
+
// Guaranteed instance objects
|
|
195
|
+
type Instance = `system.adapter.${string}.${number}`;
|
|
196
|
+
// Guaranteed adapter objects
|
|
197
|
+
type Adapter = `system.adapter.${string}`;
|
|
198
|
+
// Guaranteed group objects
|
|
199
|
+
type Group = `system.group.${string}`;
|
|
200
|
+
// Guaranteed user objects
|
|
201
|
+
type User = `system.user.${string}`;
|
|
202
|
+
// Guaranteed host objects
|
|
203
|
+
type Host = `system.host.${string}`;
|
|
204
|
+
// Guaranteed config objects
|
|
205
|
+
type Config = `system.${'certificates' | 'config' | 'repositories'}`;
|
|
206
|
+
|
|
207
|
+
// Unsure, can be folder, device, channel or state (or whatever an adapter does)
|
|
208
|
+
type AdapterScoped = `${string}.${number}.${string}`;
|
|
209
|
+
|
|
210
|
+
/** All possible typed object IDs */
|
|
211
|
+
type Any =
|
|
212
|
+
| Meta
|
|
213
|
+
| Misc
|
|
214
|
+
| Channel
|
|
215
|
+
| ScriptOrChannel
|
|
216
|
+
| State
|
|
217
|
+
| Enum
|
|
218
|
+
| Instance
|
|
219
|
+
| Adapter
|
|
220
|
+
| Group
|
|
221
|
+
| User
|
|
222
|
+
| Host
|
|
223
|
+
| Config
|
|
224
|
+
| AdapterScoped;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
type ObjectIdToObjectType<
|
|
228
|
+
T extends string,
|
|
229
|
+
Read extends 'read' | 'write' = 'read',
|
|
230
|
+
O = T extends ObjectIDs.State // State must come before Adapter or system.adapter.admin.0.foobar will resolve to AdapterObject
|
|
231
|
+
? StateObject
|
|
232
|
+
: // Instance and Adapter must come before meta or `system.adapter.admin` will resolve to MetaObject
|
|
233
|
+
T extends ObjectIDs.Instance
|
|
234
|
+
? InstanceObject
|
|
235
|
+
: T extends ObjectIDs.Adapter
|
|
236
|
+
? AdapterObject
|
|
237
|
+
: T extends ObjectIDs.Channel
|
|
238
|
+
? ChannelObject
|
|
239
|
+
: T extends ObjectIDs.Meta
|
|
240
|
+
? MetaObject
|
|
241
|
+
: T extends ObjectIDs.Misc
|
|
242
|
+
? AdapterScopedObject
|
|
243
|
+
: T extends ObjectIDs.ScriptOrChannel
|
|
244
|
+
? ScriptObject | ChannelObject
|
|
245
|
+
: T extends ObjectIDs.Enum
|
|
246
|
+
? EnumObject
|
|
247
|
+
: T extends ObjectIDs.Group
|
|
248
|
+
? GroupObject
|
|
249
|
+
: T extends ObjectIDs.User
|
|
250
|
+
? UserObject
|
|
251
|
+
: T extends ObjectIDs.Host
|
|
252
|
+
? HostObject
|
|
253
|
+
: T extends ObjectIDs.Config
|
|
254
|
+
? OtherObject & { type: 'config' }
|
|
255
|
+
: T extends ObjectIDs.AdapterScoped
|
|
256
|
+
? AdapterScopedObject
|
|
257
|
+
: iobJS.AnyObject,
|
|
258
|
+
// When reading objects, we should be less strict, so working with the return type is less of a pain to work with
|
|
259
|
+
> = Read extends 'read' ? AnyOf<O> : O;
|
|
260
|
+
|
|
261
|
+
interface ObjectCommon {
|
|
262
|
+
/** The name of this object as a simple string or an object with translations */
|
|
263
|
+
name: StringOrTranslated;
|
|
264
|
+
|
|
265
|
+
/** When set to true, this object may not be deleted */
|
|
266
|
+
dontDelete?: true;
|
|
267
|
+
|
|
268
|
+
/** When set to true, this object is only visible when expert mode is turned on in admin */
|
|
269
|
+
expert?: true;
|
|
270
|
+
|
|
271
|
+
// Icon and role aren't defined in SCHEMA.md,
|
|
272
|
+
// but they are being used by some adapters
|
|
273
|
+
/** Icon for this object */
|
|
274
|
+
icon?: string;
|
|
275
|
+
/** role of the object */
|
|
276
|
+
role?: string;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
interface StateCommonAlias {
|
|
280
|
+
/** The target state id or two target states used for reading and writing values */
|
|
281
|
+
id: string | { read: string; write: string };
|
|
282
|
+
/** An optional conversion function when reading, e.g. `"(val − 32) * 5/9"` */
|
|
283
|
+
read?: string;
|
|
284
|
+
/** An optional conversion function when reading, e.g. `"(val * 9/5) + 32"` */
|
|
285
|
+
write?: string;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
interface StateCommon extends ObjectCommon {
|
|
289
|
+
/** Type of this state. See https://github.com/ioBroker/ioBroker/blob/master/doc/SCHEMA.md#state-commonrole for a detailed description */
|
|
290
|
+
type?: CommonType;
|
|
291
|
+
/** minimum value */
|
|
292
|
+
min?: number;
|
|
293
|
+
/** maximum value */
|
|
294
|
+
max?: number;
|
|
295
|
+
/** the allowed interval for numeric values */
|
|
296
|
+
step?: number;
|
|
297
|
+
/** unit of the value */
|
|
298
|
+
unit?: string;
|
|
299
|
+
/** description of this state */
|
|
300
|
+
desc?: StringOrTranslated;
|
|
301
|
+
|
|
302
|
+
/** if this state is readable */
|
|
303
|
+
read: boolean;
|
|
304
|
+
/** if this state is writable */
|
|
305
|
+
write: boolean;
|
|
306
|
+
/** role of the state (used in user interfaces to indicate which widget to choose) */
|
|
307
|
+
role: string;
|
|
308
|
+
|
|
309
|
+
/** the default value */
|
|
310
|
+
def?: ioBroker.StateValue;
|
|
311
|
+
/** the default status of the ack flag */
|
|
312
|
+
defAck?: boolean;
|
|
313
|
+
|
|
314
|
+
/** Configures this state as an alias for another state */
|
|
315
|
+
alias?: StateCommonAlias;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Dictionary of possible values for this state in the form
|
|
319
|
+
* <pre>
|
|
320
|
+
* {
|
|
321
|
+
* "internal value 1": "displayed value 1",
|
|
322
|
+
* "internal value 2": "displayed value 2",
|
|
323
|
+
* ...
|
|
324
|
+
* }
|
|
325
|
+
* </pre>
|
|
326
|
+
* In old ioBroker versions, this could also be a string of the form
|
|
327
|
+
* "val1:text1;val2:text2" (now deprecated)
|
|
328
|
+
*/
|
|
329
|
+
states?: Record<string, string> | string;
|
|
330
|
+
|
|
331
|
+
/** ID of a helper state indicating if the handler of this state is working */
|
|
332
|
+
workingID?: string;
|
|
333
|
+
|
|
334
|
+
/** @deprecated moved to `custom.history´ - attached history information */
|
|
335
|
+
history?: any;
|
|
336
|
+
|
|
337
|
+
/** Custom settings for this state */
|
|
338
|
+
custom?: Record<string, any>;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Settings for IOT adapters and how the state should be named in e.g., Alexa.
|
|
342
|
+
* The string "ignore" is a special case, causing the state to be ignored.
|
|
343
|
+
*/
|
|
344
|
+
smartName?:
|
|
345
|
+
| string
|
|
346
|
+
| ({ [lang in Languages]?: string } & {
|
|
347
|
+
/** Which kind of device this it is */
|
|
348
|
+
smartType?: string | null;
|
|
349
|
+
/** Which value to set when the ON command is issued */
|
|
350
|
+
byOn?: string | null;
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
interface ChannelCommon extends ObjectCommon {
|
|
354
|
+
/** description of this channel */
|
|
355
|
+
desc?: string;
|
|
356
|
+
|
|
357
|
+
// Make it possible to narrow the object type using the custom property
|
|
358
|
+
custom?: undefined;
|
|
359
|
+
}
|
|
360
|
+
interface DeviceCommon extends ObjectCommon {
|
|
361
|
+
// TODO: any other definition for device?
|
|
362
|
+
|
|
363
|
+
// Make it possible to narrow the object type using the custom property
|
|
364
|
+
custom?: undefined;
|
|
365
|
+
}
|
|
366
|
+
interface EnumCommon extends ObjectCommon {
|
|
367
|
+
/** The IDs of the enum members */
|
|
368
|
+
members?: string[];
|
|
369
|
+
|
|
370
|
+
// Make it possible to narrow the object type using the custom property
|
|
371
|
+
custom?: undefined;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
interface MetaCommon extends ObjectCommon {
|
|
375
|
+
// Meta-objects have to additional CommonTypes
|
|
376
|
+
type: CommonType | 'meta.user' | 'meta.folder';
|
|
377
|
+
|
|
378
|
+
// Make it possible to narrow the object type using the custom property
|
|
379
|
+
custom?: undefined;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
type InstanceMode = 'none' | 'daemon' | 'subscribe' | 'schedule' | 'once' | 'extension';
|
|
383
|
+
interface InstanceCommon extends ObjectCommon {
|
|
384
|
+
/** The name of the host where this instance is running */
|
|
385
|
+
host: string;
|
|
386
|
+
enabled: boolean;
|
|
387
|
+
/** How and when this instance should be started */
|
|
388
|
+
mode: InstanceMode;
|
|
389
|
+
|
|
390
|
+
// Make it possible to narrow the object type using the custom property
|
|
391
|
+
custom?: undefined;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
interface HostCommon extends ObjectCommon {
|
|
395
|
+
/** The display name of this host */
|
|
396
|
+
name: string;
|
|
397
|
+
title: string;
|
|
398
|
+
installedVersion: string; // e.g. 1.2.3 (following semver)
|
|
399
|
+
/** The command line of the executable */
|
|
400
|
+
cmd: string;
|
|
401
|
+
hostname: string;
|
|
402
|
+
/** An array of IP addresses this host exposes */
|
|
403
|
+
address: string[]; // IPv4 or IPv6
|
|
404
|
+
|
|
405
|
+
type: 'js-controller';
|
|
406
|
+
platform: 'Javascript/Node.js';
|
|
407
|
+
|
|
408
|
+
// Make it possible to narrow the object type using the custom property
|
|
409
|
+
custom?: undefined;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
interface HostNative {
|
|
413
|
+
process: {
|
|
414
|
+
title: string;
|
|
415
|
+
versions: NodeJS.ProcessVersions;
|
|
416
|
+
env: Record<string, string>;
|
|
417
|
+
};
|
|
418
|
+
os: {
|
|
419
|
+
hostname: string;
|
|
420
|
+
type: ReturnType<(typeof os)['type']>;
|
|
421
|
+
platform: ReturnType<(typeof os)['platform']>;
|
|
422
|
+
arch: ReturnType<(typeof os)['arch']>;
|
|
423
|
+
release: ReturnType<(typeof os)['release']>;
|
|
424
|
+
endianness: ReturnType<(typeof os)['endianness']>;
|
|
425
|
+
tmpdir: ReturnType<(typeof os)['tmpdir']>;
|
|
426
|
+
};
|
|
427
|
+
hardware: {
|
|
428
|
+
cpus: ReturnType<(typeof os)['cpus']>;
|
|
429
|
+
totalmem: ReturnType<(typeof os)['totalmem']>;
|
|
430
|
+
networkInterfaces: ReturnType<(typeof os)['networkInterfaces']>;
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
type UserCommon = ioBroker.UserCommon;
|
|
435
|
+
|
|
436
|
+
type GroupCommon = ioBroker.GroupCommon;
|
|
437
|
+
|
|
438
|
+
type ScriptCommon = ioBroker.ScriptCommon;
|
|
439
|
+
|
|
440
|
+
type AdapterCommon = ioBroker.AdapterCommon;
|
|
441
|
+
|
|
442
|
+
interface OtherCommon extends ObjectCommon {
|
|
443
|
+
[propName: string]: any;
|
|
444
|
+
|
|
445
|
+
// Make it possible to narrow the object type using the custom property
|
|
446
|
+
custom?: undefined;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/* Base type for Objects. Should not be used directly */
|
|
450
|
+
interface BaseObject {
|
|
451
|
+
/** The ID of this object */
|
|
452
|
+
_id: string;
|
|
453
|
+
type: ObjectType; // specified in the derived interfaces
|
|
454
|
+
// Ideally we would limit this to JSON-serializable objects, but TypeScript doesn't allow this
|
|
455
|
+
// without bugging users to change their code --> https://github.com/microsoft/TypeScript/issues/15300
|
|
456
|
+
native: Record<string, any>;
|
|
457
|
+
common: Record<string, any>;
|
|
458
|
+
enums?: Record<string, string>;
|
|
459
|
+
acl?: ObjectACL;
|
|
460
|
+
from?: string;
|
|
461
|
+
/** The user who created or updated this object */
|
|
462
|
+
user?: string;
|
|
463
|
+
ts?: number;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
interface StateObject extends BaseObject {
|
|
467
|
+
type: 'state';
|
|
468
|
+
common: StateCommon;
|
|
469
|
+
acl?: StateACL;
|
|
470
|
+
/** The IDs of enums this state is assigned to. For example ["enum.functions.Licht","enum.rooms.Garten"] */
|
|
471
|
+
enumIds?: string[];
|
|
472
|
+
/** The names of enums this state is assigned to. For example ["Licht","Garten"] */
|
|
473
|
+
enumNames?: Array<iobJS.StringOrTranslated>;
|
|
474
|
+
}
|
|
475
|
+
interface PartialStateObject extends Partial<Omit<StateObject, 'common' | 'acl'>> {
|
|
476
|
+
common?: Partial<StateCommon>;
|
|
477
|
+
acl?: Partial<StateACL>;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
interface ChannelObject extends BaseObject {
|
|
481
|
+
type: 'channel';
|
|
482
|
+
common: ChannelCommon;
|
|
483
|
+
}
|
|
484
|
+
interface PartialChannelObject extends Partial<Omit<ChannelObject, 'common'>> {
|
|
485
|
+
common?: Partial<ChannelCommon>;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
interface DeviceObject extends BaseObject {
|
|
489
|
+
type: 'device';
|
|
490
|
+
common: DeviceCommon;
|
|
491
|
+
}
|
|
492
|
+
interface PartialDeviceObject extends Partial<Omit<DeviceObject, 'common'>> {
|
|
493
|
+
common?: Partial<DeviceCommon>;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
interface FolderObject extends BaseObject {
|
|
497
|
+
type: 'folder';
|
|
498
|
+
// Nothing is set in stone here, so start with allowing every property
|
|
499
|
+
common: OtherCommon;
|
|
500
|
+
}
|
|
501
|
+
interface PartialFolderObject extends Partial<Omit<FolderObject, 'common'>> {
|
|
502
|
+
common?: Partial<OtherCommon>;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
interface EnumObject extends BaseObject {
|
|
506
|
+
type: 'enum';
|
|
507
|
+
common: EnumCommon;
|
|
508
|
+
}
|
|
509
|
+
interface PartialEnumObject extends Partial<Omit<EnumObject, 'common'>> {
|
|
510
|
+
common?: Partial<EnumCommon>;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
interface MetaObject extends BaseObject {
|
|
514
|
+
type: 'meta';
|
|
515
|
+
common: MetaCommon;
|
|
516
|
+
}
|
|
517
|
+
interface PartialMetaObject extends Partial<Omit<MetaObject, 'common'>> {
|
|
518
|
+
common?: Partial<MetaCommon>;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
interface InstanceObject extends BaseObject {
|
|
522
|
+
type: 'instance';
|
|
523
|
+
common: InstanceCommon;
|
|
524
|
+
}
|
|
525
|
+
interface PartialInstanceObject extends Partial<Omit<InstanceObject, 'common'>> {
|
|
526
|
+
common?: Partial<InstanceCommon>;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
interface AdapterObject extends BaseObject {
|
|
530
|
+
type: 'adapter';
|
|
531
|
+
common: AdapterCommon;
|
|
532
|
+
/** An array of `native` properties which cannot be accessed from outside the defining adapter */
|
|
533
|
+
protectedNative?: string[];
|
|
534
|
+
/** Like protectedNative, but the properties are also encrypted and decrypted automatically */
|
|
535
|
+
encryptedNative?: string[];
|
|
536
|
+
}
|
|
537
|
+
interface PartialAdapterObject extends Partial<Omit<AdapterObject, 'common'>> {
|
|
538
|
+
common?: Partial<AdapterCommon>;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
interface HostObject extends BaseObject {
|
|
542
|
+
type: 'host';
|
|
543
|
+
common: HostCommon;
|
|
544
|
+
native: HostNative;
|
|
545
|
+
}
|
|
546
|
+
interface PartialHostObject extends Partial<Omit<HostObject, 'common' | 'native'>> {
|
|
547
|
+
common?: Partial<HostCommon>;
|
|
548
|
+
native?: Partial<HostNative>;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
interface UserObject extends BaseObject {
|
|
552
|
+
type: 'user';
|
|
553
|
+
common: UserCommon;
|
|
554
|
+
}
|
|
555
|
+
interface PartialUserObject extends Partial<Omit<UserObject, 'common'>> {
|
|
556
|
+
common?: Partial<UserCommon>;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
interface GroupObject extends BaseObject {
|
|
560
|
+
type: 'group';
|
|
561
|
+
common: GroupCommon;
|
|
562
|
+
}
|
|
563
|
+
interface PartialGroupObject extends Partial<Omit<GroupObject, 'common'>> {
|
|
564
|
+
common?: Partial<GroupCommon>;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
interface ScriptObject extends BaseObject {
|
|
568
|
+
type: 'script';
|
|
569
|
+
common: ScriptCommon;
|
|
570
|
+
}
|
|
571
|
+
interface PartialScriptObject extends Partial<Omit<ScriptObject, 'common'>> {
|
|
572
|
+
common?: Partial<ScriptCommon>;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
interface OtherObject extends BaseObject {
|
|
576
|
+
type: 'config' | 'chart';
|
|
577
|
+
common: OtherCommon;
|
|
578
|
+
}
|
|
579
|
+
interface PartialOtherObject extends Partial<Omit<OtherObject, 'common'>> {
|
|
580
|
+
common?: Partial<OtherCommon>;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
type AnyObject =
|
|
584
|
+
| StateObject
|
|
585
|
+
| ChannelObject
|
|
586
|
+
| DeviceObject
|
|
587
|
+
| FolderObject
|
|
588
|
+
| EnumObject
|
|
589
|
+
| MetaObject
|
|
590
|
+
| HostObject
|
|
591
|
+
| AdapterObject
|
|
592
|
+
| InstanceObject
|
|
593
|
+
| UserObject
|
|
594
|
+
| GroupObject
|
|
595
|
+
| ScriptObject
|
|
596
|
+
| OtherObject;
|
|
597
|
+
|
|
598
|
+
type AnyPartialObject =
|
|
599
|
+
| PartialStateObject
|
|
600
|
+
| PartialChannelObject
|
|
601
|
+
| PartialDeviceObject
|
|
602
|
+
| PartialFolderObject
|
|
603
|
+
| PartialEnumObject
|
|
604
|
+
| PartialMetaObject
|
|
605
|
+
| PartialHostObject
|
|
606
|
+
| PartialAdapterObject
|
|
607
|
+
| PartialInstanceObject
|
|
608
|
+
| PartialUserObject
|
|
609
|
+
| PartialGroupObject
|
|
610
|
+
| PartialScriptObject
|
|
611
|
+
| PartialOtherObject;
|
|
612
|
+
|
|
613
|
+
/** All objects that usually appear in an adapter scope */
|
|
614
|
+
type AdapterScopedObject = FolderObject | DeviceObject | ChannelObject | StateObject;
|
|
615
|
+
|
|
616
|
+
// For all objects that are exposed to the user we need to tone the strictness down.
|
|
617
|
+
// Otherwise, every operation on objects becomes a pain to work with
|
|
618
|
+
type Object = AnyObject;
|
|
619
|
+
|
|
620
|
+
// In set[Foreign]Object[NotExists] methods, the ID and acl of the object is optional
|
|
621
|
+
type SettableObjectWorker<T> = T extends AnyObject
|
|
622
|
+
? Omit<T, '_id' | 'acl'> & {
|
|
623
|
+
_id?: T['_id'];
|
|
624
|
+
acl?: T['acl'];
|
|
625
|
+
}
|
|
626
|
+
: never;
|
|
627
|
+
// in extend[Foreign]Object, most properties are optional
|
|
628
|
+
type PartialObjectWorker<T> = T extends AnyObject ? AnyPartialObject & { type?: T['type'] } : never;
|
|
629
|
+
|
|
630
|
+
type PartialObject<T extends AnyObject = AnyObject> = PartialObjectWorker<T>;
|
|
631
|
+
|
|
632
|
+
// Convenient definitions for manually specifying settable object types
|
|
633
|
+
type SettableObject<T extends AnyObject = AnyObject> = SettableObjectWorker<T>;
|
|
634
|
+
type SettableStateObject = SettableObject<StateObject>;
|
|
635
|
+
type SettableChannelObject = SettableObject<ChannelObject>;
|
|
636
|
+
type SettableDeviceObject = SettableObject<DeviceObject>;
|
|
637
|
+
type SettableFolderObject = SettableObject<FolderObject>;
|
|
638
|
+
type SettableEnumObject = SettableObject<EnumObject>;
|
|
639
|
+
type SettableMetaObject = SettableObject<MetaObject>;
|
|
640
|
+
type SettableHostObject = SettableObject<HostObject>;
|
|
641
|
+
type SettableAdapterObject = SettableObject<AdapterObject>;
|
|
642
|
+
type SettableInstanceObject = SettableObject<InstanceObject>;
|
|
643
|
+
type SettableUserObject = SettableObject<UserObject>;
|
|
644
|
+
type SettableGroupObject = SettableObject<GroupObject>;
|
|
645
|
+
type SettableScriptObject = SettableObject<ScriptObject>;
|
|
646
|
+
type SettableOtherObject = SettableObject<OtherObject>;
|
|
647
|
+
|
|
648
|
+
/** Represents the change of a state */
|
|
649
|
+
interface ChangedStateObject<TOld extends ioBroker.StateValue = any, TNew extends ioBroker.StateValue = TOld>
|
|
650
|
+
extends StateObject {
|
|
651
|
+
common: StateCommon;
|
|
652
|
+
native: Record<string, any>;
|
|
653
|
+
id?: string;
|
|
654
|
+
name?: string;
|
|
655
|
+
channelId?: string;
|
|
656
|
+
channelName?: string;
|
|
657
|
+
deviceId?: string;
|
|
658
|
+
deviceName?: string;
|
|
659
|
+
/** The IDs of enums this state is assigned to. For example ["enum.functions.Licht","enum.rooms.Garten"] */
|
|
660
|
+
enumIds?: string[];
|
|
661
|
+
/** The names of enums this state is assigned to. For example ["Licht","Garten"] */
|
|
662
|
+
enumNames?: Array<iobJS.StringOrTranslated>;
|
|
663
|
+
/** new state */
|
|
664
|
+
state: TypedState<TNew>;
|
|
665
|
+
/** @deprecated Use state instead */
|
|
666
|
+
newState: TypedState<TNew>;
|
|
667
|
+
/** previous state */
|
|
668
|
+
oldState: TypedState<TOld>;
|
|
669
|
+
/** Name of the adapter instance which set the value, e.g. "system.adapter.web.0" */
|
|
670
|
+
from?: string;
|
|
671
|
+
/** Unix timestamp. Default: current time */
|
|
672
|
+
ts?: number;
|
|
673
|
+
/** Unix timestamp of the last time the value changed */
|
|
674
|
+
lc?: number;
|
|
675
|
+
/** Direction flag: false for desired value and true for actual value. Default: false. */
|
|
676
|
+
ack?: boolean;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
type GetStateCallback<T extends ioBroker.StateValue = any> = (
|
|
680
|
+
err?: Error | null,
|
|
681
|
+
state?: TypedState<T> | AbsentState,
|
|
682
|
+
) => void | Promise<void>;
|
|
683
|
+
type ExistsStateCallback = (err?: Error | null, exists?: boolean) => void | Promise<void>;
|
|
684
|
+
|
|
685
|
+
type SetStateCallback = (err?: Error | null, id?: string) => void | Promise<void>;
|
|
686
|
+
type SetStatePromise = Promise<NonNullCallbackReturnTypeOf<SetStateCallback>>;
|
|
687
|
+
|
|
688
|
+
type StateChangeHandler<TOld extends ioBroker.StateValue = any, TNew extends TOld = any> = (
|
|
689
|
+
obj: ChangedStateObject<TOld, TNew>,
|
|
690
|
+
) => void | Promise<void>;
|
|
691
|
+
type ObjectChangeHandler = (id: string, obj: iobJS.Object) => void | Promise<void>;
|
|
692
|
+
|
|
693
|
+
type FileChangeHandler<WithFile extends boolean> =
|
|
694
|
+
// Variant 1: WithFile is false, data/mimeType is definitely not there
|
|
695
|
+
[WithFile] extends [false]
|
|
696
|
+
? (
|
|
697
|
+
id: string,
|
|
698
|
+
fileName: string,
|
|
699
|
+
size: number,
|
|
700
|
+
data?: undefined,
|
|
701
|
+
mimeType?: undefined,
|
|
702
|
+
) => void | Promise<void>
|
|
703
|
+
: // Variant 2: WithFile is true, data (and mimeType?) is definitely there
|
|
704
|
+
[WithFile] extends [true]
|
|
705
|
+
? (
|
|
706
|
+
id: string,
|
|
707
|
+
fileName: string,
|
|
708
|
+
size: number,
|
|
709
|
+
data: Buffer | string,
|
|
710
|
+
mimeType?: string,
|
|
711
|
+
) => void | Promise<void>
|
|
712
|
+
: // Variant 3: WithFile is not known, data/mimeType might be there
|
|
713
|
+
(
|
|
714
|
+
id: string,
|
|
715
|
+
fileName: string,
|
|
716
|
+
size: number,
|
|
717
|
+
data?: Buffer | string,
|
|
718
|
+
mimeType?: string,
|
|
719
|
+
) => void | Promise<void>;
|
|
720
|
+
|
|
721
|
+
type SetObjectCallback = (err?: Error | null, obj?: { id: string }) => void | Promise<void>;
|
|
722
|
+
type SetObjectPromise = Promise<NonNullCallbackReturnTypeOf<SetObjectCallback>>;
|
|
723
|
+
|
|
724
|
+
type GetObjectCallback<T extends string = string> = (
|
|
725
|
+
err?: Error | null,
|
|
726
|
+
obj?: ObjectIdToObjectType<T> | null,
|
|
727
|
+
) => void;
|
|
728
|
+
type GetObjectPromise<T extends string = string> = Promise<CallbackReturnTypeOf<GetObjectCallback<T>>>;
|
|
729
|
+
|
|
730
|
+
type LogLevel = 'silly' | 'debug' | 'info' | 'warn' | 'error' | 'force';
|
|
731
|
+
|
|
732
|
+
type ReadFileCallback = (err?: Error | null, file?: Buffer | string, mimeType?: string) => void | Promise<void>;
|
|
733
|
+
type ReadFilePromise = Promise<NonNullCallbackReturnTypeOf<ReadFileCallback>>;
|
|
734
|
+
|
|
735
|
+
/** Callback information for a passed message */
|
|
736
|
+
interface MessageCallbackInfo {
|
|
737
|
+
/** The original message payload */
|
|
738
|
+
message: string | object;
|
|
739
|
+
/** ID of this callback */
|
|
740
|
+
id: number;
|
|
741
|
+
// ???
|
|
742
|
+
ack: boolean;
|
|
743
|
+
/** Timestamp of this message */
|
|
744
|
+
time: number;
|
|
745
|
+
}
|
|
746
|
+
type MessageCallback = (result?: any) => void | Promise<void>;
|
|
747
|
+
|
|
748
|
+
interface SendToOptions {
|
|
749
|
+
/** Method throws or calls error cb, if callback not called in time, works for single targets only */
|
|
750
|
+
timeout?: number;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
interface Subscription {
|
|
754
|
+
name: string;
|
|
755
|
+
pattern: string | RegExp | string[] | iobJS.SubscribeOptions | iobJS.SubscribeTime | iobJS.AstroSchedule;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
interface SubscribeOptions {
|
|
759
|
+
/** "and" or "or" logic to combine the conditions (default: "and") */
|
|
760
|
+
logic?: 'and' | 'or';
|
|
761
|
+
/** name is equal or matches to given one or name marches to any item in given list */
|
|
762
|
+
id?: string | string[] | SubscribeOptions[] | RegExp | RegExp[];
|
|
763
|
+
/** name is equal or matches to given one */
|
|
764
|
+
name?: string | string[] | RegExp;
|
|
765
|
+
/** type of change */
|
|
766
|
+
change?: 'eq' | 'ne' | 'gt' | 'ge' | 'lt' | 'le' | 'any';
|
|
767
|
+
val?: ioBroker.StateValue;
|
|
768
|
+
/** New value must not be equal to given one */
|
|
769
|
+
valNe?: ioBroker.StateValue;
|
|
770
|
+
/** New value must be greater than given one */
|
|
771
|
+
valGt?: number;
|
|
772
|
+
/** New value must be greater or equal to given one */
|
|
773
|
+
valGe?: number;
|
|
774
|
+
/** The new value must be smaller than given one */
|
|
775
|
+
valLt?: number;
|
|
776
|
+
/** New value must be smaller or equal to given one */
|
|
777
|
+
valLe?: number;
|
|
778
|
+
/** The acknowledged state of new value is equal to given one */
|
|
779
|
+
ack?: boolean;
|
|
780
|
+
/** Previous value must be equal to given one */
|
|
781
|
+
oldVal?: ioBroker.StateValue;
|
|
782
|
+
/** Previous value must be not equal to given one */
|
|
783
|
+
oldValNe?: ioBroker.StateValue;
|
|
784
|
+
/** The previous value must be greater than given one */
|
|
785
|
+
oldValGt?: number;
|
|
786
|
+
/** Previous value must be greater or equal given one */
|
|
787
|
+
oldValGe?: number;
|
|
788
|
+
/** The previous value must be smaller than given one */
|
|
789
|
+
oldValLt?: number;
|
|
790
|
+
/** The previous value must be smaller or equal to given one */
|
|
791
|
+
oldValLe?: number;
|
|
792
|
+
/** Acknowledged state of previous value is equal to given one */
|
|
793
|
+
oldAck?: boolean;
|
|
794
|
+
/** New value time stamp must be equal to given one (state.ts == ts) */
|
|
795
|
+
ts?: number;
|
|
796
|
+
/** New value time stamp must be not equal to the given one (state.ts != ts) */
|
|
797
|
+
tsGt?: number;
|
|
798
|
+
/** New value time stamp must be greater than given value (state.ts > ts) */
|
|
799
|
+
tsGe?: number;
|
|
800
|
+
/** New value time stamp must be greater or equal to given one (state.ts >= ts) */
|
|
801
|
+
tsLt?: number;
|
|
802
|
+
/** New value time stamp must be smaller than given one (state.ts < ts) */
|
|
803
|
+
tsLe?: number;
|
|
804
|
+
/** Previous time stamp must be equal to given one (oldState.ts == ts) */
|
|
805
|
+
oldTs?: number;
|
|
806
|
+
/** Previous time stamp must be not equal to the given one (oldState.ts != ts) */
|
|
807
|
+
oldTsGt?: number;
|
|
808
|
+
/** Previous time stamp must be greater than the given value (oldState.ts > ts) */
|
|
809
|
+
oldTsGe?: number;
|
|
810
|
+
/** Previous time stamp must be greater or equal to given one (oldState.ts >= ts) */
|
|
811
|
+
oldTsLt?: number;
|
|
812
|
+
/** Previous time stamp must be smaller than given one (oldState.ts < ts) */
|
|
813
|
+
oldTsLe?: number;
|
|
814
|
+
/** Last change time stamp must be equal to given one (state.lc == lc) */
|
|
815
|
+
lc?: number;
|
|
816
|
+
/** Last change time stamp must be not equal to the given one (state.lc != lc) */
|
|
817
|
+
lcGt?: number;
|
|
818
|
+
/** Last change time stamp must be greater than the given value (state.lc > lc) */
|
|
819
|
+
lcGe?: number;
|
|
820
|
+
/** Last change time stamp must be greater or equal to given one (state.lc >= lc) */
|
|
821
|
+
lcLt?: number;
|
|
822
|
+
/** Last change time stamp must be smaller than given one (state.lc < lc) */
|
|
823
|
+
lcLe?: number;
|
|
824
|
+
/** Previous last change time stamp must be equal to given one (oldState.lc == lc) */
|
|
825
|
+
oldLc?: number;
|
|
826
|
+
/** Previous last change time stamp must be not equal to the given one (oldState.lc != lc) */
|
|
827
|
+
oldLcGt?: number;
|
|
828
|
+
/** Previous last change time stamp must be greater than the given value (oldState.lc > lc) */
|
|
829
|
+
oldLcGe?: number;
|
|
830
|
+
/** Previous last change time stamp must be greater or equal to given one (oldState.lc >= lc) */
|
|
831
|
+
oldLcLt?: number;
|
|
832
|
+
/** Previous last change time stamp must be smaller than given one (oldState.lc < lc) */
|
|
833
|
+
oldLcLe?: number;
|
|
834
|
+
/** Channel ID must be equal or match to given one */
|
|
835
|
+
channelId?: string | string[] | RegExp;
|
|
836
|
+
/** Channel name must be equal or match to given one */
|
|
837
|
+
channelName?: string | string[] | RegExp;
|
|
838
|
+
/** Device ID must be equal or match to given one */
|
|
839
|
+
deviceId?: string | string[] | RegExp;
|
|
840
|
+
/** Device name must be equal or match to given one */
|
|
841
|
+
deviceName?: string | string[] | RegExp;
|
|
842
|
+
/** State belongs to given enum or one enum ID of state satisfy the given regular expression */
|
|
843
|
+
enumId?: string | string[] | RegExp;
|
|
844
|
+
/** State belongs to given enum or one enum name of state satisfy the given regular expression */
|
|
845
|
+
enumName?: string | string[] | RegExp;
|
|
846
|
+
/** New value is from defined adapter */
|
|
847
|
+
from?: string | string[] | RegExp;
|
|
848
|
+
/** New value is not from defined adapter */
|
|
849
|
+
fromNe?: string | string[] | RegExp;
|
|
850
|
+
/** Old value is from defined adapter */
|
|
851
|
+
oldFrom?: string | string[] | RegExp;
|
|
852
|
+
/** Old value is not from defined adapter */
|
|
853
|
+
oldFromNe?: string | string[] | RegExp;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
interface QueryResult extends Iterable<string> {
|
|
857
|
+
/** State-ID */
|
|
858
|
+
[index: number]: string;
|
|
859
|
+
/** Number of matched states */
|
|
860
|
+
length: number;
|
|
861
|
+
/** Contains the error if one happened */
|
|
862
|
+
error?: string;
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Return the result as an array of state ids
|
|
866
|
+
*/
|
|
867
|
+
toArray(): Array<string>;
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Executes a function for each state id in the result array
|
|
871
|
+
* The execution is canceled if a callback returns false
|
|
872
|
+
*/
|
|
873
|
+
each(callback?: (id: string, index: number) => boolean | void | Promise<void>): this;
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Returns the first state found by this query.
|
|
877
|
+
* If the adapter is configured to subscribe to all states on start,
|
|
878
|
+
* this can be called synchronously and immediately returns the state.
|
|
879
|
+
* Otherwise, you need to provide a callback.
|
|
880
|
+
*/
|
|
881
|
+
getState<T extends ioBroker.StateValue = any>(callback: GetStateCallback<T>): void;
|
|
882
|
+
getState<T extends ioBroker.StateValue = any>(): TypedState<T> | null | undefined;
|
|
883
|
+
getStateAsync<T extends ioBroker.StateValue = any>(): Promise<
|
|
884
|
+
TypedState<T> | iobJS.AbsentState | null | undefined
|
|
885
|
+
>;
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Sets all queried states to the given value.
|
|
889
|
+
*/
|
|
890
|
+
setState(
|
|
891
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
892
|
+
ack?: boolean | 'true' | 'false' | SetStateCallback,
|
|
893
|
+
callback?: SetStateCallback,
|
|
894
|
+
): this;
|
|
895
|
+
setStateAsync(
|
|
896
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
897
|
+
ack?: boolean | 'true' | 'false',
|
|
898
|
+
): Promise<void>;
|
|
899
|
+
setStateDelayed(
|
|
900
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
901
|
+
isAck: boolean | number | undefined,
|
|
902
|
+
delay?: number | boolean,
|
|
903
|
+
clearRunning?: boolean | (() => void),
|
|
904
|
+
callback?: () => void,
|
|
905
|
+
): this;
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Sets all queried states to the given value only if the value really changed.
|
|
909
|
+
*/
|
|
910
|
+
setStateChanged(
|
|
911
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
912
|
+
ack?: boolean,
|
|
913
|
+
callback?: SetStateCallback,
|
|
914
|
+
): this;
|
|
915
|
+
setStateChangedAsync(state: ioBroker.StateValue | ioBroker.SettableState, ack?: boolean): Promise<void>;
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* Subscribes the given callback to changes of the matched states.
|
|
919
|
+
*/
|
|
920
|
+
on(callback: StateChangeHandler): this;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* - "sunrise": sunrise (top edge of the sun appears on the horizon)
|
|
925
|
+
* - "sunriseEnd": sunrise ends (bottom edge of the sun touches the horizon)
|
|
926
|
+
* - "goldenHourEnd": morning golden hour (soft light, best time for photography) ends
|
|
927
|
+
* - "solarNoon": solar noon (sun is in the highest position)
|
|
928
|
+
* - "goldenHour": evening golden hour starts
|
|
929
|
+
* - "sunsetStart": sunset starts (bottom edge of the sun touches the horizon)
|
|
930
|
+
* - "sunset": sunset (sun disappears below the horizon, evening civil twilight starts)
|
|
931
|
+
* - "dusk": dusk (evening nautical twilight starts)
|
|
932
|
+
* - "nauticalDusk": nautical dusk (evening astronomical twilight starts)
|
|
933
|
+
* - "night": night starts (dark enough for astronomical observations)
|
|
934
|
+
* - "nightEnd": night ends (morning astronomical twilight starts)
|
|
935
|
+
* - "nauticalDawn": nautical dawn (morning nautical twilight starts)
|
|
936
|
+
* - "dawn": dawn (morning nautical twilight ends, morning civil twilight starts)
|
|
937
|
+
* - "nadir": nadir (darkest moment of the night, sun is in the lowest position)
|
|
938
|
+
*/
|
|
939
|
+
type AstroPattern =
|
|
940
|
+
| 'sunrise'
|
|
941
|
+
| 'sunriseEnd'
|
|
942
|
+
| 'goldenHourEnd'
|
|
943
|
+
| 'solarNoon'
|
|
944
|
+
| 'goldenHour'
|
|
945
|
+
| 'sunsetStart'
|
|
946
|
+
| 'sunset'
|
|
947
|
+
| 'dusk'
|
|
948
|
+
| 'nauticalDusk'
|
|
949
|
+
| 'night'
|
|
950
|
+
| 'nightEnd'
|
|
951
|
+
| 'nauticalDawn'
|
|
952
|
+
| 'dawn'
|
|
953
|
+
| 'nadir';
|
|
954
|
+
|
|
955
|
+
interface AstroSchedule {
|
|
956
|
+
astro: AstroPattern;
|
|
957
|
+
/**
|
|
958
|
+
* Shift to the astro schedule.
|
|
959
|
+
*/
|
|
960
|
+
shift?: number;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
interface AstroDate {
|
|
964
|
+
astro: AstroPattern;
|
|
965
|
+
/** Offset to the astro event in minutes */
|
|
966
|
+
offset?: number;
|
|
967
|
+
/** Date for which the astro time is wanted */
|
|
968
|
+
date?: Date;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* from https://github.com/node-schedule/node-schedule
|
|
973
|
+
*/
|
|
974
|
+
interface ScheduleRule {
|
|
975
|
+
/**
|
|
976
|
+
* Day of the month.
|
|
977
|
+
*/
|
|
978
|
+
date?: number | number[] | string | string[];
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Day of the week.
|
|
982
|
+
*/
|
|
983
|
+
dayOfWeek?: number | number[] | string | string[];
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* Hour.
|
|
987
|
+
*/
|
|
988
|
+
hour?: number | number[] | string | string[];
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Minute.
|
|
992
|
+
*/
|
|
993
|
+
minute?: number | number[] | string | string[];
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* Month.
|
|
997
|
+
*/
|
|
998
|
+
month?: number | number[] | string | string[];
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* Second.
|
|
1002
|
+
*/
|
|
1003
|
+
second?: number | number[] | string | string[];
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Year.
|
|
1007
|
+
*/
|
|
1008
|
+
year?: number | number[] | string | string[];
|
|
1009
|
+
/**
|
|
1010
|
+
* timezone which should be used
|
|
1011
|
+
* https://github.com/moment/moment-timezone
|
|
1012
|
+
*/
|
|
1013
|
+
tz?: string;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* from https://github.com/node-schedule/node-schedule
|
|
1018
|
+
*/
|
|
1019
|
+
interface ScheduleRuleConditional {
|
|
1020
|
+
/**
|
|
1021
|
+
* set a start time for schedule
|
|
1022
|
+
* a Data object or a dateString resp a number in milliseconds which can create a Date object
|
|
1023
|
+
*/
|
|
1024
|
+
start?: Date | string | number;
|
|
1025
|
+
/**
|
|
1026
|
+
* set an end time for schedule
|
|
1027
|
+
* a Data object or a dateString resp a number in milliseconds which can create a Date object
|
|
1028
|
+
*/
|
|
1029
|
+
end?: Date | string | number;
|
|
1030
|
+
/**
|
|
1031
|
+
* timezone which should be used
|
|
1032
|
+
* https://github.com/moment/moment-timezone
|
|
1033
|
+
*/
|
|
1034
|
+
tz?: string;
|
|
1035
|
+
/**
|
|
1036
|
+
* scheduling rule
|
|
1037
|
+
* schedule rule, a Data object or a dateString resp a number in milliseconds which can create a Date object
|
|
1038
|
+
*/
|
|
1039
|
+
rule: ScheduleRule | Date | string | number;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
interface ScheduleStatus {
|
|
1043
|
+
type: string;
|
|
1044
|
+
pattern?: string;
|
|
1045
|
+
scriptName: string;
|
|
1046
|
+
id: string;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
interface LogMessage {
|
|
1050
|
+
severity: LogLevel; // severity
|
|
1051
|
+
ts: number; // timestamp as Date.now()
|
|
1052
|
+
message: string; // message
|
|
1053
|
+
from: string; // origin of the message
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
type SchedulePattern = ScheduleRule | ScheduleRuleConditional | Date | string | number;
|
|
1057
|
+
|
|
1058
|
+
interface SubscribeTime {
|
|
1059
|
+
time: SchedulePattern;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
interface StateTimer {
|
|
1063
|
+
id: number;
|
|
1064
|
+
left: number;
|
|
1065
|
+
delay: number;
|
|
1066
|
+
val: any;
|
|
1067
|
+
ack: boolean;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
type MessageSubscribeID = number;
|
|
1071
|
+
interface MessageTarget {
|
|
1072
|
+
/** Javascript Instance */
|
|
1073
|
+
instance?: string;
|
|
1074
|
+
/** Script name */
|
|
1075
|
+
script?: string;
|
|
1076
|
+
/** Message name */
|
|
1077
|
+
message: string;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
type LogSubscribeID = number;
|
|
1081
|
+
|
|
1082
|
+
interface HttpRequestOptions {
|
|
1083
|
+
timeout?: number;
|
|
1084
|
+
responseType?: 'text' | 'arraybuffer';
|
|
1085
|
+
basicAuth?: {
|
|
1086
|
+
user: string;
|
|
1087
|
+
password: string;
|
|
1088
|
+
};
|
|
1089
|
+
bearerAuth?: string;
|
|
1090
|
+
headers?: Record<string, string>;
|
|
1091
|
+
validateCertificate?: boolean;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
type HttpResponseCallback = (err?: Error | null, response?: iobJS.httpResponse) => void | Promise<void>;
|
|
1095
|
+
interface httpResponse {
|
|
1096
|
+
statusCode: number;
|
|
1097
|
+
data: string;
|
|
1098
|
+
headers: Record<string, string>;
|
|
1099
|
+
responseTime?: number;
|
|
1100
|
+
}
|
|
1101
|
+
} // end namespace iobJS
|
|
1102
|
+
|
|
1103
|
+
// =======================================================
|
|
1104
|
+
// available functions in the sandbox
|
|
1105
|
+
// =======================================================
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* The instance number of the JavaScript adapter this script runs in
|
|
1109
|
+
*/
|
|
1110
|
+
const instance: number;
|
|
1111
|
+
/**
|
|
1112
|
+
* The name of the current script
|
|
1113
|
+
*/
|
|
1114
|
+
const scriptName: string;
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* Absolute path to iobroker-data directory in a file system
|
|
1118
|
+
*/
|
|
1119
|
+
const defaultDataDir: string;
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Status of verbose mode
|
|
1123
|
+
*/
|
|
1124
|
+
const verbose: boolean;
|
|
1125
|
+
|
|
1126
|
+
/**
|
|
1127
|
+
* Queries all states with the given selector
|
|
1128
|
+
*
|
|
1129
|
+
* @param selector See @link{https://github.com/ioBroker/ioBroker.javascript#---selector} for a description
|
|
1130
|
+
*/
|
|
1131
|
+
function $(selector: string): iobJS.QueryResult;
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* Prints a message in the ioBroker log
|
|
1135
|
+
*
|
|
1136
|
+
* @param message The message to print
|
|
1137
|
+
* @param severity (optional) severity of the message. default = "info"
|
|
1138
|
+
*/
|
|
1139
|
+
function log(message: any, severity?: iobJS.LogLevel): void;
|
|
1140
|
+
|
|
1141
|
+
// console functions
|
|
1142
|
+
// @ts-expect-error We need this variable, although it conflicts with the node typings
|
|
1143
|
+
namespace console {
|
|
1144
|
+
/** log a message with info level */
|
|
1145
|
+
function log(message: any): void;
|
|
1146
|
+
/** log a message with debug level */
|
|
1147
|
+
function debug(message: any): void;
|
|
1148
|
+
/** log a message with info level (default output level for all adapters) */
|
|
1149
|
+
function info(message: any): void;
|
|
1150
|
+
/** log a message with warning severity */
|
|
1151
|
+
function warn(message: any): void;
|
|
1152
|
+
/** log a message with error severity */
|
|
1153
|
+
function error(message: any): void;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* Executes a system command
|
|
1158
|
+
*/
|
|
1159
|
+
const exec: (
|
|
1160
|
+
command: string,
|
|
1161
|
+
callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
|
|
1162
|
+
) => ChildProcess;
|
|
1163
|
+
|
|
1164
|
+
/**
|
|
1165
|
+
* Sends an email using the email adapter.
|
|
1166
|
+
* See the adapter documentation for a description of the msg parameter.
|
|
1167
|
+
*
|
|
1168
|
+
* @deprecated Use @see sendTo
|
|
1169
|
+
*/
|
|
1170
|
+
function email(msg: any): void;
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Sends a pushover message using the pushover adapter.
|
|
1174
|
+
* See the adapter documentation for a description of the msg parameter.
|
|
1175
|
+
*
|
|
1176
|
+
* @deprecated Use @see sendTo
|
|
1177
|
+
*/
|
|
1178
|
+
function pushover(msg: any): void;
|
|
1179
|
+
|
|
1180
|
+
function httpGet(url: string, callback: iobJS.HttpResponseCallback): void;
|
|
1181
|
+
function httpGet(url: string, options: iobJS.HttpRequestOptions, callback: iobJS.HttpResponseCallback): void;
|
|
1182
|
+
|
|
1183
|
+
function httpGetAsync(url: string): Promise<iobJS.httpResponse>;
|
|
1184
|
+
function httpGetAsync(url: string, options: iobJS.HttpRequestOptions): Promise<iobJS.httpResponse>;
|
|
1185
|
+
|
|
1186
|
+
function httpPost(url: string, data: object | string, callback: iobJS.HttpResponseCallback): void;
|
|
1187
|
+
function httpPost(
|
|
1188
|
+
url: string,
|
|
1189
|
+
data: object | string,
|
|
1190
|
+
options: iobJS.HttpRequestOptions,
|
|
1191
|
+
callback: iobJS.HttpResponseCallback,
|
|
1192
|
+
): void;
|
|
1193
|
+
|
|
1194
|
+
function httpPostAsync(url: string, data: object | string): Promise<iobJS.httpResponse>;
|
|
1195
|
+
function httpPostAsync(
|
|
1196
|
+
url: string,
|
|
1197
|
+
data: object | string,
|
|
1198
|
+
options: iobJS.HttpRequestOptions,
|
|
1199
|
+
): Promise<iobJS.httpResponse>;
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* Creates a temp directory for the current script and saves a new file with given content
|
|
1203
|
+
*/
|
|
1204
|
+
function createTempFile(fileName: string, data: string | ArrayBuffer): string;
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* Subscribe to the changes of the matched states.
|
|
1208
|
+
*/
|
|
1209
|
+
function on(pattern: string | RegExp | string[], handler: iobJS.StateChangeHandler): any;
|
|
1210
|
+
function on(
|
|
1211
|
+
astroOrScheduleOrOptions: iobJS.AstroSchedule | iobJS.SubscribeTime | iobJS.SubscribeOptions,
|
|
1212
|
+
handler: iobJS.StateChangeHandler,
|
|
1213
|
+
): any;
|
|
1214
|
+
/**
|
|
1215
|
+
* Subscribe to the changes of the matched states.
|
|
1216
|
+
*/
|
|
1217
|
+
function subscribe(pattern: string | RegExp | string[], handler: iobJS.StateChangeHandler): any;
|
|
1218
|
+
function subscribe(
|
|
1219
|
+
astroOrScheduleOrOptions: iobJS.AstroSchedule | iobJS.SubscribeTime | iobJS.SubscribeOptions,
|
|
1220
|
+
handler: iobJS.StateChangeHandler,
|
|
1221
|
+
): any;
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* Subscribe to all members of an enum (even if the enum changes over time)
|
|
1225
|
+
*/
|
|
1226
|
+
function onEnumMembers(id: string, handler: iobJS.StateChangeHandler): void;
|
|
1227
|
+
|
|
1228
|
+
/**
|
|
1229
|
+
* Subscribe to the changes of the matched files.
|
|
1230
|
+
* The return value can be used for offFile later
|
|
1231
|
+
*
|
|
1232
|
+
* @param id ID of a meta-object, like `vis.0`
|
|
1233
|
+
* @param filePattern File name or file pattern, like `main/*`
|
|
1234
|
+
* @param withFile If the content of the file must be returned in callback (high usage of memory)
|
|
1235
|
+
* @param handler Callback: function (id, fileName, size, data, mimeType) {}
|
|
1236
|
+
*/
|
|
1237
|
+
function onFile<WithFile extends boolean>(
|
|
1238
|
+
id: string,
|
|
1239
|
+
filePattern: string | string[],
|
|
1240
|
+
withFile: WithFile,
|
|
1241
|
+
handler: iobJS.FileChangeHandler<WithFile>,
|
|
1242
|
+
): any;
|
|
1243
|
+
function onFile(id: string, filePattern: string | string[], handler: iobJS.FileChangeHandler<false>): any;
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Un-subscribe from the changes of the matched files.
|
|
1247
|
+
*
|
|
1248
|
+
* @param id ID of a meta-object, like `vis.0`. You can provide here can be a returned object from onFile. In this case, no filePattern required.
|
|
1249
|
+
* @param filePattern File name or file pattern, like `main/*`
|
|
1250
|
+
*/
|
|
1251
|
+
function offFile(id: string | string[], filePattern?: string | string[]): boolean;
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* Registers a one-time subscription which automatically unsubscribes after the first invocation
|
|
1255
|
+
*/
|
|
1256
|
+
function once(
|
|
1257
|
+
pattern: string | RegExp | string[] | iobJS.AstroSchedule | iobJS.SubscribeTime | iobJS.SubscribeOptions,
|
|
1258
|
+
handler: iobJS.StateChangeHandler,
|
|
1259
|
+
): any;
|
|
1260
|
+
function once(
|
|
1261
|
+
pattern: string | RegExp | string[] | iobJS.AstroSchedule | iobJS.SubscribeTime | iobJS.SubscribeOptions,
|
|
1262
|
+
): Promise<iobJS.ChangedStateObject>;
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* Causes all changes of the state with id1 to the state with id2.
|
|
1266
|
+
* The return value can be used to unsubscribe later
|
|
1267
|
+
*/
|
|
1268
|
+
function on(id1: string, id2: string): void;
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Watches the state with id1 for changes and overwrites the state with id2 with value2 when any occur.
|
|
1272
|
+
*
|
|
1273
|
+
* @param id1 The state to watch for changes
|
|
1274
|
+
* @param id2 The state to update when changes occur
|
|
1275
|
+
* @param value2 The value to write into state `id2` when `id1` gets changed
|
|
1276
|
+
*/
|
|
1277
|
+
function on(id1: string, id2: string, value2: any): void;
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* Causes all changes of the state with id1 to the state with id2
|
|
1281
|
+
*/
|
|
1282
|
+
function subscribe(id1: string, id2: string): void;
|
|
1283
|
+
|
|
1284
|
+
/**
|
|
1285
|
+
* Watches the state with id1 for changes and overwrites the state with id2 with value2 when any occur.
|
|
1286
|
+
*
|
|
1287
|
+
* @param id1 The state to watch for changes
|
|
1288
|
+
* @param id2 The state to update when changes occur
|
|
1289
|
+
* @param value2 The value to write into state `id2` when `id1` gets changed
|
|
1290
|
+
*/
|
|
1291
|
+
function subscribe(id1: string, id2: string, value2: any): void;
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* Returns the list of all active subscriptions
|
|
1295
|
+
*/
|
|
1296
|
+
function getSubscriptions(): { [id: string]: iobJS.Subscription[] };
|
|
1297
|
+
|
|
1298
|
+
/**
|
|
1299
|
+
* Returns the list of all active file subscriptions
|
|
1300
|
+
*/
|
|
1301
|
+
function getFileSubscriptions(): { [id: string]: iobJS.Subscription[] };
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Unsubscribe from changes of the given object ID(s) or handler(s)
|
|
1305
|
+
*/
|
|
1306
|
+
function unsubscribe(id: string | RegExp | string[]): boolean;
|
|
1307
|
+
|
|
1308
|
+
function adapterSubscribe(id: string): void;
|
|
1309
|
+
function adapterUnsubscribe(id: string): void;
|
|
1310
|
+
|
|
1311
|
+
/**
|
|
1312
|
+
* Schedules a function to be executed on a defined schedule.
|
|
1313
|
+
* The return value can be used to clear the schedule later.
|
|
1314
|
+
*/
|
|
1315
|
+
function schedule(pattern: string | iobJS.SchedulePattern, callback: EmptyCallback): any;
|
|
1316
|
+
function schedule(date: Date, callback: EmptyCallback): any;
|
|
1317
|
+
function schedule(astro: iobJS.AstroSchedule, callback: EmptyCallback): any;
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* [{"type":"cron","pattern":"0 15 13 * * *","scriptName":"script.js.scheduleById","id":"cron_1704187467197_22756"}]
|
|
1321
|
+
*
|
|
1322
|
+
* @param allScripts Return all registered schedules of all running scripts
|
|
1323
|
+
*/
|
|
1324
|
+
function getSchedules(allScripts?: boolean): Array<iobJS.ScheduleStatus>;
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* Creates a schedule based on the state value (e.g., 12:53:09)
|
|
1328
|
+
* Schedule will be updated if the state value changes
|
|
1329
|
+
*/
|
|
1330
|
+
function scheduleById(id: string, callback: EmptyCallback): any;
|
|
1331
|
+
function scheduleById(id: string, ack: boolean, callback: EmptyCallback): any;
|
|
1332
|
+
|
|
1333
|
+
/**
|
|
1334
|
+
* Clears a schedule. Returns true if it was successful.
|
|
1335
|
+
*/
|
|
1336
|
+
function clearSchedule(schedule: any): boolean;
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* Calculates the astro time which corresponds to the given pattern.
|
|
1340
|
+
* For valid patterns, see @link{https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#astro-function}
|
|
1341
|
+
*
|
|
1342
|
+
* @param pattern One of predefined patterns, like: sunrise, sunriseEnd, ...
|
|
1343
|
+
* @param date (optional) The date for which the astro time should be calculated. Default = today
|
|
1344
|
+
* @param offsetMinutes (optional) The number of minutes to be added to the return value.
|
|
1345
|
+
*/
|
|
1346
|
+
function getAstroDate(pattern: string, date?: Date | number, offsetMinutes?: number): Date;
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Determines if now is between sunrise and sunset.
|
|
1350
|
+
*/
|
|
1351
|
+
function isAstroDay(): boolean;
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* Sets a state to the given value
|
|
1355
|
+
*
|
|
1356
|
+
* @param id The ID of the state to be set
|
|
1357
|
+
* @param state New state value
|
|
1358
|
+
* @param callback Callback
|
|
1359
|
+
*/
|
|
1360
|
+
function setState(
|
|
1361
|
+
id: string,
|
|
1362
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1363
|
+
callback?: iobJS.SetStateCallback,
|
|
1364
|
+
): void;
|
|
1365
|
+
function setState(
|
|
1366
|
+
id: string,
|
|
1367
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1368
|
+
ack: boolean,
|
|
1369
|
+
callback?: iobJS.SetStateCallback,
|
|
1370
|
+
): void;
|
|
1371
|
+
|
|
1372
|
+
function setStateAsync(
|
|
1373
|
+
id: string,
|
|
1374
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1375
|
+
ack?: boolean,
|
|
1376
|
+
): iobJS.SetStatePromise;
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* Sets a state to the given value only if the value really changed.
|
|
1380
|
+
*
|
|
1381
|
+
* @param id The ID of the state to be set
|
|
1382
|
+
* @param state New state value
|
|
1383
|
+
* @param callback Callback
|
|
1384
|
+
*/
|
|
1385
|
+
function setStateChanged(
|
|
1386
|
+
id: string,
|
|
1387
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1388
|
+
callback?: iobJS.SetStateCallback,
|
|
1389
|
+
): void;
|
|
1390
|
+
function setStateChanged(
|
|
1391
|
+
id: string,
|
|
1392
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1393
|
+
ack: boolean,
|
|
1394
|
+
callback?: iobJS.SetStateCallback,
|
|
1395
|
+
): void;
|
|
1396
|
+
|
|
1397
|
+
function setStateChangedAsync(
|
|
1398
|
+
id: string,
|
|
1399
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1400
|
+
ack?: boolean,
|
|
1401
|
+
): iobJS.SetStatePromise;
|
|
1402
|
+
|
|
1403
|
+
/**
|
|
1404
|
+
* Sets a state to the given value after a timeout has passed.
|
|
1405
|
+
* Returns the timer, so it can be manually cleared with clearStateDelayed
|
|
1406
|
+
*
|
|
1407
|
+
* @param id The ID of the state to be set
|
|
1408
|
+
* @param state New state value
|
|
1409
|
+
* @param delay The delay in milliseconds
|
|
1410
|
+
* @param clearRunning (optional) Whether an existing timeout for this state should be cleared
|
|
1411
|
+
* @param callback Callback
|
|
1412
|
+
* @returns If a delayed setState was scheduled, this returns the timer id, otherwise null.
|
|
1413
|
+
*/
|
|
1414
|
+
function setStateDelayed(
|
|
1415
|
+
id: string,
|
|
1416
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1417
|
+
delay: number,
|
|
1418
|
+
clearRunning: boolean,
|
|
1419
|
+
callback?: iobJS.SetStateCallback,
|
|
1420
|
+
): number | null;
|
|
1421
|
+
function setStateDelayed(
|
|
1422
|
+
id: string,
|
|
1423
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1424
|
+
ack: boolean,
|
|
1425
|
+
clearRunning: boolean,
|
|
1426
|
+
callback?: iobJS.SetStateCallback,
|
|
1427
|
+
): number | null;
|
|
1428
|
+
function setStateDelayed(
|
|
1429
|
+
id: string,
|
|
1430
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1431
|
+
ack: boolean,
|
|
1432
|
+
delay: number,
|
|
1433
|
+
callback?: iobJS.SetStateCallback,
|
|
1434
|
+
): number | null;
|
|
1435
|
+
function setStateDelayed(
|
|
1436
|
+
id: string,
|
|
1437
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1438
|
+
delay: number,
|
|
1439
|
+
callback?: iobJS.SetStateCallback,
|
|
1440
|
+
): number | null;
|
|
1441
|
+
function setStateDelayed(
|
|
1442
|
+
id: string,
|
|
1443
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1444
|
+
callback?: iobJS.SetStateCallback,
|
|
1445
|
+
): number | null;
|
|
1446
|
+
function setStateDelayed(
|
|
1447
|
+
id: string,
|
|
1448
|
+
state: ioBroker.StateValue | ioBroker.SettableState,
|
|
1449
|
+
ack: boolean,
|
|
1450
|
+
delay: number,
|
|
1451
|
+
clearRunning: boolean,
|
|
1452
|
+
callback?: iobJS.SetStateCallback,
|
|
1453
|
+
): number | null;
|
|
1454
|
+
|
|
1455
|
+
/**
|
|
1456
|
+
* Clears a timer created by setStateDelayed
|
|
1457
|
+
*
|
|
1458
|
+
* @param id The state id for which the timer should be cleared
|
|
1459
|
+
* @param timerID (optional) ID of the specific timer to clear. If none is given, all timers are cleared.
|
|
1460
|
+
*/
|
|
1461
|
+
function clearStateDelayed(id: string, timerID?: number): boolean;
|
|
1462
|
+
|
|
1463
|
+
/**
|
|
1464
|
+
* Returns information about a specific timer created with `setStateDelayed`.
|
|
1465
|
+
*
|
|
1466
|
+
* @param timerId The timer id that was returned by `setStateDelayed`.
|
|
1467
|
+
*/
|
|
1468
|
+
function getStateDelayed(timerId: number): iobJS.StateTimer | null;
|
|
1469
|
+
/**
|
|
1470
|
+
* Returns a list of all timers created with `setStateDelayed`. Can be limited to a specific state id.
|
|
1471
|
+
*
|
|
1472
|
+
* @param id The state id for which the timers should be.
|
|
1473
|
+
*/
|
|
1474
|
+
function getStateDelayed(id?: string): iobJS.StateTimer[];
|
|
1475
|
+
|
|
1476
|
+
/**
|
|
1477
|
+
* Returns the state with the given ID.
|
|
1478
|
+
* If the adapter is configured to subscribe to all states on start,
|
|
1479
|
+
* this can be called synchronously and immediately returns the state.
|
|
1480
|
+
* Otherwise, you need to provide a callback.
|
|
1481
|
+
*/
|
|
1482
|
+
function getState<T extends ioBroker.StateValue = any>(id: string, callback: iobJS.GetStateCallback<T>): void;
|
|
1483
|
+
function getState<T extends ioBroker.StateValue = any>(id: string): iobJS.TypedState<T> | iobJS.AbsentState;
|
|
1484
|
+
function getStateAsync<T extends ioBroker.StateValue = any>(id: string): Promise<iobJS.TypedState<T>>;
|
|
1485
|
+
|
|
1486
|
+
/**
|
|
1487
|
+
* Checks if the state with the given ID exists
|
|
1488
|
+
*/
|
|
1489
|
+
function existsState(id: string, callback: iobJS.ExistsStateCallback): void;
|
|
1490
|
+
function existsState(id: string): boolean;
|
|
1491
|
+
function existsStateAsync(id: string): Promise<boolean>;
|
|
1492
|
+
/**
|
|
1493
|
+
* Checks if the object with the given ID exists
|
|
1494
|
+
*/
|
|
1495
|
+
function existsObject(id: string): boolean;
|
|
1496
|
+
function existsObjectAsync(id: string): Promise<boolean>;
|
|
1497
|
+
|
|
1498
|
+
/**
|
|
1499
|
+
* Returns the IDs of the states with the given name
|
|
1500
|
+
*
|
|
1501
|
+
* @param name Name of the state
|
|
1502
|
+
* @param forceArray (optional) Ensures that the return value is always an array, even if only one ID was found.
|
|
1503
|
+
*/
|
|
1504
|
+
function getIdByName(name: string, forceArray?: boolean): string | string[];
|
|
1505
|
+
|
|
1506
|
+
/**
|
|
1507
|
+
* Reads an object from the object db.
|
|
1508
|
+
*
|
|
1509
|
+
* @param id Object ID
|
|
1510
|
+
* @param enumName Which enum should be included in the returned object. `true` to return all enums.
|
|
1511
|
+
*/
|
|
1512
|
+
function getObject<T extends string>(id: T, enumName?: string | true): iobJS.ObjectIdToObjectType<T, 'read'>;
|
|
1513
|
+
function getObject<T extends string>(id: T, callback: iobJS.GetObjectCallback<T>): void;
|
|
1514
|
+
function getObject<T extends string>(id: T, enumName: string | true, callback: iobJS.GetObjectCallback<T>): void;
|
|
1515
|
+
function getObjectAsync<T extends string>(id: T, enumName?: string | true): iobJS.GetObjectPromise<T>;
|
|
1516
|
+
|
|
1517
|
+
/** Creates or overwrites an object in the object db */
|
|
1518
|
+
function setObject(id: string, obj: iobJS.SettableObject, callback?: iobJS.SetObjectCallback): void;
|
|
1519
|
+
function setObjectAsync(id: string, obj: iobJS.SettableObject): iobJS.SetObjectPromise;
|
|
1520
|
+
/** Extend an object and create it if it might not exist */
|
|
1521
|
+
function extendObject(id: string, objPart: iobJS.PartialObject, callback?: iobJS.SetObjectCallback): void;
|
|
1522
|
+
function extendObjectAsync(id: string, objPart: iobJS.PartialObject): iobJS.SetObjectPromise;
|
|
1523
|
+
|
|
1524
|
+
/** Deletes an object in the object db */
|
|
1525
|
+
function deleteObject(id: string, callback?: ErrorCallback): void;
|
|
1526
|
+
function deleteObject(id: string, recursive: boolean, callback?: ErrorCallback): void;
|
|
1527
|
+
function deleteObjectAsync(id: string, recursive?: boolean): Promise<void>;
|
|
1528
|
+
|
|
1529
|
+
function getEnums(enumName?: string): { id: string; members: string[]; name: ioBroker.StringOrTranslated }[];
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* Creates a state and the corresponding object under the JavaScript namespace.
|
|
1533
|
+
*
|
|
1534
|
+
* @param name The name of the state without the namespace
|
|
1535
|
+
* @param initValue (optional) Initial value of the state
|
|
1536
|
+
* @param forceCreation (optional) Override the state if it already exists
|
|
1537
|
+
* @param common (optional) Common part of the state object
|
|
1538
|
+
* @param native (optional) Native part of the state object
|
|
1539
|
+
* @param callback (optional) Called after the state was created
|
|
1540
|
+
*/
|
|
1541
|
+
function createState(
|
|
1542
|
+
name: string,
|
|
1543
|
+
initValue: ioBroker.StateValue,
|
|
1544
|
+
forceCreation: boolean,
|
|
1545
|
+
common: Partial<iobJS.StateCommon>,
|
|
1546
|
+
native: any,
|
|
1547
|
+
callback?: iobJS.SetStateCallback,
|
|
1548
|
+
): void;
|
|
1549
|
+
function createState(
|
|
1550
|
+
name: string,
|
|
1551
|
+
initValue: ioBroker.StateValue,
|
|
1552
|
+
forceCreation: boolean,
|
|
1553
|
+
common: Partial<iobJS.StateCommon>,
|
|
1554
|
+
callback?: iobJS.SetStateCallback,
|
|
1555
|
+
): void;
|
|
1556
|
+
function createState(
|
|
1557
|
+
name: string,
|
|
1558
|
+
initValue: ioBroker.StateValue,
|
|
1559
|
+
forceCreation: boolean,
|
|
1560
|
+
callback?: iobJS.SetStateCallback,
|
|
1561
|
+
): void;
|
|
1562
|
+
function createState(name: string, callback?: iobJS.SetStateCallback): void;
|
|
1563
|
+
function createState(name: string, initValue: ioBroker.StateValue, callback?: iobJS.SetStateCallback): void;
|
|
1564
|
+
|
|
1565
|
+
function createState(name: string, common: Partial<iobJS.StateCommon>, callback?: iobJS.SetStateCallback): void;
|
|
1566
|
+
function createState(
|
|
1567
|
+
name: string,
|
|
1568
|
+
initValue: ioBroker.StateValue,
|
|
1569
|
+
common: Partial<iobJS.StateCommon>,
|
|
1570
|
+
callback?: iobJS.SetStateCallback,
|
|
1571
|
+
): void;
|
|
1572
|
+
function createState(
|
|
1573
|
+
name: string,
|
|
1574
|
+
common: Partial<iobJS.StateCommon>,
|
|
1575
|
+
native: any,
|
|
1576
|
+
callback?: iobJS.SetStateCallback,
|
|
1577
|
+
): void;
|
|
1578
|
+
function createState(
|
|
1579
|
+
name: string,
|
|
1580
|
+
initValue: ioBroker.StateValue,
|
|
1581
|
+
common: Partial<iobJS.StateCommon>,
|
|
1582
|
+
native: any,
|
|
1583
|
+
callback?: iobJS.SetStateCallback,
|
|
1584
|
+
): void;
|
|
1585
|
+
|
|
1586
|
+
function createStateAsync(
|
|
1587
|
+
name: string,
|
|
1588
|
+
initValue?: ioBroker.StateValue,
|
|
1589
|
+
forceCreation?: boolean,
|
|
1590
|
+
common?: Partial<iobJS.StateCommon>,
|
|
1591
|
+
native?: any,
|
|
1592
|
+
): iobJS.SetStatePromise;
|
|
1593
|
+
function createStateAsync(name: string, common: Partial<iobJS.StateCommon>): iobJS.SetStatePromise;
|
|
1594
|
+
function createStateAsync(name: string, common: Partial<iobJS.StateCommon>, native?: any): iobJS.SetStatePromise;
|
|
1595
|
+
function createStateAsync(
|
|
1596
|
+
name: string,
|
|
1597
|
+
initValue: ioBroker.StateValue,
|
|
1598
|
+
common: Partial<iobJS.StateCommon>,
|
|
1599
|
+
): iobJS.SetStatePromise;
|
|
1600
|
+
function createStateAsync(
|
|
1601
|
+
name: string,
|
|
1602
|
+
initValue: ioBroker.StateValue,
|
|
1603
|
+
common: Partial<iobJS.StateCommon>,
|
|
1604
|
+
native?: any,
|
|
1605
|
+
): iobJS.SetStatePromise;
|
|
1606
|
+
|
|
1607
|
+
function createAlias(name: string, alias: string | iobJS.StateCommonAlias, callback?: iobJS.SetStateCallback): void;
|
|
1608
|
+
function createAlias(
|
|
1609
|
+
name: string,
|
|
1610
|
+
alias: string | iobJS.StateCommonAlias,
|
|
1611
|
+
forceCreation: boolean,
|
|
1612
|
+
callback?: iobJS.SetStateCallback,
|
|
1613
|
+
): void;
|
|
1614
|
+
function createAlias(
|
|
1615
|
+
name: string,
|
|
1616
|
+
alias: string | iobJS.StateCommonAlias,
|
|
1617
|
+
forceCreation: boolean,
|
|
1618
|
+
common: Partial<iobJS.StateCommon>,
|
|
1619
|
+
callback?: iobJS.SetStateCallback,
|
|
1620
|
+
): void;
|
|
1621
|
+
function createAlias(
|
|
1622
|
+
name: string,
|
|
1623
|
+
alias: string | iobJS.StateCommonAlias,
|
|
1624
|
+
forceCreation: boolean,
|
|
1625
|
+
common: Partial<iobJS.StateCommon>,
|
|
1626
|
+
native: any,
|
|
1627
|
+
callback?: iobJS.SetStateCallback,
|
|
1628
|
+
): void;
|
|
1629
|
+
function createAlias(
|
|
1630
|
+
name: string,
|
|
1631
|
+
alias: string | iobJS.StateCommonAlias,
|
|
1632
|
+
common: Partial<iobJS.StateCommon>,
|
|
1633
|
+
callback?: iobJS.SetStateCallback,
|
|
1634
|
+
): void;
|
|
1635
|
+
function createAlias(
|
|
1636
|
+
name: string,
|
|
1637
|
+
alias: string | iobJS.StateCommonAlias,
|
|
1638
|
+
common: Partial<iobJS.StateCommon>,
|
|
1639
|
+
native: any,
|
|
1640
|
+
callback?: iobJS.SetStateCallback,
|
|
1641
|
+
): void;
|
|
1642
|
+
|
|
1643
|
+
function createAliasAsync(
|
|
1644
|
+
name: string,
|
|
1645
|
+
alias: string | iobJS.StateCommonAlias,
|
|
1646
|
+
forceCreation?: boolean,
|
|
1647
|
+
common?: Partial<iobJS.StateCommon>,
|
|
1648
|
+
native?: any,
|
|
1649
|
+
): iobJS.SetStatePromise;
|
|
1650
|
+
function createAliasAsync(
|
|
1651
|
+
name: string,
|
|
1652
|
+
alias: string | iobJS.StateCommonAlias,
|
|
1653
|
+
common: Partial<iobJS.StateCommon>,
|
|
1654
|
+
): iobJS.SetStatePromise;
|
|
1655
|
+
function createAliasAsync(
|
|
1656
|
+
name: string,
|
|
1657
|
+
alias: string | iobJS.StateCommonAlias,
|
|
1658
|
+
common: Partial<iobJS.StateCommon>,
|
|
1659
|
+
native?: any,
|
|
1660
|
+
): iobJS.SetStatePromise;
|
|
1661
|
+
|
|
1662
|
+
/**
|
|
1663
|
+
* Deletes the state with the given ID
|
|
1664
|
+
*
|
|
1665
|
+
* @param callback (optional) Is called after the state was deleted (or not).
|
|
1666
|
+
*/
|
|
1667
|
+
function deleteState(id: string, callback?: GenericCallback<boolean>): void;
|
|
1668
|
+
function deleteStateAsync(id: string): Promise<boolean>;
|
|
1669
|
+
|
|
1670
|
+
/**
|
|
1671
|
+
* Sends a message to a specific instance or all instances of some specific adapter.
|
|
1672
|
+
*
|
|
1673
|
+
* @param instanceName The instance to send this message to.
|
|
1674
|
+
* If the ID of an instance is given (e.g. "admin.0"), only this instance will receive the message.
|
|
1675
|
+
* If the name of an adapter is given (e.g. "admin"), all instances of this adapter will receive it.
|
|
1676
|
+
* @param command (optional) Command name of the target instance. Default: "send"
|
|
1677
|
+
* @param message The message (e.g., params) to send.
|
|
1678
|
+
*/
|
|
1679
|
+
function sendTo(
|
|
1680
|
+
instanceName: string,
|
|
1681
|
+
command: string,
|
|
1682
|
+
message: string | object,
|
|
1683
|
+
options: iobJS.SendToOptions,
|
|
1684
|
+
callback?: iobJS.MessageCallback | iobJS.MessageCallbackInfo,
|
|
1685
|
+
): void;
|
|
1686
|
+
function sendTo(
|
|
1687
|
+
instanceName: string,
|
|
1688
|
+
command: string,
|
|
1689
|
+
message: string | object,
|
|
1690
|
+
callback?: iobJS.MessageCallback | iobJS.MessageCallbackInfo,
|
|
1691
|
+
): void;
|
|
1692
|
+
function sendTo(
|
|
1693
|
+
instanceName: string,
|
|
1694
|
+
message: string | object,
|
|
1695
|
+
callback?: iobJS.MessageCallback | iobJS.MessageCallbackInfo,
|
|
1696
|
+
): void;
|
|
1697
|
+
function sendToAsync(
|
|
1698
|
+
instanceName: string,
|
|
1699
|
+
message: string | object,
|
|
1700
|
+
): Promise<iobJS.MessageCallback | iobJS.MessageCallbackInfo>;
|
|
1701
|
+
function sendToAsync(
|
|
1702
|
+
instanceName: string,
|
|
1703
|
+
command: string,
|
|
1704
|
+
message: string | object,
|
|
1705
|
+
): Promise<iobJS.MessageCallback | iobJS.MessageCallbackInfo>;
|
|
1706
|
+
function sendToAsync(
|
|
1707
|
+
instanceName: string,
|
|
1708
|
+
command: string,
|
|
1709
|
+
message: string | object,
|
|
1710
|
+
options: iobJS.SendToOptions,
|
|
1711
|
+
): Promise<iobJS.MessageCallback | iobJS.MessageCallbackInfo>;
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* Sends a message to a specific instance or all instances of some specific adapter.
|
|
1715
|
+
*
|
|
1716
|
+
* @param host Host name.
|
|
1717
|
+
* @param command Command name for the target host.
|
|
1718
|
+
* @param message The message (e.g., params) to send.
|
|
1719
|
+
*/
|
|
1720
|
+
function sendToHost(
|
|
1721
|
+
host: string,
|
|
1722
|
+
command: string,
|
|
1723
|
+
message: string | object,
|
|
1724
|
+
callback?: iobJS.MessageCallback | iobJS.MessageCallbackInfo,
|
|
1725
|
+
): void;
|
|
1726
|
+
function sendToHostAsync(
|
|
1727
|
+
host: string,
|
|
1728
|
+
command: string,
|
|
1729
|
+
message: string | object,
|
|
1730
|
+
): Promise<iobJS.MessageCallback | iobJS.MessageCallbackInfo>;
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* Creates a new notification (visible in admin adapter)
|
|
1734
|
+
*
|
|
1735
|
+
* @param msg Message text
|
|
1736
|
+
*/
|
|
1737
|
+
function registerNotification(msg: string): void;
|
|
1738
|
+
function registerNotification(msg: string, isAlert: boolean): void;
|
|
1739
|
+
|
|
1740
|
+
function setTimeout(callback: (args: void) => void, ms?: number): NodeJS.Timeout;
|
|
1741
|
+
function clearTimeout(timeoutId: NodeJS.Timeout | string | number | undefined): void;
|
|
1742
|
+
function setInterval(callback: (args: void) => void, ms?: number): NodeJS.Timeout;
|
|
1743
|
+
function clearInterval(intervalId: NodeJS.Timeout | string | number | undefined): void;
|
|
1744
|
+
function setImmediate(callback: (args: void) => void): NodeJS.Immediate;
|
|
1745
|
+
|
|
1746
|
+
type CompareTimeOperations = 'between' | 'not between' | '>' | '>=' | '<' | '<=' | '==' | '<>';
|
|
1747
|
+
|
|
1748
|
+
/**
|
|
1749
|
+
* Compares two or more times
|
|
1750
|
+
*
|
|
1751
|
+
* @param timeToCompare - The time to compare with startTime and/or endTime. If none is given, the current time is used
|
|
1752
|
+
*/
|
|
1753
|
+
function compareTime(
|
|
1754
|
+
startTime: string | number | Date | iobJS.AstroDate,
|
|
1755
|
+
endTime: string | number | Date | iobJS.AstroDate,
|
|
1756
|
+
operation: CompareTimeOperations,
|
|
1757
|
+
timeToCompare?: string | number | Date | iobJS.AstroDate,
|
|
1758
|
+
): boolean;
|
|
1759
|
+
|
|
1760
|
+
/** Sets up a callback which is called when the script stops */
|
|
1761
|
+
function onStop(callback: (cb?: EmptyCallback) => void, timeout?: number): void;
|
|
1762
|
+
|
|
1763
|
+
function formatValue(value: number | string, format?: any): string;
|
|
1764
|
+
function formatValue(value: number | string, decimals: number, format?: any): string;
|
|
1765
|
+
function formatDate(dateObj: string | Date | number, format: string, language?: string): string;
|
|
1766
|
+
function formatDate(
|
|
1767
|
+
dateObj: string | Date | number,
|
|
1768
|
+
isDuration: boolean | string,
|
|
1769
|
+
format: string,
|
|
1770
|
+
language?: string,
|
|
1771
|
+
): string;
|
|
1772
|
+
function formatTimeDiff(diff: number): string;
|
|
1773
|
+
function formatTimeDiff(diff: number, format: string): string;
|
|
1774
|
+
|
|
1775
|
+
function getDateObject(date?: number | string | Date): Date;
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* Writes a file.
|
|
1779
|
+
*
|
|
1780
|
+
* @param id Name of the root directory. This should be the adapter instance, e.g. "admin.0"
|
|
1781
|
+
* @param name File name
|
|
1782
|
+
* @param data Contents of the file
|
|
1783
|
+
* @param callback Is called when the operation has finished (successfully or not)
|
|
1784
|
+
*/
|
|
1785
|
+
function writeFile(id: string, name: string, data: Buffer | string, callback: ErrorCallback): void;
|
|
1786
|
+
function writeFileAsync(id: string, name: string, data: Buffer | string): Promise<void>;
|
|
1787
|
+
|
|
1788
|
+
/**
|
|
1789
|
+
* Reads a file.
|
|
1790
|
+
*
|
|
1791
|
+
* @param id Name of the root directory. This should be the adapter instance, e.g. "admin.0"
|
|
1792
|
+
* @param name File name
|
|
1793
|
+
* @param callback Is called when the operation has finished (successfully or not)
|
|
1794
|
+
*/
|
|
1795
|
+
function readFile(id: string, name: string, callback: iobJS.ReadFileCallback): void;
|
|
1796
|
+
function readFileAsync(id: string, name: string): iobJS.ReadFilePromise;
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* Deletes a file.
|
|
1800
|
+
*
|
|
1801
|
+
* @param id Name of the root directory. This should be the adapter instance, e.g. "admin.0"
|
|
1802
|
+
* @param name File name
|
|
1803
|
+
* @param callback Is called when the operation has finished (successfully or not)
|
|
1804
|
+
*/
|
|
1805
|
+
function unlink(id: string, name: string, callback: ErrorCallback): void;
|
|
1806
|
+
function unlinkAsync(id: string, name: string): Promise<void>;
|
|
1807
|
+
|
|
1808
|
+
/**
|
|
1809
|
+
* Deletes a file.
|
|
1810
|
+
*
|
|
1811
|
+
* @param id Name of the root directory. This should be the adapter instance, e.g. "admin.0"
|
|
1812
|
+
* @param name File name
|
|
1813
|
+
* @param callback Is called when the operation has finished (successfully or not)
|
|
1814
|
+
*/
|
|
1815
|
+
function delFile(id: string, name: string, callback: ErrorCallback): void;
|
|
1816
|
+
function delFileAsync(id: string, name: string): Promise<void>;
|
|
1817
|
+
|
|
1818
|
+
/**
|
|
1819
|
+
* Renames a file.
|
|
1820
|
+
*
|
|
1821
|
+
* @param id Name of the root directory. This should be the adapter instance, e.g. "admin.0"
|
|
1822
|
+
* @param oldName Current file name
|
|
1823
|
+
* @param newName New file name
|
|
1824
|
+
* @param callback Is called when the operation has finished (successfully or not)
|
|
1825
|
+
*/
|
|
1826
|
+
function rename(id: string, oldName: string, newName: string, callback: ErrorCallback): void;
|
|
1827
|
+
function renameAsync(id: string, oldName: string, newName: string): Promise<void>;
|
|
1828
|
+
|
|
1829
|
+
/**
|
|
1830
|
+
* Renames a file.
|
|
1831
|
+
*
|
|
1832
|
+
* @param id Name of the root directory. This should be the adapter instance, e.g. "admin.0"
|
|
1833
|
+
* @param oldName Current file name
|
|
1834
|
+
* @param newName New file name
|
|
1835
|
+
* @param callback Is called when the operation has finished (successfully or not)
|
|
1836
|
+
*/
|
|
1837
|
+
function renameFile(id: string, oldName: string, newName: string, callback: ErrorCallback): void;
|
|
1838
|
+
function renameFileAsync(id: string, oldName: string, newName: string): Promise<void>;
|
|
1839
|
+
|
|
1840
|
+
function getHistory(instance: any, options: any, callback: any): any;
|
|
1841
|
+
function getHistoryAsync(instance: any, options: any): Promise<any>;
|
|
1842
|
+
|
|
1843
|
+
/**
|
|
1844
|
+
* Starts or restarts a script by name
|
|
1845
|
+
*
|
|
1846
|
+
* @param scriptName (optional) Name of the script. If none is given, the current script is (re)started.
|
|
1847
|
+
*/
|
|
1848
|
+
function runScript(scriptName?: string, callback?: ErrorCallback): boolean;
|
|
1849
|
+
function runScriptAsync(scriptName?: string): Promise<void>;
|
|
1850
|
+
|
|
1851
|
+
/**
|
|
1852
|
+
* Starts or restarts a script by name
|
|
1853
|
+
*
|
|
1854
|
+
* @param scriptName (optional) Name of the script. If none is given, the current script is (re)started.
|
|
1855
|
+
* @param ignoreIfStarted If set to true, running scripts will not be restarted.
|
|
1856
|
+
* @param callback (optional) Is called when the script has finished (successfully or not)
|
|
1857
|
+
*/
|
|
1858
|
+
function startScript(
|
|
1859
|
+
scriptName: string | undefined,
|
|
1860
|
+
ignoreIfStarted: boolean,
|
|
1861
|
+
callback?: GenericCallback<boolean>,
|
|
1862
|
+
): boolean;
|
|
1863
|
+
function startScriptAsync(scriptName?: string, ignoreIfStarted?: boolean): Promise<void>;
|
|
1864
|
+
|
|
1865
|
+
/**
|
|
1866
|
+
* Starts or restarts a script by name
|
|
1867
|
+
*
|
|
1868
|
+
* @param scriptName (optional) Name of the script. If none is given, the current script is (re)started.
|
|
1869
|
+
* @param callback (optional) Is called when the script has finished (successfully or not)
|
|
1870
|
+
*/
|
|
1871
|
+
function startScript(scriptName?: string, callback?: GenericCallback<boolean>): boolean;
|
|
1872
|
+
/**
|
|
1873
|
+
* Stops a script by name
|
|
1874
|
+
*
|
|
1875
|
+
* @param scriptName (optional) Name of the script. If none is given, the current script is stopped.
|
|
1876
|
+
*/
|
|
1877
|
+
function stopScript(scriptName: string | undefined, callback?: GenericCallback<boolean>): boolean;
|
|
1878
|
+
function stopScriptAsync(scriptName?: string): Promise<void>;
|
|
1879
|
+
|
|
1880
|
+
function isScriptActive(scriptName: string): boolean;
|
|
1881
|
+
|
|
1882
|
+
function startInstanceAsync(instanceName: string): Promise<boolean>;
|
|
1883
|
+
function restartInstanceAsync(instanceName: string): Promise<boolean>;
|
|
1884
|
+
function stopInstanceAsync(instanceName: string): Promise<boolean>;
|
|
1885
|
+
|
|
1886
|
+
/** Converts a value to an integer */
|
|
1887
|
+
function toInt(val: any): number;
|
|
1888
|
+
/** Converts a value to a floating point number */
|
|
1889
|
+
function toFloat(val: any): number;
|
|
1890
|
+
/** Converts a value to a boolean */
|
|
1891
|
+
function toBoolean(val: any): boolean;
|
|
1892
|
+
|
|
1893
|
+
/**
|
|
1894
|
+
* Digs in an object for the property value at the given path.
|
|
1895
|
+
*
|
|
1896
|
+
* @param obj The object to dig in
|
|
1897
|
+
* @param path The path of the property to dig for in the given object
|
|
1898
|
+
*/
|
|
1899
|
+
function getAttr(obj: string | Record<string, any>, path: string | string[]): any;
|
|
1900
|
+
|
|
1901
|
+
/**
|
|
1902
|
+
* Sends a message to another script.
|
|
1903
|
+
*
|
|
1904
|
+
* @param target Message name or target object
|
|
1905
|
+
* @param data Any data, that should be sent to message bus
|
|
1906
|
+
* @param options Actually only {timeout: X} is supported as option
|
|
1907
|
+
* @param callback Callback to get the result from other script
|
|
1908
|
+
* @returns ID of the subscription. It could be used for unsubscribing.
|
|
1909
|
+
*/
|
|
1910
|
+
function messageTo(
|
|
1911
|
+
target: iobJS.MessageTarget | string,
|
|
1912
|
+
data: any,
|
|
1913
|
+
options?: any,
|
|
1914
|
+
callback?: SimpleCallback<any>,
|
|
1915
|
+
): iobJS.MessageSubscribeID;
|
|
1916
|
+
function messageToAsync(
|
|
1917
|
+
target: iobJS.MessageTarget | string,
|
|
1918
|
+
data: any,
|
|
1919
|
+
options?: any,
|
|
1920
|
+
): Promise<iobJS.MessageCallback | iobJS.MessageCallbackInfo>;
|
|
1921
|
+
|
|
1922
|
+
/**
|
|
1923
|
+
* Process message from another script.
|
|
1924
|
+
*
|
|
1925
|
+
* @param message Message name
|
|
1926
|
+
* @param callback Callback to send the result to another script
|
|
1927
|
+
*/
|
|
1928
|
+
function onMessage(message: string, callback?: MessageCallback<any>): null | number;
|
|
1929
|
+
|
|
1930
|
+
/**
|
|
1931
|
+
* Unregister onmessage handler
|
|
1932
|
+
*
|
|
1933
|
+
* @param id Message subscription id from onMessage or by message name
|
|
1934
|
+
* @returns true if subscription exists and was deleted.
|
|
1935
|
+
*/
|
|
1936
|
+
function onMessageUnregister(id: iobJS.MessageSubscribeID | string): boolean;
|
|
1937
|
+
|
|
1938
|
+
function jsonataExpression(data: any, expression: string): Promise<any>;
|
|
1939
|
+
|
|
1940
|
+
function onObject(pattern: string, callback: iobJS.ObjectChangeHandler): SubscribeObject | SubscribeObject[] | null;
|
|
1941
|
+
function subscribeObject(
|
|
1942
|
+
pattern: string,
|
|
1943
|
+
callback: iobJS.ObjectChangeHandler,
|
|
1944
|
+
): SubscribeObject | SubscribeObject[] | null;
|
|
1945
|
+
|
|
1946
|
+
function unsubscribeObject(id: string): boolean | boolean[];
|
|
1947
|
+
|
|
1948
|
+
/**
|
|
1949
|
+
* Receives logs of specified severity level in a script.
|
|
1950
|
+
*
|
|
1951
|
+
* @param severity Severity level
|
|
1952
|
+
* @param callback Callback to send the result to another script
|
|
1953
|
+
*/
|
|
1954
|
+
function onLog(severity: iobJS.LogLevel | '*', callback: SimpleCallback<iobJS.LogMessage>): iobJS.LogSubscribeID;
|
|
1955
|
+
|
|
1956
|
+
/**
|
|
1957
|
+
* Unsubscribe log handler.
|
|
1958
|
+
*
|
|
1959
|
+
* @param idOrCallbackOrSeverity Message subscription id from onLog or by callback function
|
|
1960
|
+
* @returns true if subscription exists and was deleted.
|
|
1961
|
+
*/
|
|
1962
|
+
function onLogUnregister(
|
|
1963
|
+
idOrCallbackOrSeverity: iobJS.LogSubscribeID | SimpleCallback<iobJS.LogMessage> | iobJS.LogLevel | '*',
|
|
1964
|
+
): boolean;
|
|
1965
|
+
// TODO: More signatures for other types than number
|
|
1966
|
+
|
|
1967
|
+
/** `await` this method to pause for the given number of milliseconds */
|
|
1968
|
+
function wait(ms: number): Promise<void>;
|
|
1969
|
+
|
|
1970
|
+
/** `await` this method to pause for the given number of milliseconds */
|
|
1971
|
+
function sleep(ms: number): Promise<void>;
|
|
1972
|
+
}
|