iobroker.device-watcher 2.9.11 → 2.9.12
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 +5 -1
- package/io-package.json +14 -14
- package/main.js +249 -216
- package/package.json +8 -8
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 ciddi89 <mail@christian-behrends.de>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -189,6 +189,10 @@ It's possible to select:
|
|
|
189
189
|
Placeholder for the next version (at the beginning of the line):
|
|
190
190
|
### **WORK IN PROGRESS**
|
|
191
191
|
-->
|
|
192
|
+
### 2.9.12 (2024-01-02)
|
|
193
|
+
|
|
194
|
+
- (ciddi89) Fixed: Changed handling for state changes and subscriptions [#283](https://github.com/ciddi89/ioBroker.device-watcher/issues/283)
|
|
195
|
+
|
|
192
196
|
### 2.9.11 (2023-12-12)
|
|
193
197
|
|
|
194
198
|
- (ciddi89) Fixed: Fullybroswer >v3 use id not common name
|
|
@@ -522,7 +526,7 @@ It's possible to select:
|
|
|
522
526
|
|
|
523
527
|
MIT License
|
|
524
528
|
|
|
525
|
-
Copyright (c)
|
|
529
|
+
Copyright (c) 2024 Christian Behrends <mail@christian-behrends.de>
|
|
526
530
|
|
|
527
531
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
528
532
|
of this software and associated documentation files (the "Software"), to deal
|
package/io-package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"common": {
|
|
3
3
|
"name": "device-watcher",
|
|
4
|
-
"version": "2.9.
|
|
4
|
+
"version": "2.9.12",
|
|
5
5
|
"news": {
|
|
6
|
+
"2.9.12": {
|
|
7
|
+
"en": "Fixed: Changed handling for state changes and subscriptions [#283](https://github.com/ciddi89/ioBroker.device-watcher/issues/283)",
|
|
8
|
+
"de": "Behoben: Handhabung für Zustandsänderungen und Abonnements geändert [#283](https://github.com/ciddi89/ioBroker.device-watcher/issues/283)",
|
|
9
|
+
"ru": "Исправлено: Изменение обработки государственных изменений и подписок [#283](https://github.com/ciddi89/ioBroker.device-watcher/issues/283)",
|
|
10
|
+
"pt": "Corrigido: Manuseio alterado para alterações e assinaturas do Estado [#283](https://github.com/ciddi89/ioBroker.device-watcher/issues/283)",
|
|
11
|
+
"nl": "Gewijzigd voor staatsverandering en abonnementen",
|
|
12
|
+
"fr": "Correction : Traitement modifié pour les changements d ' état et les abonnements [#283](https://github.com/ciddi89/ioBroker.device-watcher/issues/283)",
|
|
13
|
+
"it": "Risolto: Modificato il trattamento per le modifiche dello stato e gli abbonamenti [#283](https://github.com/ciddi89/ioBroker.device-watcher/issues/283)",
|
|
14
|
+
"es": "Corregido: Modificación de la tramitación de los cambios y suscripciones estatales [#283](https://github.com/ciddi89/ioBroker.device-watcher/issues/283)",
|
|
15
|
+
"pl": "Fixed: Changed handling for state changes and subscriptions #283(https:/github.com/ciddi89/ioBroker.device-watcher/issues/283) (ang.)",
|
|
16
|
+
"uk": "Виправлено: Змінене поводження з державними змінами та підписками [#283](https://github.com/ciddi89/ioBroker.device-watcher/issues/283)",
|
|
17
|
+
"zh-cn": "固定:国家变化和订阅的改变(第283号)"
|
|
18
|
+
},
|
|
6
19
|
"2.9.11": {
|
|
7
20
|
"en": "Fixed: Fullybroswer >v3 use id not common name",
|
|
8
21
|
"de": "Behoben: Fullybroswer >v3 verwende den ID Namen",
|
|
@@ -80,19 +93,6 @@
|
|
|
80
93
|
"pl": "Admin jsonConfig schema\nZmiana: Admin jsonConfig to json5\nWstęp: Wsparcie dla urządzeń Tuya z internetowym państwem\nInne: czyste pliki plikowe",
|
|
81
94
|
"uk": "Виправлено: Admin jsonConfig schema\nЗмінено: Admin jsonConfig to json5\nДодано: Підтримка пристроїв Туя з онлайн-державою\nІнше: очищення файлів",
|
|
82
95
|
"zh-cn": "Fix: Admin json Config schema\n修改: Admin json Configg to json5\n增 编:在网上国家支持图亚装置\n其他:清洁档案"
|
|
83
|
-
},
|
|
84
|
-
"2.9.5": {
|
|
85
|
-
"en": "Added: if available use deviceName datapoint for sonoff devices\nFixed: Changed zwave to zwave2\nFixed: minor bugfixes\nAdded: FullyBrowser > v3",
|
|
86
|
-
"de": "Hinzugefügt: Wenn verfügbar benutze deviceName Datenpunkt für Sonoff Geräte\nBehoben: Zwave zu zwave2 geändert\nBehoben: kleinere Bugfixes\nHinzugefügt: FullyBrowser > V3",
|
|
87
|
-
"ru": "Добавлена: если доступно использование устройстваName datapoint для устройств sonoff\nИсправлено: Изменено zwave в zwave2\nИсправлено: незначительные багфиксы\nДобавлено: FullyBrowser > В3",
|
|
88
|
-
"pt": "Adicionado: se disponível use deviceName datapoint for sonoff devices\nCorrigido: Alterado zwave para zwave2\nCorrigido: pequenos bugfixes\nAdicionado: FullyBrowser > v3",
|
|
89
|
-
"nl": "Toegegeven:\nQuality over Quantity (QoQ) Releases Vertaling:\nQuality over Quantity (QoQ) Releases Vertaling:\nVertaling: Vertaling:",
|
|
90
|
-
"fr": "Ajouté: si le dispositif d'utilisation disponibleNom datapoint pour les appareils à sonoff\nFixé: Zwave changée en zwave2\nCorrection : corrections mineures\nAjouté: FullyBrowser phy v3",
|
|
91
|
-
"it": "Aggiunto: if available use deviceName datapoint for sonoff devices\nFisso: Cambiato zwave a zwave2\nRisolto: bugfix minori\nAggiunto: FullyBrowser > V",
|
|
92
|
-
"es": "Añadido: si está disponible el punto de datos del dispositivoName para dispositivos sonoff\nFijo: Cambio de onda de zwave2\nFijación: bugfixes menores\nAñadido: FullyBrowser v3",
|
|
93
|
-
"pl": "Addd: jeśli urządzenie użyte do transmisji danych\nFixed: Changed zwave to zwave2 (ang.)\nFixed: minor bugfixes\nAdded: FullyBrowser> (ang.). v3",
|
|
94
|
-
"uk": "Додано: якщо доступний пристрій useName для пристроїв sonoff\nВиправлено: Змінено zwave to zwave2\nВиправлено: незначні виправлення\nДоданий: FullyBrowser > в3",
|
|
95
|
-
"zh-cn": "增删:如果能用装置Name数据点用于子壳装置\n九. 固定:对兹瓦韦的改变\n固定:小额配件\n增 编:全页 评 注"
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
98
|
"titleLang": {
|
package/main.js
CHANGED
|
@@ -374,215 +374,27 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
374
374
|
async onStateChange(id, state) {
|
|
375
375
|
if (state) {
|
|
376
376
|
// this.log.debug(`State changed: ${id} changed ${state.val}`);
|
|
377
|
-
let batteryData;
|
|
378
|
-
let signalData;
|
|
379
|
-
let oldLowBatState;
|
|
380
|
-
let contactData;
|
|
381
|
-
let oldStatus;
|
|
382
|
-
let isLowBatValue;
|
|
383
|
-
let instanceStatusRaw;
|
|
384
|
-
let oldAdapterUpdatesCounts;
|
|
385
377
|
|
|
386
378
|
try {
|
|
387
379
|
/*=============================================
|
|
388
|
-
=
|
|
380
|
+
= Instances / Adapter =
|
|
389
381
|
=============================================*/
|
|
390
|
-
if (
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (this.config.checkSendAdapterUpdateMsg && this.countAdapterUpdates > oldAdapterUpdatesCounts) {
|
|
395
|
-
await this.sendStateNotifications('updateAdapter', null);
|
|
382
|
+
if (this.config.checkAdapterInstances) {
|
|
383
|
+
// Adapter Update data
|
|
384
|
+
if (id.endsWith('updatesJson')) {
|
|
385
|
+
await this.renewAdapterUpdateData(id);
|
|
396
386
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
instance.updateAvailable = adapter.newVersion;
|
|
401
|
-
}
|
|
402
|
-
} else {
|
|
403
|
-
instance.updateAvailable = ' - ';
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/*=============================================
|
|
409
|
-
= Instances =
|
|
410
|
-
=============================================*/
|
|
411
|
-
for (const [instanceID, instanceData] of this.listInstanceRaw) {
|
|
412
|
-
const checkInstance = async (instanceID, instanceData) => {
|
|
413
|
-
if (!instanceData.checkIsRunning) {
|
|
414
|
-
instanceData.checkIsRunning = true;
|
|
415
|
-
instanceStatusRaw = await this.setInstanceStatus(instanceData.instanceMode, instanceData.schedule, instanceID);
|
|
416
|
-
instanceData.isAlive = instanceStatusRaw[0];
|
|
417
|
-
instanceData.isHealthy = instanceStatusRaw[1];
|
|
418
|
-
instanceData.status = instanceStatusRaw[2];
|
|
419
|
-
instanceData.checkIsRunning = false;
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
switch (id) {
|
|
425
|
-
case `system.adapter.${instanceID}.alive`:
|
|
426
|
-
if (state.val !== instanceData.isAlive) {
|
|
427
|
-
await checkInstance(instanceID, instanceData);
|
|
428
|
-
// send message when instance was deactivated
|
|
429
|
-
if (this.config.checkSendInstanceDeactivatedMsg && !instanceData.isAlive) {
|
|
430
|
-
if (this.blacklistInstancesNotify.includes(instanceID)) continue;
|
|
431
|
-
await this.sendStateNotifications('deactivatedInstance', instanceID);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
break;
|
|
436
|
-
case `system.adapter.${instanceID}.connected`:
|
|
437
|
-
if (state.val !== instanceData.isConnectedHost && instanceData.isAlive) {
|
|
438
|
-
await checkInstance(instanceID, instanceData);
|
|
439
|
-
// send message when instance has an error
|
|
440
|
-
if (this.config.checkSendInstanceFailedMsg && !instanceData.isHealthy && instanceData.isAlive) {
|
|
441
|
-
if (this.blacklistInstancesNotify.includes(instanceID)) continue;
|
|
442
|
-
await this.sendStateNotifications('errorInstance', instanceID);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
break;
|
|
446
|
-
case `${instanceID}.info.connection`:
|
|
447
|
-
if (state.val !== instanceData.isConnectedDevice && instanceData.isAlive) {
|
|
448
|
-
await checkInstance(instanceID, instanceData);
|
|
449
|
-
// send message when instance has an error
|
|
450
|
-
if (this.config.checkSendInstanceFailedMsg && !instanceData.isHealthy && instanceData.isAlive) {
|
|
451
|
-
if (this.blacklistInstancesNotify.includes(instanceID)) continue;
|
|
452
|
-
await this.sendStateNotifications('errorInstance', instanceID);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
break;
|
|
387
|
+
// Instanz data
|
|
388
|
+
if (Array.from(this.listInstanceRaw.values()).some((obj) => Object.values(obj).includes(id))) {
|
|
389
|
+
await this.renewInstanceData(id, state);
|
|
457
390
|
}
|
|
458
391
|
}
|
|
459
392
|
|
|
460
393
|
/*=============================================
|
|
461
394
|
= Devices =
|
|
462
395
|
=============================================*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
switch (id) {
|
|
466
|
-
// device connection
|
|
467
|
-
case deviceData.instanceDeviceConnectionDP:
|
|
468
|
-
if (state.val !== deviceData.instancedeviceConnected) {
|
|
469
|
-
deviceData.instancedeviceConnected = state.val;
|
|
470
|
-
}
|
|
471
|
-
break;
|
|
472
|
-
|
|
473
|
-
// device updates
|
|
474
|
-
case deviceData.UpdateDP:
|
|
475
|
-
if (state.val !== deviceData.Upgradable) {
|
|
476
|
-
deviceData.Upgradable = await this.checkDeviceUpdate(deviceData.adapterID, state.val);
|
|
477
|
-
if (deviceData.Upgradable === true) {
|
|
478
|
-
if (this.config.checkSendDeviceUpgrade && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
479
|
-
await this.sendStateNotifications('updateDevice', device);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
break;
|
|
484
|
-
|
|
485
|
-
// device signal
|
|
486
|
-
case deviceData.SignalStrengthDP:
|
|
487
|
-
signalData = await this.calculateSignalStrength(state, deviceData.adapterID);
|
|
488
|
-
deviceData.SignalStrength = signalData[0];
|
|
489
|
-
|
|
490
|
-
break;
|
|
491
|
-
|
|
492
|
-
// device battery
|
|
493
|
-
case deviceData.batteryDP:
|
|
494
|
-
if (deviceData.isBatteryDevice) {
|
|
495
|
-
oldLowBatState = deviceData.LowBat;
|
|
496
|
-
if (state.val === 0 && deviceData.BatteryRaw >= 5) continue;
|
|
497
|
-
batteryData = await this.getBatteryData(state.val, oldLowBatState, deviceData.faultReport, deviceData.adapterID);
|
|
498
|
-
|
|
499
|
-
deviceData.Battery = batteryData[0];
|
|
500
|
-
deviceData.BatteryRaw = batteryData[2];
|
|
501
|
-
deviceData.BatteryUnitRaw = batteryData[3];
|
|
502
|
-
if (deviceData.LowBatDP !== 'none') {
|
|
503
|
-
isLowBatValue = await this.getInitValue(deviceData.LowBatDP);
|
|
504
|
-
} else {
|
|
505
|
-
isLowBatValue = undefined;
|
|
506
|
-
}
|
|
507
|
-
deviceData.LowBat = await this.setLowbatIndicator(state.val, isLowBatValue, deviceData.faultReport, deviceData.adapterID);
|
|
508
|
-
|
|
509
|
-
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
510
|
-
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
511
|
-
await this.sendStateNotifications('lowBatDevice', device);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
break;
|
|
516
|
-
|
|
517
|
-
// device low bat
|
|
518
|
-
case deviceData.LowBatDP:
|
|
519
|
-
if (deviceData.isBatteryDevice) {
|
|
520
|
-
oldLowBatState = deviceData.LowBat;
|
|
521
|
-
batteryData = await this.getBatteryData(deviceData.BatteryRaw, state.val, deviceData.faultReport, deviceData.adapterID);
|
|
522
|
-
deviceData.Battery = batteryData[0];
|
|
523
|
-
deviceData.BatteryRaw = batteryData[2];
|
|
524
|
-
deviceData.BatteryUnitRaw = batteryData[3];
|
|
525
|
-
deviceData.LowBat = await this.setLowbatIndicator(deviceData.BatteryRaw, state.val, deviceData.faultReport, deviceData.adapterID);
|
|
526
|
-
|
|
527
|
-
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
528
|
-
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
529
|
-
await this.sendStateNotifications('lowBatDevice', device);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
break;
|
|
534
|
-
|
|
535
|
-
//device error / fault reports
|
|
536
|
-
case deviceData.faultReportDP:
|
|
537
|
-
if (deviceData.isBatteryDevice) {
|
|
538
|
-
oldLowBatState = deviceData.LowBat;
|
|
539
|
-
batteryData = await this.getBatteryData(deviceData.BatteryRaw, oldLowBatState, state.val, deviceData.adapterID);
|
|
540
|
-
|
|
541
|
-
deviceData.Battery = batteryData[0];
|
|
542
|
-
deviceData.BatteryRaw = batteryData[2];
|
|
543
|
-
deviceData.BatteryUnitRaw = batteryData[3];
|
|
544
|
-
deviceData.LowBat = await this.setLowbatIndicator(deviceData.BatteryRaw, undefined, state.val, deviceData.adapterID);
|
|
545
|
-
|
|
546
|
-
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
547
|
-
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
548
|
-
await this.sendStateNotifications('lowBatDevice', device);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
break;
|
|
553
|
-
|
|
554
|
-
// device unreach
|
|
555
|
-
case deviceData.UnreachDP:
|
|
556
|
-
if (deviceData.UnreachState !== state.val) {
|
|
557
|
-
oldStatus = deviceData.Status;
|
|
558
|
-
deviceData.UnreachState = state.val;
|
|
559
|
-
contactData = await this.getOnlineState(
|
|
560
|
-
deviceData.timeSelector,
|
|
561
|
-
deviceData.adapterID,
|
|
562
|
-
deviceData.UnreachDP,
|
|
563
|
-
deviceData.SignalStrength,
|
|
564
|
-
deviceData.UnreachState,
|
|
565
|
-
deviceData.DeviceStateSelectorDP,
|
|
566
|
-
deviceData.rssiPeerSelectorDP,
|
|
567
|
-
);
|
|
568
|
-
if (contactData !== undefined) {
|
|
569
|
-
deviceData.LastContact = contactData[0];
|
|
570
|
-
deviceData.Status = contactData[1];
|
|
571
|
-
deviceData.SignalStrength = contactData[2];
|
|
572
|
-
}
|
|
573
|
-
if (this.config.checkSendOfflineMsg && oldStatus !== deviceData.Status && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
574
|
-
if (deviceData.instanceDeviceConnectionDP.val !== undefined) {
|
|
575
|
-
// check if the generally deviceData connected state is for a while true
|
|
576
|
-
if (await this.getTimestampConnectionDP(deviceData.instanceDeviceConnectionDP, 20000)) {
|
|
577
|
-
await this.sendStateNotifications('onlineStateDevice', device);
|
|
578
|
-
}
|
|
579
|
-
} else {
|
|
580
|
-
await this.sendStateNotifications('onlineStateDevice', device);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
396
|
+
if (Array.from(this.listAllDevicesRaw.values()).some((obj) => Object.values(obj).includes(id))) {
|
|
397
|
+
await this.renewDeviceData(id, state);
|
|
586
398
|
}
|
|
587
399
|
} catch (error) {
|
|
588
400
|
this.log.error(`Issue at state change: ${error}`);
|
|
@@ -864,9 +676,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
864
676
|
|
|
865
677
|
const instanceDeviceConnectionDP = `${instance}.info.connection`;
|
|
866
678
|
const instancedeviceConnected = await this.getInitValue(instanceDeviceConnectionDP);
|
|
867
|
-
this.subscribeForeignStates(instanceDeviceConnectionDP);
|
|
868
|
-
this.subscribeForeignObjects(`${this.selAdapter[i].Selektor}`);
|
|
869
|
-
|
|
679
|
+
// this.subscribeForeignStates(instanceDeviceConnectionDP);
|
|
680
|
+
//this.subscribeForeignObjects(`${this.selAdapter[i].Selektor}`);
|
|
681
|
+
this.subscribeForeignObjects('*');
|
|
870
682
|
/*=============================================
|
|
871
683
|
= Get device name =
|
|
872
684
|
=============================================*/
|
|
@@ -884,7 +696,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
884
696
|
const shortCurrDeviceString = currDeviceString.slice(0, currDeviceString.lastIndexOf('.') + 1 - 1);
|
|
885
697
|
|
|
886
698
|
// subscribe to object device path
|
|
887
|
-
this.
|
|
699
|
+
// this.subscribeForeignStates(currDeviceString);
|
|
888
700
|
|
|
889
701
|
/*=============================================
|
|
890
702
|
= Get signal strength =
|
|
@@ -911,7 +723,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
911
723
|
break;
|
|
912
724
|
}
|
|
913
725
|
//subscribe to states
|
|
914
|
-
this.subscribeForeignStates(deviceQualityDP);
|
|
726
|
+
// this.subscribeForeignStates(deviceQualityDP);
|
|
915
727
|
|
|
916
728
|
const signalData = await this.calculateSignalStrength(deviceQualityState, adapterID);
|
|
917
729
|
let linkQuality = signalData[0];
|
|
@@ -983,9 +795,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
983
795
|
faultReportingState = await this.getInitValue(faultReportingDP);
|
|
984
796
|
|
|
985
797
|
//subscribe to states
|
|
986
|
-
this.subscribeForeignStates(deviceBatteryStateDP);
|
|
987
|
-
this.subscribeForeignStates(isLowBatDP);
|
|
988
|
-
this.subscribeForeignStates(faultReportingDP);
|
|
798
|
+
// this.subscribeForeignStates(deviceBatteryStateDP);
|
|
799
|
+
// this.subscribeForeignStates(isLowBatDP);
|
|
800
|
+
// this.subscribeForeignStates(faultReportingDP);
|
|
989
801
|
|
|
990
802
|
const batteryData = await this.getBatteryData(deviceBatteryState, deviceLowBatState, faultReportingState, adapterID);
|
|
991
803
|
batteryHealth = batteryData[0];
|
|
@@ -1018,10 +830,10 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1018
830
|
}
|
|
1019
831
|
|
|
1020
832
|
// subscribe to states
|
|
1021
|
-
this.subscribeForeignStates(timeSelector);
|
|
1022
|
-
this.subscribeForeignStates(unreachDP);
|
|
1023
|
-
this.subscribeForeignStates(deviceStateSelectorDP);
|
|
1024
|
-
this.subscribeForeignStates(rssiPeerSelectorDP);
|
|
833
|
+
// this.subscribeForeignStates(timeSelector);
|
|
834
|
+
// this.subscribeForeignStates(unreachDP);
|
|
835
|
+
// this.subscribeForeignStates(deviceStateSelectorDP);
|
|
836
|
+
// this.subscribeForeignStates(rssiPeerSelectorDP);
|
|
1025
837
|
|
|
1026
838
|
const onlineState = await this.getOnlineState(timeSelector, adapterID, unreachDP, linkQuality, deviceUnreachState, deviceStateSelectorDP, rssiPeerSelectorDP);
|
|
1027
839
|
let deviceState;
|
|
@@ -1059,7 +871,8 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
1059
871
|
}
|
|
1060
872
|
|
|
1061
873
|
// subscribe to states
|
|
1062
|
-
this.subscribeForeignStates(deviceUpdateDP);
|
|
874
|
+
// this.subscribeForeignStates(deviceUpdateDP);
|
|
875
|
+
this.subscribeForeignStates('*');
|
|
1063
876
|
}
|
|
1064
877
|
|
|
1065
878
|
/*=============================================
|
|
@@ -2043,6 +1856,146 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2043
1856
|
this.log.debug(`Function finished: ${this.writeDatapoints.name}`);
|
|
2044
1857
|
} //<--End of writing Datapoints
|
|
2045
1858
|
|
|
1859
|
+
/**
|
|
1860
|
+
* @param {string | string[]} id
|
|
1861
|
+
* @param {ioBroker.State} state
|
|
1862
|
+
*/
|
|
1863
|
+
async renewDeviceData(id, state) {
|
|
1864
|
+
let batteryData;
|
|
1865
|
+
let signalData;
|
|
1866
|
+
let oldLowBatState;
|
|
1867
|
+
let contactData;
|
|
1868
|
+
let oldStatus;
|
|
1869
|
+
let isLowBatValue;
|
|
1870
|
+
|
|
1871
|
+
const deviceID = id.slice(0, id.lastIndexOf('.') + 1 - 1);
|
|
1872
|
+
const deviceData = this.listAllDevicesRaw.get(deviceID);
|
|
1873
|
+
|
|
1874
|
+
if (deviceData) {
|
|
1875
|
+
// On statechange update available datapoint
|
|
1876
|
+
switch (id) {
|
|
1877
|
+
// device connection
|
|
1878
|
+
case deviceData.instanceDeviceConnectionDP:
|
|
1879
|
+
if (state.val !== deviceData.instancedeviceConnected) {
|
|
1880
|
+
deviceData.instancedeviceConnected = state.val;
|
|
1881
|
+
}
|
|
1882
|
+
break;
|
|
1883
|
+
|
|
1884
|
+
// device updates
|
|
1885
|
+
case deviceData.UpdateDP:
|
|
1886
|
+
if (state.val !== deviceData.Upgradable) {
|
|
1887
|
+
deviceData.Upgradable = await this.checkDeviceUpdate(deviceData.adapterID, state.val);
|
|
1888
|
+
if (deviceData.Upgradable === true) {
|
|
1889
|
+
if (this.config.checkSendDeviceUpgrade && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1890
|
+
await this.sendStateNotifications('updateDevice', deviceID);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
break;
|
|
1895
|
+
|
|
1896
|
+
// device signal
|
|
1897
|
+
case deviceData.SignalStrengthDP:
|
|
1898
|
+
signalData = await this.calculateSignalStrength(state, deviceData.adapterID);
|
|
1899
|
+
deviceData.SignalStrength = signalData[0];
|
|
1900
|
+
|
|
1901
|
+
break;
|
|
1902
|
+
|
|
1903
|
+
// device battery
|
|
1904
|
+
case deviceData.batteryDP:
|
|
1905
|
+
if (deviceData.isBatteryDevice) {
|
|
1906
|
+
oldLowBatState = deviceData.LowBat;
|
|
1907
|
+
if (state.val === 0 && deviceData.BatteryRaw >= 5) return;
|
|
1908
|
+
batteryData = await this.getBatteryData(state.val, oldLowBatState, deviceData.faultReport, deviceData.adapterID);
|
|
1909
|
+
|
|
1910
|
+
deviceData.Battery = batteryData[0];
|
|
1911
|
+
deviceData.BatteryRaw = batteryData[2];
|
|
1912
|
+
deviceData.BatteryUnitRaw = batteryData[3];
|
|
1913
|
+
if (deviceData.LowBatDP !== 'none') {
|
|
1914
|
+
isLowBatValue = await this.getInitValue(deviceData.LowBatDP);
|
|
1915
|
+
} else {
|
|
1916
|
+
isLowBatValue = undefined;
|
|
1917
|
+
}
|
|
1918
|
+
deviceData.LowBat = await this.setLowbatIndicator(state.val, isLowBatValue, deviceData.faultReport, deviceData.adapterID);
|
|
1919
|
+
|
|
1920
|
+
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
1921
|
+
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1922
|
+
await this.sendStateNotifications('lowBatDevice', deviceID);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
break;
|
|
1927
|
+
|
|
1928
|
+
// device low bat
|
|
1929
|
+
case deviceData.LowBatDP:
|
|
1930
|
+
if (deviceData.isBatteryDevice) {
|
|
1931
|
+
oldLowBatState = deviceData.LowBat;
|
|
1932
|
+
batteryData = await this.getBatteryData(deviceData.BatteryRaw, state.val, deviceData.faultReport, deviceData.adapterID);
|
|
1933
|
+
deviceData.Battery = batteryData[0];
|
|
1934
|
+
deviceData.BatteryRaw = batteryData[2];
|
|
1935
|
+
deviceData.BatteryUnitRaw = batteryData[3];
|
|
1936
|
+
deviceData.LowBat = await this.setLowbatIndicator(deviceData.BatteryRaw, state.val, deviceData.faultReport, deviceData.adapterID);
|
|
1937
|
+
|
|
1938
|
+
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
1939
|
+
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1940
|
+
await this.sendStateNotifications('lowBatDevice', deviceID);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
break;
|
|
1945
|
+
|
|
1946
|
+
//device error / fault reports
|
|
1947
|
+
case deviceData.faultReportDP:
|
|
1948
|
+
if (deviceData.isBatteryDevice) {
|
|
1949
|
+
oldLowBatState = deviceData.LowBat;
|
|
1950
|
+
batteryData = await this.getBatteryData(deviceData.BatteryRaw, oldLowBatState, state.val, deviceData.adapterID);
|
|
1951
|
+
|
|
1952
|
+
deviceData.Battery = batteryData[0];
|
|
1953
|
+
deviceData.BatteryRaw = batteryData[2];
|
|
1954
|
+
deviceData.BatteryUnitRaw = batteryData[3];
|
|
1955
|
+
deviceData.LowBat = await this.setLowbatIndicator(deviceData.BatteryRaw, undefined, state.val, deviceData.adapterID);
|
|
1956
|
+
|
|
1957
|
+
if (deviceData.LowBat && oldLowBatState !== deviceData.LowBat) {
|
|
1958
|
+
if (this.config.checkSendBatteryMsg && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1959
|
+
await this.sendStateNotifications('lowBatDevice', deviceID);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
break;
|
|
1964
|
+
|
|
1965
|
+
// device unreach
|
|
1966
|
+
case deviceData.UnreachDP:
|
|
1967
|
+
if (deviceData.UnreachState !== state.val) {
|
|
1968
|
+
oldStatus = deviceData.Status;
|
|
1969
|
+
deviceData.UnreachState = state.val;
|
|
1970
|
+
contactData = await this.getOnlineState(
|
|
1971
|
+
deviceData.timeSelector,
|
|
1972
|
+
deviceData.adapterID,
|
|
1973
|
+
deviceData.UnreachDP,
|
|
1974
|
+
deviceData.SignalStrength,
|
|
1975
|
+
deviceData.UnreachState,
|
|
1976
|
+
deviceData.DeviceStateSelectorDP,
|
|
1977
|
+
deviceData.rssiPeerSelectorDP,
|
|
1978
|
+
);
|
|
1979
|
+
if (contactData !== undefined) {
|
|
1980
|
+
deviceData.LastContact = contactData[0];
|
|
1981
|
+
deviceData.Status = contactData[1];
|
|
1982
|
+
deviceData.SignalStrength = contactData[2];
|
|
1983
|
+
}
|
|
1984
|
+
if (this.config.checkSendOfflineMsg && oldStatus !== deviceData.Status && !this.blacklistNotify.includes(deviceData.Path)) {
|
|
1985
|
+
if (deviceData.instanceDeviceConnectionDP.val !== undefined) {
|
|
1986
|
+
// check if the generally deviceData connected state is for a while true
|
|
1987
|
+
if (await this.getTimestampConnectionDP(deviceData.instanceDeviceConnectionDP, 20000)) {
|
|
1988
|
+
await this.sendStateNotifications('onlineStateDevice', deviceID);
|
|
1989
|
+
}
|
|
1990
|
+
} else {
|
|
1991
|
+
await this.sendStateNotifications('onlineStateDevice', deviceID);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
break;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
2046
1999
|
/**
|
|
2047
2000
|
* get all Instances at start
|
|
2048
2001
|
*/
|
|
@@ -2127,10 +2080,12 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2127
2080
|
}
|
|
2128
2081
|
|
|
2129
2082
|
//subscribe to statechanges
|
|
2130
|
-
this.subscribeForeignStates(id);
|
|
2131
|
-
this.subscribeForeignStates(instanceConnectedHostDP);
|
|
2132
|
-
this.subscribeForeignStates(instanceConnectedDeviceDP);
|
|
2133
|
-
this.
|
|
2083
|
+
// this.subscribeForeignStates(id);
|
|
2084
|
+
// this.subscribeForeignStates(instanceConnectedHostDP);
|
|
2085
|
+
// this.subscribeForeignStates(instanceConnectedDeviceDP);
|
|
2086
|
+
this.subscribeForeignStates('*');
|
|
2087
|
+
//this.subscribeForeignObjects(`system.adapter.*`);
|
|
2088
|
+
this.subscribeForeignObjects('*');
|
|
2134
2089
|
|
|
2135
2090
|
// create raw list
|
|
2136
2091
|
this.listInstanceRaw.set(instanceID, {
|
|
@@ -2146,6 +2101,9 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2146
2101
|
isConnectedDevice: instanceConnectedDeviceVal,
|
|
2147
2102
|
status: instanceStatus,
|
|
2148
2103
|
checkIsRunning: false,
|
|
2104
|
+
aliveDP: `system.adapter.${instanceID}.alive`,
|
|
2105
|
+
hostConnectionDP: instanceConnectedHostDP,
|
|
2106
|
+
deviceConnectionDP: instanceConnectedDeviceDP,
|
|
2149
2107
|
});
|
|
2150
2108
|
}
|
|
2151
2109
|
await this.createInstanceList();
|
|
@@ -2364,7 +2322,7 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2364
2322
|
const adapterUpdateListDP = `admin.*.info.updatesJson`;
|
|
2365
2323
|
|
|
2366
2324
|
// subscribe to datapoint
|
|
2367
|
-
this.subscribeForeignStates(adapterUpdateListDP);
|
|
2325
|
+
// this.subscribeForeignStates(adapterUpdateListDP);
|
|
2368
2326
|
|
|
2369
2327
|
await this.getAdapterUpdateData(adapterUpdateListDP);
|
|
2370
2328
|
|
|
@@ -2535,6 +2493,81 @@ class DeviceWatcher extends utils.Adapter {
|
|
|
2535
2493
|
await this.setStateChangedAsync(`adapterAndInstances.countInstancesError`, { val: this.countErrorInstance, ack: true });
|
|
2536
2494
|
}
|
|
2537
2495
|
|
|
2496
|
+
/**
|
|
2497
|
+
* @param {string} id
|
|
2498
|
+
*/
|
|
2499
|
+
async renewAdapterUpdateData(id) {
|
|
2500
|
+
const oldAdapterUpdatesCounts = this.countAdapterUpdates;
|
|
2501
|
+
await this.getAdapterUpdateData(id);
|
|
2502
|
+
await this.createAdapterUpdateList();
|
|
2503
|
+
if (this.config.checkSendAdapterUpdateMsg && this.countAdapterUpdates > oldAdapterUpdatesCounts) {
|
|
2504
|
+
await this.sendStateNotifications('updateAdapter', null);
|
|
2505
|
+
}
|
|
2506
|
+
this.listInstanceRaw.forEach((instance) => {
|
|
2507
|
+
const adapterUpdate = this.adapterUpdatesJsonRaw.get(instance.Adapter);
|
|
2508
|
+
instance.updateAvailable = adapterUpdate ? adapterUpdate.newVersion : ' - ';
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
/**
|
|
2512
|
+
* call function on state change, renew data and send messages
|
|
2513
|
+
* @param {string} id
|
|
2514
|
+
* @param {ioBroker.State} state
|
|
2515
|
+
*/
|
|
2516
|
+
async renewInstanceData(id, state) {
|
|
2517
|
+
const instanceID = await this.getInstanceName(id);
|
|
2518
|
+
const instanceData = this.listInstanceRaw.get(instanceID);
|
|
2519
|
+
if (instanceData) {
|
|
2520
|
+
let instanceStatusRaw;
|
|
2521
|
+
|
|
2522
|
+
const checkInstance = async (instanceID, instanceData) => {
|
|
2523
|
+
if (!instanceData.checkIsRunning) {
|
|
2524
|
+
instanceData.checkIsRunning = true;
|
|
2525
|
+
instanceStatusRaw = await this.setInstanceStatus(instanceData.instanceMode, instanceData.schedule, instanceID);
|
|
2526
|
+
instanceData.isAlive = instanceStatusRaw[0];
|
|
2527
|
+
instanceData.isHealthy = instanceStatusRaw[1];
|
|
2528
|
+
instanceData.status = instanceStatusRaw[2];
|
|
2529
|
+
instanceData.checkIsRunning = false;
|
|
2530
|
+
return;
|
|
2531
|
+
}
|
|
2532
|
+
};
|
|
2533
|
+
|
|
2534
|
+
switch (id) {
|
|
2535
|
+
case `system.adapter.${instanceID}.alive`:
|
|
2536
|
+
if (state.val !== instanceData.isAlive) {
|
|
2537
|
+
await checkInstance(instanceID, instanceData);
|
|
2538
|
+
// send message when instance was deactivated
|
|
2539
|
+
if (this.config.checkSendInstanceDeactivatedMsg && !instanceData.isAlive) {
|
|
2540
|
+
if (this.blacklistInstancesNotify.includes(instanceID)) return;
|
|
2541
|
+
await this.sendStateNotifications('deactivatedInstance', instanceID);
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
break;
|
|
2545
|
+
|
|
2546
|
+
case `system.adapter.${instanceID}.connected`:
|
|
2547
|
+
if (state.val !== instanceData.isConnectedHost && instanceData.isAlive) {
|
|
2548
|
+
await checkInstance(instanceID, instanceData);
|
|
2549
|
+
// send message when instance has an error
|
|
2550
|
+
if (this.config.checkSendInstanceFailedMsg && !instanceData.isHealthy && instanceData.isAlive) {
|
|
2551
|
+
if (this.blacklistInstancesNotify.includes(instanceID)) return;
|
|
2552
|
+
await this.sendStateNotifications('errorInstance', instanceID);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
break;
|
|
2556
|
+
|
|
2557
|
+
case `${instanceID}.info.connection`:
|
|
2558
|
+
if (state.val !== instanceData.isConnectedDevice && instanceData.isAlive) {
|
|
2559
|
+
await checkInstance(instanceID, instanceData);
|
|
2560
|
+
// send message when instance has an error
|
|
2561
|
+
if (this.config.checkSendInstanceFailedMsg && !instanceData.isHealthy && instanceData.isAlive) {
|
|
2562
|
+
if (this.blacklistInstancesNotify.includes(instanceID)) return;
|
|
2563
|
+
await this.sendStateNotifications('errorInstance', instanceID);
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
break;
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2538
2571
|
/**
|
|
2539
2572
|
* create Datapoints for Instances
|
|
2540
2573
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.device-watcher",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.12",
|
|
4
4
|
"description": "Watchdog for devices",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Christian Behrends",
|
|
@@ -37,24 +37,24 @@
|
|
|
37
37
|
"@types/chai": "^4.3.11",
|
|
38
38
|
"@types/chai-as-promised": "^7.1.8",
|
|
39
39
|
"@types/mocha": "^10.0.6",
|
|
40
|
-
"@types/node": "^20.10.
|
|
41
|
-
"@types/node-schedule": "^2.1.
|
|
40
|
+
"@types/node": "^20.10.6",
|
|
41
|
+
"@types/node-schedule": "^2.1.5",
|
|
42
42
|
"@types/proxyquire": "^1.3.31",
|
|
43
43
|
"@types/sinon": "^17.0.2",
|
|
44
44
|
"@types/sinon-chai": "^3.2.12",
|
|
45
45
|
"chai": "^4.3.10",
|
|
46
46
|
"chai-as-promised": "^7.1.1",
|
|
47
47
|
"cron-parser": "^4.9.0",
|
|
48
|
-
"eslint": "^8.
|
|
49
|
-
"eslint-config-prettier": "^9.
|
|
50
|
-
"eslint-plugin-prettier": "^5.
|
|
48
|
+
"eslint": "^8.56.0",
|
|
49
|
+
"eslint-config-prettier": "^9.1.0",
|
|
50
|
+
"eslint-plugin-prettier": "^5.1.2",
|
|
51
51
|
"mocha": "^10.2.0",
|
|
52
52
|
"node-schedule": "^2.1.1",
|
|
53
|
-
"prettier": "^3.1.
|
|
53
|
+
"prettier": "^3.1.1",
|
|
54
54
|
"proxyquire": "^2.1.3",
|
|
55
55
|
"sinon": "^17.0.1",
|
|
56
56
|
"sinon-chai": "^3.7.0",
|
|
57
|
-
"typescript": "~5.3.
|
|
57
|
+
"typescript": "~5.3.3"
|
|
58
58
|
},
|
|
59
59
|
"main": "main.js",
|
|
60
60
|
"files": [
|