Skip to content

Commit

Permalink
feature: add a notification if position data is not received
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 committed May 11, 2019
1 parent d19ccc4 commit 4a3e37a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ module.exports = function(app) {
var plugin = {};
var alarm_sent = false
var unsubscribe = undefined
var positionInterval
var state
var configuration
var delayStartTime
var lastPositionTime
var positionAlarmSent

plugin.start = function(props) {
configuration = props
Expand Down Expand Up @@ -169,6 +172,10 @@ module.exports = function(app) {
unsubscribe()
unsubscribe = null
}
if ( positionInterval ) {
clearInterval(positionInterval)
positionInterval = null
}
}

function startWatchingPosistion()
Expand All @@ -192,6 +199,18 @@ module.exports = function(app) {
}, ['navigation.position' ].map(app.streambundle.getSelfStream, app.streambundle)).changes().debounceImmediate(1000).onValue(state => {
sendAnchorAlarm(state, app, plugin)
})

positionInterval = setInterval(() => {
app.debug('checking last position...')
if ( !lastPositionTime || Date.now() - lastPositionTime > configuration.noPositionAlarmTime * 1000 ) {
positionAlarmSent = true
sendAnchorAlarm(configuration.state, app, plugin, 'No position received')
} else if ( alarm_sent == false && positionAlarmSent ) {
var delta = getAnchorAlarmDelta(app, "normal")
app.handleMessage(plugin.id, delta)
positionAlarmSent = false
}
}, 10000)
}

function raiseAnchor(cb) {
Expand Down Expand Up @@ -225,6 +244,10 @@ module.exports = function(app) {
unsubscribe()
unsubscribe = null
}
if ( positionInterval ) {
clearInterval(positionInterval)
positionInterval = null
}
}


Expand Down Expand Up @@ -522,6 +545,11 @@ module.exports = function(app) {
title: "Send a notification when past the warning percentage",
default: false
},
noPositionAlarmTime: {
type: "number",
title: "Send a notification if no position is received for the given number of seconds",
default: 10
},
position: {
type: "object",
title: "Anchor Position",
Expand Down

0 comments on commit 4a3e37a

Please sign in to comment.