iobroker.digitalstrom 2.3.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -1
- package/README.md +806 -35
- package/admin/assets/index.js +682 -0
- package/admin/index.html +45 -0
- package/build/lib/activityCounter.js +82 -0
- package/build/lib/activityCounter.js.map +1 -0
- package/build/lib/configUtils.js +125 -0
- package/build/lib/configUtils.js.map +1 -0
- package/build/lib/constants.js +1285 -0
- package/build/lib/constants.js.map +1 -0
- package/build/lib/dss.js +877 -0
- package/build/lib/dss.js.map +1 -0
- package/build/lib/dssQueue.js +517 -0
- package/build/lib/dssQueue.js.map +1 -0
- package/build/lib/dssSmartHome.js +769 -0
- package/build/lib/dssSmartHome.js.map +1 -0
- package/build/lib/dssSmartHomeSync.js +601 -0
- package/build/lib/dssSmartHomeSync.js.map +1 -0
- package/build/lib/dssStructure.js +3390 -0
- package/build/lib/dssStructure.js.map +1 -0
- package/build/lib/websocket.js +386 -0
- package/build/lib/websocket.js.map +1 -0
- package/build/main.js +2203 -0
- package/build/main.js.map +1 -0
- package/io-package.json +262 -266
- package/package.json +67 -36
- package/admin/admin.d.ts +0 -1
- package/admin/index_m.html +0 -201
- package/admin/style.css +0 -10
- package/admin/words.js +0 -20
- package/img/dss-apartment.png +0 -0
- package/img/dss-devices.png +0 -0
- package/lib/adapter-config.d.ts +0 -16
- package/lib/constants.js +0 -1202
- package/lib/dss.js +0 -193
- package/lib/dssQueue.js +0 -268
- package/lib/dssStructure.js +0 -1662
- package/lib/tools.js +0 -91
- package/main.js +0 -713
package/main.js
DELETED
|
@@ -1,713 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Digitalstrom ioBroker Adapter
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
Rule 5 When applications send a scene command to a set of digitalSTROM-Devices with more than one target device they have to use scene calls directed to a group, splitting into multiple calls to single devices has to be avoided due to latency and statemachine consistency issues.
|
|
9
|
-
|
|
10
|
-
Rule 8 Application processes that do automatic cyclic reads or writes of device parameters are subject to a request limit: at maximum one request per minute and circuit is allowed.
|
|
11
|
-
|
|
12
|
-
Rule 9 Application processes that do automatic cyclic reads of measured values are subject to a request limit: at maximum one request per minute and circuit is allowed.
|
|
13
|
-
|
|
14
|
-
Rule 10 The action command ”Set Output Value” must not be used for other than device configuration purposes.
|
|
15
|
-
|
|
16
|
-
Rule 13 Applications that automatically generate Call Scene action commands (see 6.1.1) must not execute the action commands at a rate faster than one request per second.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const utils = require('@iobroker/adapter-core');
|
|
21
|
-
const ObjectHelper = require('@apollon/iobroker-tools'); // Get common adapter utils
|
|
22
|
-
|
|
23
|
-
const DSS = require('./lib/dss');
|
|
24
|
-
const DSSQueue = require('./lib/dssQueue');
|
|
25
|
-
const DSSStructure = require('./lib/dssStructure');
|
|
26
|
-
const dssConstants = require('./lib/constants');
|
|
27
|
-
|
|
28
|
-
let Sentry;
|
|
29
|
-
let SentryIntegrations;
|
|
30
|
-
|
|
31
|
-
class Digitalstrom extends utils.Adapter {
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @param {Partial<ioBroker.AdapterOptions>} [options={}]
|
|
35
|
-
*/
|
|
36
|
-
constructor(options) {
|
|
37
|
-
super({
|
|
38
|
-
...options,
|
|
39
|
-
name: 'digitalstrom',
|
|
40
|
-
});
|
|
41
|
-
this.on('ready', this.onReady.bind(this));
|
|
42
|
-
this.on('objectChange', this.onObjectChange.bind(this));
|
|
43
|
-
this.on('stateChange', this.onStateChange.bind(this));
|
|
44
|
-
this.on('message', this.onMessage.bind(this));
|
|
45
|
-
this.on('unload', this.onUnload.bind(this));
|
|
46
|
-
|
|
47
|
-
this.objectHelper = ObjectHelper.objectHelper;
|
|
48
|
-
this.objectHelper.init(this);
|
|
49
|
-
this.connected = null;
|
|
50
|
-
|
|
51
|
-
this.dss = null;
|
|
52
|
-
this.dssQueue = null;
|
|
53
|
-
this.dssStruct = null;
|
|
54
|
-
this.lastScenes = {};
|
|
55
|
-
|
|
56
|
-
this.dataPollInterval = 60000;
|
|
57
|
-
this.dataPollTimeout = null;
|
|
58
|
-
|
|
59
|
-
this.restartTimeout = null;
|
|
60
|
-
this.stopping = false;
|
|
61
|
-
|
|
62
|
-
process.on('SIGINT', () => {
|
|
63
|
-
this.stopAdapter();
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
process.on('uncaughtException', (err) => {
|
|
67
|
-
console.log('Exception: ' + err + '/' + err.toString());
|
|
68
|
-
this.log && this.log.warn('Exception: ' + err);
|
|
69
|
-
|
|
70
|
-
this.stopAdapter();
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
initSentry(callback) {
|
|
75
|
-
if (!this.ioPack.common || !this.ioPack.common.plugins || !this.ioPack.common.plugins.sentry) {
|
|
76
|
-
return callback && callback();
|
|
77
|
-
}
|
|
78
|
-
const sentryConfig = this.ioPack.common.plugins.sentry;
|
|
79
|
-
if (!sentryConfig.dsn) {
|
|
80
|
-
this.log.warn('Invalid Sentry definition, no dsn provided. Disable error reporting');
|
|
81
|
-
return callback && callback();
|
|
82
|
-
}
|
|
83
|
-
// Require needed tooling
|
|
84
|
-
Sentry = require('@sentry/node');
|
|
85
|
-
SentryIntegrations = require('@sentry/integrations');
|
|
86
|
-
// By installing source map support, we get the original source
|
|
87
|
-
// locations in error messages
|
|
88
|
-
require('source-map-support').install();
|
|
89
|
-
|
|
90
|
-
let sentryPathWhitelist = [];
|
|
91
|
-
if (sentryConfig.pathWhitelist && Array.isArray(sentryConfig.pathWhitelist)) {
|
|
92
|
-
sentryPathWhitelist = sentryConfig.pathWhitelist;
|
|
93
|
-
}
|
|
94
|
-
if (this.pack.name && !sentryPathWhitelist.includes(this.pack.name)) {
|
|
95
|
-
sentryPathWhitelist.push(this.pack.name);
|
|
96
|
-
}
|
|
97
|
-
let sentryErrorBlacklist = [];
|
|
98
|
-
if (sentryConfig.errorBlacklist && Array.isArray(sentryConfig.errorBlacklist)) {
|
|
99
|
-
sentryErrorBlacklist = sentryConfig.errorBlacklist;
|
|
100
|
-
}
|
|
101
|
-
if (!sentryErrorBlacklist.includes('SyntaxError')) {
|
|
102
|
-
sentryErrorBlacklist.push('SyntaxError');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
Sentry.init({
|
|
106
|
-
release: this.pack.name + '@' + this.pack.version,
|
|
107
|
-
dsn: sentryConfig.dsn,
|
|
108
|
-
integrations: [
|
|
109
|
-
new SentryIntegrations.Dedupe()
|
|
110
|
-
]
|
|
111
|
-
});
|
|
112
|
-
Sentry.configureScope(scope => {
|
|
113
|
-
scope.setTag('version', this.common.installedVersion || this.common.version);
|
|
114
|
-
if (this.common.installedFrom) {
|
|
115
|
-
scope.setTag('installedFrom', this.common.installedFrom);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
scope.setTag('installedFrom', this.common.installedVersion || this.common.version);
|
|
119
|
-
}
|
|
120
|
-
scope.addEventProcessor(function(event, hint) {
|
|
121
|
-
// Try to filter out some events
|
|
122
|
-
if (event.exception && event.exception.values && event.exception.values[0]) {
|
|
123
|
-
const eventData = event.exception.values[0];
|
|
124
|
-
// if error type is one from blacklist we ignore this error
|
|
125
|
-
if (eventData.type && sentryErrorBlacklist.includes(eventData.type)) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
if (eventData.stacktrace && eventData.stacktrace.frames && Array.isArray(eventData.stacktrace.frames) && eventData.stacktrace.frames.length) {
|
|
129
|
-
// if last exception frame is from an nodejs internal method we ignore this error
|
|
130
|
-
if (eventData.stacktrace.frames[eventData.stacktrace.frames.length - 1].filename && (eventData.stacktrace.frames[eventData.stacktrace.frames.length - 1].filename.startsWith('internal/') || eventData.stacktrace.frames[eventData.stacktrace.frames.length - 1].filename.startsWith('Module.'))) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
// Check if any entry is whitelisted from pathWhitelist
|
|
134
|
-
const whitelisted = eventData.stacktrace.frames.find(frame => {
|
|
135
|
-
if (frame.function && frame.function.startsWith('Module.')) {
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
if (frame.filename && frame.filename.startsWith('internal/')) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
if (frame.filename && !sentryPathWhitelist.find(path => path && path.length && frame.filename.includes(path))) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
return true;
|
|
145
|
-
});
|
|
146
|
-
if (!whitelisted) {
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return event;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
this.getForeignObject('system.config', (err, obj) => {
|
|
156
|
-
if (obj && obj.common && obj.common.diag) {
|
|
157
|
-
this.getForeignObject('system.meta.uuid', (err, obj) => {
|
|
158
|
-
// create uuid
|
|
159
|
-
if (!err && obj) {
|
|
160
|
-
Sentry.configureScope(scope => {
|
|
161
|
-
scope.setUser({
|
|
162
|
-
id: obj.native.uuid
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
callback && callback();
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
callback && callback();
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Is called when databases are connected and adapter received configuration.
|
|
178
|
-
*/
|
|
179
|
-
async onReady() {
|
|
180
|
-
if (this.supportsFeature && this.supportsFeature('PLUGINS')) {
|
|
181
|
-
this.main();
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
this.initSentry(() => this.main());
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Is called when adapter shuts down - callback has to be called under any circumstances!
|
|
190
|
-
* @param {() => void} callback
|
|
191
|
-
*/
|
|
192
|
-
onUnload(callback) {
|
|
193
|
-
try {
|
|
194
|
-
this.stopAdapter(callback);
|
|
195
|
-
} catch (e) {
|
|
196
|
-
callback();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Is called if a subscribed object changes
|
|
202
|
-
* @param {string} id
|
|
203
|
-
* @param {ioBroker.Object | null | undefined} obj
|
|
204
|
-
*/
|
|
205
|
-
onObjectChange(id, obj) {
|
|
206
|
-
if (obj) {
|
|
207
|
-
// The object was changed
|
|
208
|
-
this.log.debug(`object ${id} changed: ${JSON.stringify(obj)}`);
|
|
209
|
-
} else {
|
|
210
|
-
// The object was deleted
|
|
211
|
-
this.log.debug(`object ${id} deleted`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Is called if a subscribed state changes
|
|
217
|
-
* @param {string} id
|
|
218
|
-
* @param {ioBroker.State | null | undefined} state
|
|
219
|
-
*/
|
|
220
|
-
onStateChange(id, state) {
|
|
221
|
-
if (state) {
|
|
222
|
-
// The state was changed
|
|
223
|
-
this.log.debug(`state ${id} changed: ${state.val} (ack = ${state.ack})`);
|
|
224
|
-
|
|
225
|
-
this.objectHelper.handleStateChange(id, state);
|
|
226
|
-
} else {
|
|
227
|
-
// The state was deleted
|
|
228
|
-
this.log.debug(`state ${id} deleted`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Some message was sent to this instance over message box. Used by email, pushover, text2speech, ...
|
|
234
|
-
* Using this method requires "common.message" property to be set to true in io-package.json
|
|
235
|
-
* @param {ioBroker.Message} obj
|
|
236
|
-
*/
|
|
237
|
-
onMessage(obj) {
|
|
238
|
-
if (typeof obj === 'object' && obj.message) {
|
|
239
|
-
if (obj.command === 'createAppToken') {
|
|
240
|
-
if (!obj.callback) return;
|
|
241
|
-
// e.g. send email or pushover or whatever
|
|
242
|
-
this.log.info('Try to retrieve AppToken for host ' + obj.message.host + ' and username ' + obj.message.username);
|
|
243
|
-
|
|
244
|
-
const tokenConnection = new DSS({
|
|
245
|
-
host: obj.message.host,
|
|
246
|
-
logger: {
|
|
247
|
-
silly: this.log.silly.bind(this),
|
|
248
|
-
debug: this.log.debug.bind(this),
|
|
249
|
-
info: this.log.info.bind(this),
|
|
250
|
-
warn: this.log.warn.bind(this),
|
|
251
|
-
error: this.log.error.bind(this)
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
tokenConnection.createAppTokenAsync(obj.message.username, obj.message.password).then((appToken) => {
|
|
256
|
-
this.log.info('Return AppToken for host ' + obj.message.host + ' and username ' + obj.message.username + ': ' + appToken);
|
|
257
|
-
this.sendTo(obj.from, obj.command, {appToken}, obj.callback);
|
|
258
|
-
}, (error) => {
|
|
259
|
-
this.log.warn('Error while retrieving AppToken for host ' + obj.message.host + ' and username ' + obj.message.username + ': ' + error);
|
|
260
|
-
this.sendTo(obj.from, obj.command, {error}, obj.callback);
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
stopAdapter(callback) {
|
|
267
|
-
if (this.stopping) return;
|
|
268
|
-
this.stopping = true;
|
|
269
|
-
this.log && this.log.info('stopping ... ' + Date.now());
|
|
270
|
-
this.setConnected(false);
|
|
271
|
-
|
|
272
|
-
if (this.dataPollTimeout) {
|
|
273
|
-
clearTimeout(this.dataPollTimeout);
|
|
274
|
-
this.dataPollTimeout = null;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// remove all queue entries and end timers
|
|
278
|
-
this.dssQueue && this.dssQueue.clearQueues();
|
|
279
|
-
|
|
280
|
-
// unsubscribe to all events
|
|
281
|
-
if (this.dss) {
|
|
282
|
-
this.dss.unsubscribeAllEvents((time) => {
|
|
283
|
-
this.log && this.log.info('cleaned everything up... ' + time);
|
|
284
|
-
callback && callback();
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
callback && callback();
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
restartAdapter(timeout) {
|
|
293
|
-
if (this.restartTimeout) return;
|
|
294
|
-
this.restartTimeout = setTimeout(() => {
|
|
295
|
-
this.terminate ? this.terminate(-100) : process.exit(-100);
|
|
296
|
-
}, timeout || 1000);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
setConnected(isConnected) {
|
|
300
|
-
if (this.connected !== isConnected) {
|
|
301
|
-
this.connected = isConnected;
|
|
302
|
-
this.setState('info.connection', this.connected, true);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
main() {
|
|
307
|
-
// Reset the connection indicator during startup
|
|
308
|
-
this.setConnected(false);
|
|
309
|
-
|
|
310
|
-
if (!this.config.host || !this.config.appToken) {
|
|
311
|
-
this.log.warn('Please open Admin page for this adapter to set the host and create an App Token.');
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (this.config.usePresetValues === undefined) {
|
|
315
|
-
this.config.usePresetValues = true;
|
|
316
|
-
}
|
|
317
|
-
this.dss = new DSS({
|
|
318
|
-
host: this.config.host,
|
|
319
|
-
appToken: this.config.appToken,
|
|
320
|
-
logger: {
|
|
321
|
-
silly: this.log.silly.bind(this),
|
|
322
|
-
debug: this.log.debug.bind(this),
|
|
323
|
-
info: this.log.info.bind(this),
|
|
324
|
-
warn: this.log.warn.bind(this),
|
|
325
|
-
error: this.log.error.bind(this)
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
this.dssQueue = new DSSQueue({
|
|
329
|
-
logger: {
|
|
330
|
-
silly: this.log.silly.bind(this),
|
|
331
|
-
debug: this.log.debug.bind(this),
|
|
332
|
-
info: this.log.info.bind(this),
|
|
333
|
-
warn: this.log.warn.bind(this),
|
|
334
|
-
error: this.log.error.bind(this)
|
|
335
|
-
},
|
|
336
|
-
dss: this.dss
|
|
337
|
-
});
|
|
338
|
-
this.dssStruct = new DSSStructure({
|
|
339
|
-
dss: this.dss,
|
|
340
|
-
dssQueue: this.dssQueue,
|
|
341
|
-
adapter: this
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
if (this.dataPollInterval !== 0) {
|
|
345
|
-
this.dataPollInterval = (this.config.dataPollInterval * 1000) || this.dataPollInterval;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
this.dss.requestAsync('apartment', 'getName').then((dssName) => {
|
|
349
|
-
this.log.debug('getName: ' + JSON.stringify(dssName));
|
|
350
|
-
|
|
351
|
-
this.objectHelper.loadExistingObjects(() => {
|
|
352
|
-
|
|
353
|
-
this.initializeDSSData(err => {
|
|
354
|
-
if (err) {
|
|
355
|
-
this.log.warn('Error while initializing Data: ' + err);
|
|
356
|
-
this.restartAdapter(60000);
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
this.registerObjects();
|
|
361
|
-
this.objectHelper.processObjectQueue(() => {
|
|
362
|
-
this.setInitialValues(() => {
|
|
363
|
-
this.lastScenes = this.dssStruct.initialScenes;
|
|
364
|
-
setTimeout(() => {
|
|
365
|
-
this.initializeSubscriptions(() => {
|
|
366
|
-
this.subscribeStates('*');
|
|
367
|
-
this.setConnected(true);
|
|
368
|
-
this.log.info('Subscribed to states ...');
|
|
369
|
-
|
|
370
|
-
this.startDataPolling();
|
|
371
|
-
|
|
372
|
-
this.clearAdditionalObjects();
|
|
373
|
-
});
|
|
374
|
-
}, 2000);
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
}, (err) => {
|
|
381
|
-
this.log.error('Error while checking DSS connection (getName):' + JSON.stringify(err));
|
|
382
|
-
this.log.error('Please check the host and that the host is reachable and check the settings please! Adapter restarts in 5 minutes');
|
|
383
|
-
this.restartAdapter(300000);
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
initializeDSSData(callback) {
|
|
388
|
-
this.dss.requestAsync('system', 'version').then((dssVersion) => {
|
|
389
|
-
this.log.debug('version: ' + JSON.stringify(dssVersion));
|
|
390
|
-
|
|
391
|
-
this.dssStruct.init((err) => {
|
|
392
|
-
if (err) {
|
|
393
|
-
return void (callback && callback(err));
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
callback && callback(null);
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
}, (err) => {
|
|
400
|
-
this.log.error('Error getVersion:' + JSON.stringify(err));
|
|
401
|
-
callback && callback(err);
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
startDataPolling(fromTimeout) {
|
|
406
|
-
if (this.dataPollTimeout) {
|
|
407
|
-
!fromTimeout && clearTimeout(this.dataPollTimeout);
|
|
408
|
-
this.dataPollTimeout = null;
|
|
409
|
-
}
|
|
410
|
-
if (this.dataPollInterval === 0) {
|
|
411
|
-
this.log.info('Data polling deactivated.');
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
this.dssStruct.updateMeterData(() => {
|
|
415
|
-
this.dataPollTimeout = setTimeout(() => this.startDataPolling(true), this.dataPollInterval);
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
initializeSubscriptions(callback) {
|
|
420
|
-
const eventNames = Object.keys(dssConstants.availableEvents).filter(name => dssConstants.availableEvents[name]);
|
|
421
|
-
this.dss && this.dss.subscribeEvents(eventNames, errs => {
|
|
422
|
-
if (errs && Array.isArray(errs)) {
|
|
423
|
-
this.log.warn('Error to subscribe to ' + errs.length + 'Events. See the following log lines.');
|
|
424
|
-
errs.forEach((err, idx) => this.log.warn(idx + ': ' + err));
|
|
425
|
-
this.restartAdapter(30000);
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
this.log.debug('Successfully subscribed to ' + eventNames.length + ' Events');
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
this.dss.on('deviceSensorValue', data => {
|
|
432
|
-
this.eventLog(data.name, data, true);
|
|
433
|
-
if (!data.source || !data.source.isDevice || data.properties.sensorValueFloat === undefined) {
|
|
434
|
-
this.log.info('--INVALID ' + JSON.stringify(data));
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
const sourceDeviceId = this.dssStruct.stateMap[data.source.dSUID + '.sensors.' + data.properties.sensorIndex];
|
|
438
|
-
if (!sourceDeviceId) {
|
|
439
|
-
this.log.info('INVALID Device Sensor update');
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
this.setState(sourceDeviceId, parseFloat(data.properties.sensorValueFloat), true);
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
this.dss.on('deviceBinaryInputEvent', data => {
|
|
446
|
-
this.eventLog(data.name, data, true);
|
|
447
|
-
if (!data.source || !data.source.isDevice || data.properties.inputType === undefined) {
|
|
448
|
-
this.log.info('--INVALID ' + JSON.stringify(data));
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
const sourceDeviceId = this.dssStruct.stateMap[data.source.dSUID + '.binaryInputs.' + data.properties.inputIndex];
|
|
452
|
-
if (!sourceDeviceId) {
|
|
453
|
-
this.log.info('INVALID Device Binary input event');
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
this.setState(sourceDeviceId, parseInt(data.properties.inputState, 10) + 1, true);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
const handleStateChange = (data) => {
|
|
460
|
-
this.eventLog(data.name, data, true);
|
|
461
|
-
if (!data.properties || !data.properties.statename) {
|
|
462
|
-
this.log.info('--INVALID ' + JSON.stringify(data));
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
const sourceDeviceId = this.dssStruct.stateMap[data.properties.statename];
|
|
466
|
-
if (!sourceDeviceId) {
|
|
467
|
-
this.log.info('Unhandled State Change: ' + data.properties.statename);
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
let stateValue = data.properties.state;
|
|
471
|
-
if (this.dssStruct.dssObjects[sourceDeviceId] && this.dssStruct.dssObjects[sourceDeviceId].native) {
|
|
472
|
-
if (this.dssStruct.dssObjects[sourceDeviceId].native.valueTrue !== undefined && stateValue === this.dssStruct.dssObjects[sourceDeviceId].native.valueTrue) {
|
|
473
|
-
stateValue = true;
|
|
474
|
-
}
|
|
475
|
-
else if (this.dssStruct.dssObjects[sourceDeviceId].native.valueFalse !== undefined && stateValue === this.dssStruct.dssObjects[sourceDeviceId].native.valueFalse) {
|
|
476
|
-
stateValue = false;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
this.setState(sourceDeviceId, stateValue, true);
|
|
480
|
-
}
|
|
481
|
-
this.dss.on('stateChange', handleStateChange);
|
|
482
|
-
this.dss.on('addonStateChange', handleStateChange);
|
|
483
|
-
|
|
484
|
-
this.dss.on('buttonClick', data => {
|
|
485
|
-
this.eventLog(data.name, data, true);
|
|
486
|
-
if (!data.source || !data.source.isDevice) {
|
|
487
|
-
this.log.info('--INVALID ' + JSON.stringify(data));
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
const buttonIndex = data.properties.buttonIndex ? data.properties.buttonIndex - 1 : 0;
|
|
491
|
-
if (!this.dssStruct.stateMap[data.source.dSUID + '.' + buttonIndex + '.button']) {
|
|
492
|
-
this.log.info('INVALID Button click');
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
this.setState(this.dssStruct.stateMap[data.source.dSUID + '.' + buttonIndex + '.button'], true, true);
|
|
496
|
-
this.setState(this.dssStruct.stateMap[data.source.dSUID + '.' + buttonIndex + '.buttonClickType'], data.properties.clickType || -1, true);
|
|
497
|
-
this.setState(this.dssStruct.stateMap[data.source.dSUID + '.' + buttonIndex + '.buttonHoldCount'], data.properties.holdCount || 0, true);
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
this.dss.on('zoneSensorValue', data => {
|
|
501
|
-
this.eventLog(data.name, data, true);
|
|
502
|
-
if (!data.source || !data.properties || !data.properties.sensorType || data.properties.sensorValueFloat === undefined) {
|
|
503
|
-
this.log.info('--INVALID ' + JSON.stringify(data));
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
let sourceDeviceId = this.dssStruct.stateMap[data.source.zoneID + '.sensors.' + data.properties.sensorType];
|
|
507
|
-
if (!sourceDeviceId && data.properties.sensorType === 60) {
|
|
508
|
-
sourceDeviceId = this.dssStruct.stateMap['0.sensors.60'];
|
|
509
|
-
}
|
|
510
|
-
if (!sourceDeviceId) {
|
|
511
|
-
this.log.info('INVALID Zone Sensor update: ' + data.source.zoneID + '.sensors.' + data.properties.sensorType);
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
this.setState(sourceDeviceId, data.properties.sensorValueFloat, true);
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
const handleScene = (data, value, forwarded) => {
|
|
518
|
-
this.eventLog(data.name + (forwarded ? ' (forwarded)' : ''), data, true);
|
|
519
|
-
if (!data.source) {
|
|
520
|
-
this.log.info('--INVALID ' + JSON.stringify(data));
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
let sourceDeviceId;
|
|
524
|
-
let lastSourceDeviceId;
|
|
525
|
-
|
|
526
|
-
if (data.source.isDevice) {
|
|
527
|
-
sourceDeviceId = this.dssStruct.stateMap[data.source.dSUID + '.scenes.' + data.properties.sceneID];
|
|
528
|
-
if (this.lastScenes[data.source.dSUID] !== undefined) {
|
|
529
|
-
lastSourceDeviceId = this.dssStruct.stateMap[data.source.dSUID + '.scenes.' + this.lastScenes[data.source.dSUID]];
|
|
530
|
-
}
|
|
531
|
-
if (value) {
|
|
532
|
-
this.lastScenes[data.source.dSUID] = data.properties.sceneID;
|
|
533
|
-
}
|
|
534
|
-
else {
|
|
535
|
-
this.lastScenes[data.source.dSUID] = undefined;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
this.dss.emit(data.source.dSUID, data);
|
|
539
|
-
}
|
|
540
|
-
else if (data.source.isGroup && (data.properties.zoneID !== '0' || data.properties.groupID !== '0')) {
|
|
541
|
-
sourceDeviceId = this.dssStruct.stateMap[data.properties.zoneID + '.' + data.properties.groupID + '.scenes.' + data.properties.sceneID];
|
|
542
|
-
if (this.lastScenes[data.properties.zoneID + '.' + data.properties.groupID] !== undefined) {
|
|
543
|
-
lastSourceDeviceId = this.dssStruct.stateMap[data.properties.zoneID + '.' + data.properties.groupID + '.scenes.' + this.lastScenes[data.properties.zoneID + '.' + data.properties.groupID]];
|
|
544
|
-
}
|
|
545
|
-
if (value) {
|
|
546
|
-
this.lastScenes[data.properties.zoneID + '.' + data.properties.groupID] = data.properties.sceneID;
|
|
547
|
-
}
|
|
548
|
-
else {
|
|
549
|
-
this.lastScenes[data.source.dSUID] = undefined;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
if (this.config.initializeOutputValues && !forwarded && this.dssStruct.zoneDevices[data.properties.zoneID] && this.dssStruct.zoneDevices[data.properties.zoneID][data.properties.groupID]) {
|
|
553
|
-
this.dssStruct.zoneDevices[data.properties.zoneID][data.properties.groupID].forEach(dSUID => this.dss.emit(dSUID, data));
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
else if (data.source.isApartment || (data.source.isGroup && data.properties.zoneID === '0' && data.properties.groupID === '0')) {
|
|
557
|
-
sourceDeviceId = this.dssStruct.stateMap['0.0.scenes.' + data.properties.sceneID];
|
|
558
|
-
if (this.lastScenes['0.0'] !== undefined) {
|
|
559
|
-
lastSourceDeviceId = this.dssStruct.stateMap['0.0.scenes.' + this.lastScenes['0.0']];
|
|
560
|
-
}
|
|
561
|
-
if (value) {
|
|
562
|
-
this.lastScenes['0.0'] = data.properties.sceneID;
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
this.lastScenes['0.0'] = undefined;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
if (this.config.initializeOutputValues && !forwarded) {
|
|
569
|
-
const handledDevices = {};
|
|
570
|
-
Object.keys(this.dssStruct.zoneDevices).forEach(zoneId => {
|
|
571
|
-
Object.keys(this.dssStruct.zoneDevices[zoneId]).forEach(groupId => {
|
|
572
|
-
this.dssStruct.zoneDevices[zoneId][groupId].forEach(dSUID => {
|
|
573
|
-
//console.log('Check handled device: ' + dSUID + ' : ' + handledDevices[dSUID]);
|
|
574
|
-
if (!handledDevices[dSUID]) {
|
|
575
|
-
this.dss.emit(dSUID, data);
|
|
576
|
-
handledDevices[dSUID] = true;
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
});
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
if (sourceDeviceId) {
|
|
585
|
-
this.setState(sourceDeviceId, value, true);
|
|
586
|
-
lastSourceDeviceId && lastSourceDeviceId !== sourceDeviceId && value && this.setState(lastSourceDeviceId, false, true);
|
|
587
|
-
const idArr = sourceDeviceId.split('.');
|
|
588
|
-
idArr[idArr.length - 1] = 'sceneId';
|
|
589
|
-
const sceneIdState = idArr.join('.');
|
|
590
|
-
if (value) {
|
|
591
|
-
this.setState(sceneIdState, data.properties.sceneID, true);
|
|
592
|
-
}
|
|
593
|
-
else {
|
|
594
|
-
this.setState(sceneIdState, null, true);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
!forwarded && this.log.info('INVALID scenecall');
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
// When Scene is called on zone level we also update all groups in that zone
|
|
602
|
-
if (data.source.isGroup && data.properties.zoneID !== '0' && data.properties.groupID === '0') {
|
|
603
|
-
if (this.dssStruct.zoneDevices[data.properties.zoneID]) {
|
|
604
|
-
Object.keys(this.dssStruct.zoneDevices[data.properties.zoneID]).forEach(group => {
|
|
605
|
-
data.properties.groupID = group.toString();
|
|
606
|
-
handleScene(data, value, true);
|
|
607
|
-
});
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
else if (data.source.isGroup && data.properties.zoneID === '0' && data.properties.groupID === '0') {
|
|
611
|
-
this.dssStruct.apartmentStructure.zones.forEach(zone => {
|
|
612
|
-
if (!this.dssStruct.zoneDevices[zone.id]) return;
|
|
613
|
-
data.properties.zoneID = zone.id.toString();
|
|
614
|
-
Object.keys(this.dssStruct.zoneDevices[zone.id]).forEach(group => {
|
|
615
|
-
data.properties.groupID = group.toString();
|
|
616
|
-
handleScene(data, value, true);
|
|
617
|
-
});
|
|
618
|
-
})
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
//console.log('Check Button: ' + this.dssStruct.stateMap[data.properties.originDSUID + '.0.button']);
|
|
622
|
-
if (!forwarded && data.properties.callOrigin === '9') {
|
|
623
|
-
if (data.properties.originDSUID && this.dssStruct.stateMap[data.properties.originDSUID + '.0.button']) {
|
|
624
|
-
this.setState(this.dssStruct.stateMap[data.properties.originDSUID + '.0.button'], true, true);
|
|
625
|
-
this.dssStruct.stateMap[data.properties.originDSUID + '.0.buttonClickType'] && this.setState(this.dssStruct.stateMap[data.properties.originDSUID + '.0.buttonClickType'], 0, true);
|
|
626
|
-
this.dssStruct.stateMap[data.properties.originDSUID + '.0.buttonHoldCount'] && this.setState(this.dssStruct.stateMap[data.properties.originDSUID + '.0.buttonHoldCount'], 0, true);
|
|
627
|
-
}
|
|
628
|
-
else if (data.source.dSUID && this.dssStruct.stateMap[data.source.dSUID + '.0.button']) {
|
|
629
|
-
this.setState(this.dssStruct.stateMap[data.source.dSUID + '.0.button'], true, true);
|
|
630
|
-
this.dssStruct.stateMap[data.source.dSUID + '.0.buttonClickType'] && this.setState(this.dssStruct.stateMap[data.source.dSUID + '.0.buttonClickType'], 0, true);
|
|
631
|
-
this.dssStruct.stateMap[data.source.dSUID + '.0.buttonHoldCount'] && this.setState(this.dssStruct.stateMap[data.source.dSUID + '.0.buttonHoldCount'], 0, true);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
this.dss.on('callScene', data => handleScene(data, true));
|
|
637
|
-
this.dss.on('undoScene', data => handleScene(data, false));
|
|
638
|
-
|
|
639
|
-
this.dss.on('eventError', (eventName, errorCount, err) => {
|
|
640
|
-
this.log.warn('Too many event polling errors, restarting adapter');
|
|
641
|
-
this.restartAdapter();
|
|
642
|
-
});
|
|
643
|
-
// Log unhandled Events to see what happens so at all
|
|
644
|
-
eventNames.forEach(eventName => this.dss.listenerCount(eventName) === 0 && this.dss.on(eventName, data => this.eventLog(eventName, data, false)));
|
|
645
|
-
|
|
646
|
-
callback && callback(null);
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
eventLog(eventName, event, handled) {
|
|
651
|
-
this.log.debug((handled ? '' : 'UNHANDLED ') + 'EVENT: ' + eventName + ': ' + JSON.stringify(event));
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
registerObjects() {
|
|
655
|
-
const objNames = Object.keys(this.dssStruct.dssObjects);
|
|
656
|
-
this.log.info('Create ' + objNames.length + ' objects ...');
|
|
657
|
-
objNames.forEach(id => {
|
|
658
|
-
const obj = this.dssStruct.dssObjects[id];
|
|
659
|
-
const initValue = obj.value;
|
|
660
|
-
const onChange = obj.onChange;
|
|
661
|
-
delete obj.value;
|
|
662
|
-
delete obj.onChange;
|
|
663
|
-
|
|
664
|
-
this.objectHelper.setOrUpdateObject(id, obj, ['name'], initValue, onChange);
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
setInitialValues(callback, list) {
|
|
669
|
-
if (list === undefined) {
|
|
670
|
-
list = Object.keys(this.dssStruct.initialObjectValues);
|
|
671
|
-
}
|
|
672
|
-
if (list && !list.length) {
|
|
673
|
-
return callback && callback();
|
|
674
|
-
}
|
|
675
|
-
const id = list.shift();
|
|
676
|
-
//console.log('SET INITIAL: ' + id + ' = ' + this.dssStruct.initialObjectValues[id] + ', obj = ' + JSON.stringify(this.dssStruct.dssObjects[id]));
|
|
677
|
-
this.setState(id, this.dssStruct.initialObjectValues[id], true, () => this.setInitialValues(callback, list));
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
clearAdditionalObjects(delIds, callback) {
|
|
681
|
-
if (typeof delIds === 'function') {
|
|
682
|
-
callback = delIds;
|
|
683
|
-
delIds = null;
|
|
684
|
-
}
|
|
685
|
-
if (!delIds && this.objectHelper.existingStates) {
|
|
686
|
-
delIds = Object.keys(this.objectHelper.existingStates);
|
|
687
|
-
delIds.length && this.log.info('Deleting the following states: ' + JSON.stringify(delIds));
|
|
688
|
-
}
|
|
689
|
-
if (!delIds || !delIds.length) {
|
|
690
|
-
return void (callback && callback());
|
|
691
|
-
}
|
|
692
|
-
const del = delIds.shift();
|
|
693
|
-
this.delObject(del, err => {
|
|
694
|
-
if (err) {
|
|
695
|
-
this.log.info(' Could not delete ' + del + ': ' + err);
|
|
696
|
-
}
|
|
697
|
-
delete this.objectHelper[del];
|
|
698
|
-
setImmediate(() => this.clearAdditionalObjects(delIds, callback));
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// @ts-ignore parent is a valid property on module
|
|
704
|
-
if (module.parent) {
|
|
705
|
-
// Export the constructor in compact mode
|
|
706
|
-
/**
|
|
707
|
-
* @param {Partial<ioBroker.AdapterOptions>} [options={}]
|
|
708
|
-
*/
|
|
709
|
-
module.exports = (options) => new Digitalstrom(options);
|
|
710
|
-
} else {
|
|
711
|
-
// otherwise start the instance directly
|
|
712
|
-
new Digitalstrom();
|
|
713
|
-
}
|