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/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
- // The adapter-core module gives you access to the core ioBroker functions
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 {import('@iobroker/adapter-core').AdapterOptions} [options] - Adapter options
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.setState('info.connection', false, true);
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 || 'admin',
77
- password: cfg.password || 'Admin123',
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
- callback();
118
- //}
109
+ await this.setState('info.connection', false, true);
119
110
  } catch (e) {
120
111
  this.log.debug(`Error on stopping ${e.message}`);
121
- /* ignore */
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.registerName} ist nicht schreibbar`);
140
+ this.log.warn(`${dp.pointName} ist nicht schreibbar`);
144
141
  return;
145
142
  }
146
143
 
147
- this.log.info(`Schreibe ${state.val} → ${dp.registerName}`);
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.debug,
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: dp.ioType || 'number',
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 * 10000) % interval === 0) {
329
- this.log.info(`Starte Polling: ${dps.length} Datenpunkte alle ${interval}s`);
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
- // await this.setState('info.connection', false, true);
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
- export default new WemCanapi();
403
-
404
- // if (require.main !== module) {
405
- // // Export the constructor in compact mode
406
- // /**
407
- // * @param {Partial<utils.AdapterOptions>} [options] - Adapter options
408
- // */
409
- // module.exports = options => new WemCanapi(options);
410
- // } else {
411
- // // otherwise start the instance directly
412
- // new WemCanapi();
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
- "name": "iobroker.wem-canapi",
3
- "version": "0.0.2",
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
- },
24
- "devDependencies": {
25
- "@alcalzone/release-script": "^5.2.1",
26
- "@alcalzone/release-script-plugin-iobroker": "^5.2.0",
27
- "@alcalzone/release-script-plugin-license": "^5.2.2",
28
- "@alcalzone/release-script-plugin-manual-review": "^5.2.0",
29
- "@emotion/react": "^11.14.0",
30
- "@emotion/styled": "^11.14.0",
31
- "@iobroker/adapter-dev": "^1.5.0",
32
- "@iobroker/adapter-react-v5": "^7.5.0",
33
- "@iobroker/dev-server": "^0.8.0",
34
- "@iobroker/eslint-config": "^2.3.4",
35
- "@iobroker/testing": "^6.3.0",
36
- "@mui/material": "^7.0.0",
37
- "@tsconfig/node22": "^22.0.7",
38
- "@types/node": "^22.0.0",
39
- "@types/react": "^18.0.0",
40
- "@types/react-dom": "^18.0.0",
41
- "@vitejs/plugin-react": "^4.0.0",
42
- "react": "^18.0.0",
43
- "react-dom": "^18.0.0",
44
- "typescript": "~5.7.2",
45
- "vite": "^6.0.0"
46
- },
47
- "main": "main.js",
48
- "files": [
49
- "admin/build/",
50
- "admin/index_m.html",
51
- "admin/index.js",
52
- "admin/index.css",
53
- "admin/canapi.csv",
54
- "admin/wem-canapi.png",
55
- "lib/",
56
- "io-package.json",
57
- "LICENSE",
58
- "main.js"
59
- ],
60
- "scripts": {
61
- "build": "cd admin && npm run build && cd .. && node scripts/sync.mjs",
62
- "watch": "cd admin && npm run watch",
63
- "sync": "node scripts/sync.mjs",
64
- "test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"",
65
- "test:package": "mocha test/package --exit",
66
- "test:integration": "mocha test/integration --exit",
67
- "test": "npm run test:js && npm run test:package",
68
- "lint": "eslint -c eslint.config.mjs .",
69
- "translate": "translate-adapter",
70
- "release": "release-script",
71
- "release-patch": "release-script patch --yes",
72
- "release-minor": "release-script minor --yes",
73
- "release-major": "release-script major --yes",
74
- "dev-server": "dev-server watch --no-start",
75
- "dev-debug": "dev-server debug --wait --no-start"
76
- },
77
- "bugs": {
78
- "url": "https://github.com/TanteJoe/ioBroker.wem-canapi/issues"
79
- },
80
- "directories": {
81
- "lib": "lib",
82
- "test": "test"
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
  }