iobroker.sun2000 2.4.2 → 2.4.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/lib/tools.js CHANGED
@@ -260,15 +260,19 @@ const createAsyncLock = () => {
260
260
  const waitForValue = (func, timeout = 5000) => {
261
261
  return new Promise((resolve, reject) => {
262
262
  const timer = setInterval(() => {
263
- const variable = func();
264
- if (variable !== undefined && variable !== null) {
265
- clearInterval(timer);
266
- resolve(variable);
267
- }
268
- timeout -= 200;
269
- if (timeout <= 0) {
270
- clearInterval(timer);
271
- reject('Timeout: Wert wurde nicht rechtzeitig gesetzt.');
263
+ try {
264
+ const variable = func();
265
+ if (variable !== undefined && variable !== null) {
266
+ clearInterval(timer);
267
+ resolve(variable);
268
+ }
269
+ timeout -= 200;
270
+ if (timeout <= 0) {
271
+ clearInterval(timer);
272
+ reject('waitForValue: Timeout waiting for value');
273
+ }
274
+ } catch (err) {
275
+ this.adapter.logger.warn(`waitForValue ${err?.message}`);
272
276
  }
273
277
  }, 200); // alle 200ms prüfen
274
278
  });
package/lib/types.js CHANGED
@@ -262,6 +262,7 @@ const statisticsType = {
262
262
  deltaReset: 'deltaReset',
263
263
  delta: 'delta',
264
264
  level: 'level',
265
+ computed: 'computed', // wird aus anderen Werten im selben Eintrag berechnet
265
266
  };
266
267
 
267
268
  module.exports = {
package/main.js CHANGED
@@ -280,6 +280,86 @@ class Sun2000 extends utils.Adapter {
280
280
  }
281
281
  */
282
282
 
283
+ /**
284
+ * Sends anonymous usage statistics via the Sentry plugin.
285
+ * Only fires if the Sentry plugin is available and the user has
286
+ * opted in via adapter config (sendStatistics: true).
287
+ *
288
+ * No personal data, no IPs, no identifiers — only aggregated
289
+ * feature flags and hardware counts.
290
+ */
291
+ sendAnonymousStatistics() {
292
+ try {
293
+ if (!this.config.sendStatistics) return;
294
+
295
+ if (!this.supportsFeature?.('PLUGINS')) return;
296
+
297
+ const sentryInstance = this.getPluginInstance('sentry');
298
+ if (!sentryInstance) return;
299
+
300
+ const Sentry = sentryInstance.getSentryObject();
301
+ if (!Sentry) return;
302
+
303
+ // --- Device counts from this.devices ---
304
+ const inverterCount = this.devices.filter(d => d.driverClass === driverClasses.inverter).length;
305
+ const emmaCharger = this.devices.filter(d => d.driverClass === driverClasses.emmacharger).length;
306
+
307
+ // --- Integration type as readable string ---
308
+ const integrationMap = { 0: 'sDongle', 1: 'smartLogger', 2: 'emma' };
309
+ const integration = integrationMap[this.settings.integration] ?? 'unknown';
310
+
311
+ const payload = {
312
+ // Adapter
313
+ adapterVersion: this.version,
314
+
315
+ // Platform / environment
316
+ platform: process.platform, // 'linux', 'win32', 'darwin'
317
+ nodeVersion: process.version, // 'v20.x.x'
318
+ arch: process.arch, // 'arm', 'x64'
319
+
320
+ // Integration type
321
+ integration, // 'sDongle' | 'smartLogger' | 'emma'
322
+
323
+ emmaCharger,
324
+
325
+ // Device counts and types
326
+ inverterCount,
327
+
328
+ // Features
329
+ modbusProxy: this.settings.ms?.active ?? false,
330
+ batteryTOU: this.settings.cb?.tou ?? false,
331
+
332
+ // Timing (gives insight into installation size / load)
333
+ highInterval: Math.round(this.settings.highInterval / 1000), // seconds
334
+ };
335
+
336
+ Sentry.withScope(scope => {
337
+ scope.setLevel('info');
338
+
339
+ // Each payload field as a separate Sentry extra — visible in Sentry dashboard
340
+ for (const [key, value] of Object.entries(payload)) {
341
+ scope.setExtra(key, value);
342
+ }
343
+
344
+ // Most important fields as filterable tags
345
+ scope.setTag('adapterVersion', payload.adapterVersion);
346
+ scope.setTag('platform', payload.platform);
347
+ scope.setTag('arch', payload.arch);
348
+ scope.setTag('integration', payload.integration);
349
+ scope.setTag('inverterCount', String(payload.inverterCount));
350
+ scope.setTag('emmaCharger', String(payload.emmaCharger));
351
+ scope.setTag('modbusProxy', String(payload.modbusProxy));
352
+
353
+ Sentry.captureMessage('sun2000.adapterStatistics', 'info');
354
+ });
355
+
356
+ this.logger.debug('sun2000: anonymous statistics sent via Sentry');
357
+ } catch (e) {
358
+ // Never let statistics reporting affect adapter operation
359
+ this.logger.debug(`sun2000: statistics reporting failed silently: ${e.message}`);
360
+ }
361
+ }
362
+
283
363
  async endOfmodbusAdjust(info) {
284
364
  if (!info.modbusAdjust) {
285
365
  this.settings.modbusAdjust = info.modbusAdjust;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.sun2000",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "description": "sun2000",
5
5
  "author": {
6
6
  "name": "bolliy",
@@ -42,7 +42,7 @@
42
42
  "@iobroker/eslint-config": "^2.2.0",
43
43
  "@iobroker/testing": "^5.2.2",
44
44
  "@tsconfig/node22": "^22.0.5",
45
- "@types/node": "^25.5.0",
45
+ "@types/node": "^25.6.0",
46
46
  "globals": "^16.5.0",
47
47
  "typescript": "~5.9.3"
48
48
  },