Skip to content

Commit

Permalink
add option to set interval
Browse files Browse the repository at this point in the history
  • Loading branch information
nitaybz committed Dec 20, 2020
1 parent 96cc44e commit ba85288
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ If you don't use Homebridge UI or HOOBS, keep reading:
"platforms": [
{
"platform": "NetworkPresence",
"interval": 10,
"threshold": 15,
"devices": [
{
Expand All @@ -68,7 +69,8 @@ If you don't use Homebridge UI or HOOBS, keep reading:
| Parameter | Description | Default | type |
| -------------------------------- | ------------------------------------------------------- |:--------:|:--------:|:--------:|
| `platform` | always `"NetworkPresence"` | - | String |
| `threshold` | Time in minutes to wait before updating 'disconnected' status. important for not spamming your notifications or wrongly activating automation because the device has gone from the network for short time. | `15` | Integer |
| `interval` | Time in seconds between status polling for connected devices | `10` | Integer |
| `threshold` | Time in minutes to wait before updating 'disconnected' status. important for not spamming your notifications or wrongly activating automation because the device has gone from the network for short time | `15` | Integer |
| `debug`       | When set to `true`, the plugin will produce extra logs for debugging purposes | `false` | Boolean |
| **Devices** | List of devices to monitor (with the below information)| | Array|
| `name` | Name of the accessory in HomeKit | | String |
Expand Down
1 change: 1 addition & 0 deletions config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"platforms": [
{
"platform": "NetworkPresence",
"interval": 10,
"threshold": 15,
"devices": [
{
Expand Down
11 changes: 11 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
"default": false,
"required": false
},
"interval": {
"title": "Polling Interval for New Devices (seconds)",
"description": "Time in seconds between status polling",
"type": "integer",
"default": 10,
"minimum": 1,
"maximum": 60
},
"threshold": {
"title": "Disconnect Threshold (minutes)",
"description": "Time in minutes to wait before updating 'disconnected' status",
Expand Down Expand Up @@ -70,6 +78,9 @@
}
},
"layout": [
{
"key": "interval"
},
{
"key": "threshold"
},
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class NetworkPresence {
this.PLUGIN_NAME = PLUGIN_NAME
this.PLATFORM_NAME = PLATFORM_NAME
this.name = config.name || PLATFORM_NAME
this.interval = config.interval ? config.interval * 1000 : 10000
this.threshold = !config.threshold && config.threshold !== 0 ? 15 : config.threshold
this.devicesConfig = config.devices || []
this.debug = config.debug || false
Expand Down
7 changes: 4 additions & 3 deletions lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const init = function() {
removeCachedDevices.bind(this)()

this.log(`Initiating Network Scanner...`)
const net = new NetworkObserver()
const net = new NetworkObserver(this.interval)

net.on('err', (err) => {
this.log('ERROR OCCURRED !!')
Expand All @@ -21,17 +21,18 @@ const init = function() {
}

class NetworkObserver extends EventEmitter {
constructor() {
constructor(interval) {
super();
this.pingOptions = {
timeout: 2000
};
this.interval = interval
this.cachedDevices = [];
this.tick();
}

get pollInterval() {
return 1000;
return this.interval;
}

get devices() {
Expand Down

0 comments on commit ba85288

Please sign in to comment.