Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
update device settings without adapter restart
  • Loading branch information
Jey-Cee committed Mar 5, 2024
1 parent c928613 commit e580657
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 19 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Remark: This feature is limited to the subnet of the ioBroker host.
### **WORK IN PROGRESS**
-->

### 1.0.6 04.03.2024
* (Jey Cee) Reduce system load during discovery process to prevent adapter crash

### 1.0.5 04.02.2024
* (Jey Cee) remove discovery adapter as dependency
* (Jey Cee) add possibility to choose the interface which will be used for ping operations
Expand Down
6 changes: 5 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"common": {
"name": "net-tools",
"version": "1.0.5",
"version": "1.0.6",
"news": {
"1.0.6": {
"en": "Reduce system load during discovery process to prevent adapter crash",
"de": "Systemlast verringert während des Discovery prozess, um einen Absturz des Adapters zu verhindern."
},
"1.0.5": {
"en": "remove discovery adapter as dependency \nadd possibility to choose the interface which will be used for ping operations \nadd possibility to enter IP range for device discovery \nadd auto search by configurable schedule \nfix/catch crash if device was deleted in objects and not in device management \nfix ping rights on lxc containers which prevent to ping devices",
"de": "Discovery-Adapter als Abhängigkeit entfernen \nMöglichkeit hinzufügen, die Schnittstelle zu wählen, die für Ping-Operationen verwendet werden soll \nHinzufügen der Möglichkeit, einen IP-Bereich für die Geräteerkennung einzugeben \nautomatische Suche nach konfigurierbarem Zeitplan hinzufügen \nBehebung eines Absturzes, wenn ein Gerät in Objekten und nicht in der Geräteverwaltung gelöscht wurde \nPing-Rechte auf lxc-Containern beheben, die das Anpingen von Geräten verhindern"
Expand Down
2 changes: 1 addition & 1 deletion lib/devicemgmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class dmNetTools extends dmUtils.DeviceManagement {
async handleDiscover(context) {
context.showMessage(
'Dicovery started. This process will take a few minutes until all devices are discovered. You can close this dialog and continue working in the meantime.');
const result = await this.adapter.discover();
this.adapter.discover();
return { refresh: false };
}

Expand Down
64 changes: 48 additions & 16 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ let wolTries = 3;
let wolTimer = null;
let discoverTimeout = null;
let pingTimeout = null;
/**
* @type {Array.<Object>}
*
* Represents a list of tasks to be executed.
*
* Each element in the taskList array is an object with specific properties. It looks like:
* ```
* {
* host: '192.168.11.15', // IP of the host
* extendedInfo: true, // Indicates if extended information should be obtained
* pingInterval: 60, // Time interval in seconds between two consecutive pings
* retries: 0, // The number of retries already made
* retryCounter: 0, // Used to count the number of retries
* stateAlive: { channel: '84b8b87e0294', state: 'alive' }, // Information about the 'alive' state
* stateTime: { channel: '84b8b87e0294', state: 'time' }, // Information about 'time' state
* stateRps: { channel: '84b8b87e0294', state: 'rps' } // Information about 'rps' state
* }
* ```
*/
let taskList = [];
let cronJob = null;

Expand All @@ -42,7 +61,7 @@ class NetTools extends utils.Adapter {
});
this.on('ready', this.onReady.bind(this));
this.on('stateChange', this.onStateChange.bind(this));
// this.on('objectChange', this.onObjectChange.bind(this));
this.on('objectChange', this.onObjectChange.bind(this));
this.on('message', this.onMessage.bind(this));
this.on('unload', this.onUnload.bind(this));

Expand Down Expand Up @@ -89,6 +108,8 @@ class NetTools extends utils.Adapter {
this.subscribeStates('*discover');
this.subscribeStates('*wol');
this.subscribeStates('*scan');
this.subscribeObjects('*');

}
}

Expand Down Expand Up @@ -127,20 +148,29 @@ class NetTools extends utils.Adapter {

// If you need to react to object changes, uncomment the following block and the corresponding line in the constructor.
// You also need to subscribe to the objects with `this.subscribeObjects`, similar to `this.subscribeStates`.
// /**
// * Is called if a subscribed object changes
// * @param {string} id
// * @param {ioBroker.Object | null | undefined} obj
// */
// onObjectChange(id, obj) {
// if (obj) {
// // The object was changed
// this.log.info(`object ${id} changed: ${JSON.stringify(obj)}`);
// } else {
// // The object was deleted
// this.log.info(`object ${id} deleted`);
// }
// }
/**
* Is called if a subscribed object changes
* @param {string} id
* @param {ioBroker.Object | null | undefined} obj
*/
onObjectChange(id, obj) {
if (obj) {
// The object was changed

if (obj.type === 'device') {
// Look if ther is a host entry in taskList for the ip
const hostEntry = taskList.find(entry => entry.host === obj.native.ip);
if (hostEntry) {
hostEntry.pingInterval = obj.native.pingInterval;
hostEntry.retries = obj.native.retries;
}
taskList = taskList.map(entry => entry.host === hostEntry.host ? hostEntry : entry);
}
} else {
// The object was deleted
//this.log.info(`object ${id} deleted`);
}
}

/**
* Is called if a subscribed state changes
Expand Down Expand Up @@ -187,7 +217,7 @@ class NetTools extends utils.Adapter {
}
} else {
// The state was deleted
this.log.info(`state ${id} deleted`);
//this.log.info(`state ${id} deleted`);
}
}

Expand Down Expand Up @@ -332,6 +362,8 @@ class NetTools extends utils.Adapter {
}
await Promise.all(promises);
}
this.log.info('Discovery finished')
return true;
} catch (err) {
this.log.warn('Discovery faild: ' + err);
return false;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.net-tools",
"version": "1.0.5",
"version": "1.0.6",
"description": "This adapter cyclic polls configured IPs, can send wake-on-lan packages and scan for open ports.",
"author": {
"name": "Jey Cee",
Expand Down

0 comments on commit e580657

Please sign in to comment.