Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pingsToChange for pingCommands #243

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@
"functionBody": "return (model.pingCommand && model.pingCommand.length > 0)"
}
},
{
"key": "pingsToChange",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried this with the UI? Since it's the same option as in the pinging section, will the value just change in both fields of the UI? Also, will changing either write to the same config?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, near the top of this file, we'll need to update the description of pingCommand.

The number of pings necessary to trigger a state change, only used if the IP address is set.

"condition": {
"functionBody": "return (model.pingCommand && model.pingCommand.length > 0)"
}
},
{
"key": "pingInterval",
"condition": {
Expand Down
14 changes: 7 additions & 7 deletions src/pinger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ export default class Pinger extends EventEmitter {
* @param immediate Whether or not to return the current state. Uses a buffer otherwise.
*/
async pollState(immediate: boolean = false): Promise<void> {
// Trust the ping command to return a true state

// Check if this is pingCommand or normal ping. Use history pinging either way.
if (this.config.pingCommand) {
const isOnline = await this.executePingCommand();
this.emit("stateChanged", isOnline);
return;
this.history.push(isOnline);
}
else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the else and braces on the same line; } else {.

const isOnline = await this.ping();
this.history.push(isOnline);
}

// Use history for pinging, since it may be unreliable
const isOnline = await this.ping();
this.history.push(isOnline);

// If there are not enough measurements yet, return prematurely
if (!immediate && this.history.length < this.config.pingsToChange) return;
Expand Down