iobroker.wem-canapi 0.0.2 → 0.0.4
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 +1 -1
- package/README.md +10 -6
- package/admin/canapi.csv +3 -3
- package/admin/i18n/de.json +31 -0
- package/admin/i18n/en.json +31 -0
- package/admin/i18n/es.json +31 -0
- package/admin/i18n/fr.json +31 -0
- package/admin/i18n/it.json +31 -0
- package/admin/i18n/nl.json +31 -0
- package/admin/i18n/pl.json +31 -0
- package/admin/i18n/pt.json +31 -0
- package/admin/i18n/ru.json +31 -0
- package/admin/i18n/uk.json +31 -0
- package/admin/i18n/zh-cn.json +31 -0
- package/admin/index.js +615 -16
- package/admin/index_m.html +1 -0
- package/io-package.json +158 -132
- package/lib/canApiClient.js +69 -16
- package/lib/csvParser.js +0 -36
- package/main.js +72 -56
- package/package.json +84 -82
package/main.js
CHANGED
|
@@ -3,22 +3,13 @@
|
|
|
3
3
|
/*
|
|
4
4
|
* Created with @iobroker/create-adapter v3.1.5
|
|
5
5
|
*/
|
|
6
|
-
// const CanApiClient = require('./lib/canApiClient');
|
|
7
6
|
import CanApiClient from './lib/canApiClient.js';
|
|
8
|
-
//
|
|
9
|
-
// you need to create an adapter
|
|
10
|
-
//const utils = require('@iobroker/adapter-core');
|
|
11
|
-
|
|
7
|
+
// @ts-expect-error adapter-core is supplied by the ioBroker runtime and may be absent in editor-only environments.
|
|
12
8
|
import { Adapter } from '@iobroker/adapter-core';
|
|
13
|
-
// const CsvParser = require('./lib/csvParser');
|
|
14
|
-
import CsvParser from './lib/csvParser.js';
|
|
15
|
-
|
|
16
|
-
// Load your modules here, e.g.:
|
|
17
|
-
// const fs = require('fs');
|
|
18
9
|
|
|
19
10
|
class WemCanapi extends Adapter {
|
|
20
11
|
/**
|
|
21
|
-
* @param {
|
|
12
|
+
* @param {object} [options] - Adapter options
|
|
22
13
|
*/
|
|
23
14
|
constructor(options) {
|
|
24
15
|
super({
|
|
@@ -47,7 +38,7 @@ class WemCanapi extends Adapter {
|
|
|
47
38
|
* Is called when databases are connected and adapter received configuration.
|
|
48
39
|
*/
|
|
49
40
|
async onReady() {
|
|
50
|
-
await this.
|
|
41
|
+
await this.setStateAsync('info.connection', false, true);
|
|
51
42
|
|
|
52
43
|
const cfg = this.config;
|
|
53
44
|
if (!cfg.host) {
|
|
@@ -69,18 +60,22 @@ class WemCanapi extends Adapter {
|
|
|
69
60
|
this.dpMap.set(dp.id, dp);
|
|
70
61
|
}
|
|
71
62
|
|
|
63
|
+
if (!cfg.username || !cfg.password) {
|
|
64
|
+
this.log.warn('Benutzername oder Passwort nicht konfiguriert - Anfrage erfolgt ohne Authentifizierung.');
|
|
65
|
+
}
|
|
66
|
+
|
|
72
67
|
// HTTP-Client erstellen
|
|
73
68
|
this.client = new CanApiClient({
|
|
74
69
|
host: cfg.host,
|
|
75
70
|
port: cfg.port || 80,
|
|
76
|
-
username: cfg.username || '
|
|
77
|
-
password: cfg.password || '
|
|
71
|
+
username: cfg.username || '',
|
|
72
|
+
password: cfg.password || '',
|
|
78
73
|
timeout: cfg.timeout || 5000,
|
|
79
74
|
log: this.log,
|
|
75
|
+
adapter: this,
|
|
80
76
|
});
|
|
81
77
|
|
|
82
78
|
// Verbindung testen
|
|
83
|
-
//const testpwd = this.config.password;
|
|
84
79
|
const ok = await this.client.testConnection();
|
|
85
80
|
await this.setState('info.connection', ok, true);
|
|
86
81
|
|
|
@@ -92,6 +87,7 @@ class WemCanapi extends Adapter {
|
|
|
92
87
|
// Objekte anlegen
|
|
93
88
|
const activeDPs = selected.map(id => this.dpMap.get(id)).filter(Boolean);
|
|
94
89
|
await this._createSyncState();
|
|
90
|
+
await this._createResetObject();
|
|
95
91
|
await this._createObjects(activeDPs);
|
|
96
92
|
await this.subscribeStatesAsync('*');
|
|
97
93
|
|
|
@@ -107,20 +103,15 @@ class WemCanapi extends Adapter {
|
|
|
107
103
|
*/
|
|
108
104
|
async onUnload(callback) {
|
|
109
105
|
try {
|
|
110
|
-
/* for (const t of this.timers.values()) this.clearInterval(t);
|
|
111
|
-
this.timers.clear();
|
|
112
|
-
await this.setState('info.connection', false, true); */
|
|
113
106
|
if (this.timerId) {
|
|
114
107
|
this.clearTimeout(this.timerId);
|
|
115
|
-
await this.setState('info.connection', false, true);
|
|
116
108
|
}
|
|
117
|
-
|
|
118
|
-
//}
|
|
109
|
+
await this.setState('info.connection', false, true);
|
|
119
110
|
} catch (e) {
|
|
120
111
|
this.log.debug(`Error on stopping ${e.message}`);
|
|
121
|
-
|
|
112
|
+
} finally {
|
|
113
|
+
callback();
|
|
122
114
|
}
|
|
123
|
-
callback();
|
|
124
115
|
}
|
|
125
116
|
|
|
126
117
|
// ─────────────────────────────────────────────────────────────
|
|
@@ -134,17 +125,23 @@ class WemCanapi extends Adapter {
|
|
|
134
125
|
|
|
135
126
|
// ioBroker-ID → Datenpunkt finden
|
|
136
127
|
const localId = id.replace(`${this.namespace}.`, '');
|
|
128
|
+
if ('info.ResetAllObjects' === localId && state.val === true) {
|
|
129
|
+
this.log.info('Reset All Objects');
|
|
130
|
+
await this._resetObj(this.dpMap.values());
|
|
131
|
+
await this.setState(localId, { val: false, ack: true });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
137
134
|
|
|
138
135
|
for (const dp of this.dpMap.values()) {
|
|
139
136
|
if (dp.treePath !== localId) {
|
|
140
137
|
continue;
|
|
141
138
|
}
|
|
142
139
|
if (!dp.canWrite) {
|
|
143
|
-
this.log.warn(`${dp.
|
|
140
|
+
this.log.warn(`${dp.pointName} ist nicht schreibbar`);
|
|
144
141
|
return;
|
|
145
142
|
}
|
|
146
143
|
|
|
147
|
-
this.log.info(`Schreibe ${state.val} → ${dp.
|
|
144
|
+
this.log.info(`Schreibe ${state.val} → ${dp.pointName} `);
|
|
148
145
|
const ok = await this.client.writeDatapoint(dp, state.val);
|
|
149
146
|
|
|
150
147
|
if (ok) {
|
|
@@ -169,18 +166,6 @@ class WemCanapi extends Adapter {
|
|
|
169
166
|
}
|
|
170
167
|
|
|
171
168
|
switch (obj.command) {
|
|
172
|
-
// ── CSV parsen ───────────────────────────────────────
|
|
173
|
-
case 'parseCSV': {
|
|
174
|
-
try {
|
|
175
|
-
const parser = new CsvParser();
|
|
176
|
-
const dps = parser.parse(obj.message.csvContent);
|
|
177
|
-
this._respond(obj, { result: dps, error: null });
|
|
178
|
-
} catch (e) {
|
|
179
|
-
this._respond(obj, { result: null, error: e.message });
|
|
180
|
-
}
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
169
|
// ── Verbindungstest ──────────────────────────────────
|
|
185
170
|
case 'testConnection': {
|
|
186
171
|
try {
|
|
@@ -189,7 +174,8 @@ class WemCanapi extends Adapter {
|
|
|
189
174
|
port: obj.message.port || 80,
|
|
190
175
|
username: obj.message.username || '',
|
|
191
176
|
password: obj.message.password || '',
|
|
192
|
-
log: this.log
|
|
177
|
+
log: this.log,
|
|
178
|
+
adapter: this,
|
|
193
179
|
});
|
|
194
180
|
this.log.debug('Testing Connection from AdminGUI');
|
|
195
181
|
const ok = await testClient.testConnection();
|
|
@@ -228,6 +214,23 @@ class WemCanapi extends Adapter {
|
|
|
228
214
|
native: {},
|
|
229
215
|
});
|
|
230
216
|
}
|
|
217
|
+
async _createResetObject() {
|
|
218
|
+
// State anlegen if Sync is running
|
|
219
|
+
|
|
220
|
+
await this.setObjectNotExistsAsync('info.ResetAllObjects', {
|
|
221
|
+
type: 'state',
|
|
222
|
+
common: {
|
|
223
|
+
name: 'Reset All Objects',
|
|
224
|
+
desc: 'Reset error counts for all objects',
|
|
225
|
+
type: 'boolean',
|
|
226
|
+
role: 'button',
|
|
227
|
+
def: false,
|
|
228
|
+
read: true,
|
|
229
|
+
write: true,
|
|
230
|
+
},
|
|
231
|
+
native: {},
|
|
232
|
+
});
|
|
233
|
+
}
|
|
231
234
|
async _createObjects(datapoints) {
|
|
232
235
|
for (const dp of datapoints) {
|
|
233
236
|
// Channel-Hierarchie anlegen
|
|
@@ -247,7 +250,7 @@ class WemCanapi extends Adapter {
|
|
|
247
250
|
const common = {
|
|
248
251
|
name: dp.pointName || dp.deviceName,
|
|
249
252
|
desc: `${dp.deviceName}: ${dp.pointName}`,
|
|
250
|
-
type:
|
|
253
|
+
type: CanApiClient.ioType(dp),
|
|
251
254
|
role: this._role(dp),
|
|
252
255
|
read: true,
|
|
253
256
|
write: dp.canWrite || false,
|
|
@@ -325,8 +328,8 @@ class WemCanapi extends Adapter {
|
|
|
325
328
|
this.timerrunning = true;
|
|
326
329
|
for (const [interval, dps] of this.groups.entries()) {
|
|
327
330
|
if (lastinterval != interval) {
|
|
328
|
-
if ((this.timercounter *
|
|
329
|
-
this.log.
|
|
331
|
+
if ((this.timercounter * 10) % interval === 0) {
|
|
332
|
+
this.log.debug(`Starte Polling: ${dps.length} Datenpunkte alle ${interval}s`);
|
|
330
333
|
|
|
331
334
|
await this._pollGroup(interval, dps);
|
|
332
335
|
// console.log('debug groups');
|
|
@@ -365,7 +368,7 @@ class WemCanapi extends Adapter {
|
|
|
365
368
|
if (!isrunning) {
|
|
366
369
|
await this.setState('info.syncrunnig', true, true);
|
|
367
370
|
// @ts-expect-error Client null breits abgefangen
|
|
368
|
-
const results = await this.client.readDatapoints(datapoints, this);
|
|
371
|
+
const results = await this.client.readDatapoints(await this._filterDatapointsOnError(datapoints), this);
|
|
369
372
|
|
|
370
373
|
let anyOk = false;
|
|
371
374
|
|
|
@@ -394,20 +397,33 @@ class WemCanapi extends Adapter {
|
|
|
394
397
|
}
|
|
395
398
|
} catch (e) {
|
|
396
399
|
this.log.warn(`[Poll ${interval}s] Fehler: ${e.message}`);
|
|
397
|
-
|
|
400
|
+
await this.setState('info.syncrunnig', false, true);
|
|
398
401
|
}
|
|
399
402
|
}
|
|
400
|
-
|
|
403
|
+
async _getObj(obj) {
|
|
404
|
+
const returnobj = await this.getObjectAsync(obj);
|
|
405
|
+
return returnobj;
|
|
406
|
+
}
|
|
407
|
+
async _filterDatapointsOnError(datapoints) {
|
|
408
|
+
const filtered = [];
|
|
409
|
+
for (const dp of datapoints) {
|
|
410
|
+
const obj = await this._getObj(dp.treePath);
|
|
411
|
+
if (!obj?.errorcount || obj.errorcount <= 5) {
|
|
412
|
+
filtered.push(dp);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
401
415
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
416
|
+
return filtered;
|
|
417
|
+
}
|
|
418
|
+
async _resetObj(datapoints) {
|
|
419
|
+
for (const dp of datapoints) {
|
|
420
|
+
const obj = await this._getObj(dp.treePath);
|
|
421
|
+
if (obj?.errorcount) {
|
|
422
|
+
obj.common.color = '';
|
|
423
|
+
obj.errorcount = 0;
|
|
424
|
+
await this.setObjectAsync(`${dp.treePath}`, obj);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
new WemCanapi();
|
package/package.json
CHANGED
|
@@ -1,84 +1,86 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
2
|
+
"name": "iobroker.wem-canapi",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "Get Values directly from the Weishaupt devices via CanAPI",
|
|
5
|
+
"author": "TanteJoe <github@schubel.info>",
|
|
6
|
+
"homepage": "https://github.com/TanteJoe/ioBroker.wem-canapi",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"WEM",
|
|
10
|
+
"Weishaupt",
|
|
11
|
+
"CanAPI",
|
|
12
|
+
"ioBroker"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/TanteJoe/ioBroker.wem-canapi.git"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">= 22"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@iobroker/adapter-core": "^3.4.3",
|
|
23
|
+
"@iobroker/adapter-react-v5": "^7.5.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@alcalzone/release-script": "^5.2.1",
|
|
27
|
+
"@alcalzone/release-script-plugin-iobroker": "^5.2.0",
|
|
28
|
+
"@alcalzone/release-script-plugin-license": "^5.2.2",
|
|
29
|
+
"@alcalzone/release-script-plugin-manual-review": "^5.2.0",
|
|
30
|
+
"@emotion/react": "^11.14.0",
|
|
31
|
+
"@emotion/styled": "^11.14.0",
|
|
32
|
+
"@iobroker/adapter-dev": "^1.5.0",
|
|
33
|
+
"@iobroker/adapter-react-v5": "^7.5.0",
|
|
34
|
+
"@iobroker/dev-server": "^0.8.0",
|
|
35
|
+
"@iobroker/eslint-config": "^2.3.4",
|
|
36
|
+
"@iobroker/testing": "^6.3.0",
|
|
37
|
+
"@mui/material": "^7.0.0",
|
|
38
|
+
"@tsconfig/node22": "^22.0.7",
|
|
39
|
+
"@types/node": "^22.0.0",
|
|
40
|
+
"@types/react": "^18.0.0",
|
|
41
|
+
"@types/react-dom": "^18.0.0",
|
|
42
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
43
|
+
"react": "^18.0.0",
|
|
44
|
+
"react-dom": "^18.0.0",
|
|
45
|
+
"typescript": "~5.7.2",
|
|
46
|
+
"vite": "^6.0.0"
|
|
47
|
+
},
|
|
48
|
+
"main": "main.js",
|
|
49
|
+
"type": "module",
|
|
50
|
+
"files": [
|
|
51
|
+
"admin/i18n/",
|
|
52
|
+
"admin/index_m.html",
|
|
53
|
+
"admin/index.js",
|
|
54
|
+
"admin/index.css",
|
|
55
|
+
"admin/canapi.csv",
|
|
56
|
+
"admin/wem-canapi.png",
|
|
57
|
+
"lib/",
|
|
58
|
+
"io-package.json",
|
|
59
|
+
"LICENSE",
|
|
60
|
+
"main.js"
|
|
61
|
+
],
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "cd admin && npm run build && cd .. && node scripts/sync.mjs",
|
|
64
|
+
"watch": "cd admin && npm run watch",
|
|
65
|
+
"sync": "node scripts/sync.mjs",
|
|
66
|
+
"test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"",
|
|
67
|
+
"test:package": "mocha test/package --exit",
|
|
68
|
+
"test:integration": "mocha test/integration --exit",
|
|
69
|
+
"test": "npm run test:js && npm run test:package",
|
|
70
|
+
"lint": "eslint -c eslint.config.mjs .",
|
|
71
|
+
"translate": "translate-adapter",
|
|
72
|
+
"release": "release-script",
|
|
73
|
+
"release-patch": "release-script patch --yes",
|
|
74
|
+
"release-minor": "release-script minor --yes",
|
|
75
|
+
"release-major": "release-script major --yes",
|
|
76
|
+
"dev-server": "dev-server watch --no-start",
|
|
77
|
+
"dev-debug": "dev-server debug --wait --no-start"
|
|
78
|
+
},
|
|
79
|
+
"bugs": {
|
|
80
|
+
"url": "https://github.com/TanteJoe/ioBroker.wem-canapi/issues"
|
|
81
|
+
},
|
|
82
|
+
"directories": {
|
|
83
|
+
"lib": "lib",
|
|
84
|
+
"test": "test"
|
|
85
|
+
}
|
|
84
86
|
}
|