diff --git a/lib/plugins/index.js b/lib/plugins/index.js index c22650682e6..ba0a572a54b 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -21,6 +21,8 @@ function init() { require('./rawbg')() , require('./delta')() , require('./direction')() + , require('./timeago')() + , require('./upbat')() , require('./ar2')() , require('./errorcodes')() , require('./iob')() @@ -32,8 +34,6 @@ function init() { , require('./sensorage')() , require('./insulinage')() , require('./basalprofile')() - , require('./timeago')() - , require('./upbat')() , require('./boluscalc')() // fake plugin to show/hide , require('./profile')() // fake plugin to hold extended settings ]; diff --git a/lib/plugins/openaps.js b/lib/plugins/openaps.js index 2e4b99425a0..40df965e951 100644 --- a/lib/plugins/openaps.js +++ b/lib/plugins/openaps.js @@ -71,13 +71,7 @@ function init() { } var now = moment(); - var level = levels.NONE; - if (ops.lastLoopTime.add(prefs.urgent, 'minutes').isBefore(now)) { - level = levels.URGENT; - } else if (ops.lastLoopTime.add(prefs.warn, 'minutes').isBefore(now)) { - level = levels.WARN; - } - + var level = statusLevel(ops, prefs, now); if (level >= levels.WARN) { sbx.notifications.requestNotify({ level: level @@ -98,12 +92,13 @@ function init() { info.push({label: 'Status', value: prop.status.label}); var ops = prepOps(prop, sbx); + var prefs = openaps.getPrefs(sbx); function valueString (prefix, value) { return value ? prefix + value : ''; } - function addedSuggestion() { + function addSuggestion() { info.push({ label: timeAt(false, sbx) + timeFormat(ops.suggestedTime, sbx) , value: valueString('BG: ', ops.suggested.bg) + valueString(', ', ops.suggested.reason) @@ -112,7 +107,7 @@ function init() { if ('enacted' === prop.status.code) { if (ops.suggestedTime.isAfter(ops.enactedTime)) { - addedSuggestion(); + addSuggestion(); } var canceled = ops.enacted.rate === 0 && ops.enacted.duration === 0; info.push({ @@ -125,7 +120,7 @@ function init() { ].join('') }); } else if ('looping' === prop.status.code) { - addedSuggestion(); + addSuggestion(); } else if (ops.lastLoopTime) { info.push({ label: timeAt(false, sbx) + timeFormat(ops.lastLoopTime, sbx) @@ -156,6 +151,7 @@ function init() { value: timeFormat(prop.status.when, sbx) , label: 'OpenAPS ' + prop.status.symbol , info: info + , pillClass: sbx.data.inRetroMode ? 'current' : statusClass(ops, prefs, moment(sbx.time)) }); }; @@ -163,6 +159,33 @@ function init() { } +function statusClass (ops, prefs, sbx) { + var level = statusLevel(ops, prefs, sbx); + var cls = 'current'; + + if (level === levels.WARN) { + cls = 'warn'; + } else if (level === levels.URGENT) { + cls = 'urgent'; + } + + return cls; +} + +function statusLevel (ops, prefs, now) { + var urgentTime = ops.lastLoopTime.clone().add(prefs.urgent, 'minutes'); + var warningTime = ops.lastLoopTime.clone().add(prefs.warn, 'minutes'); + + var level = levels.NONE; + if (urgentTime.isBefore(now)) { + level = levels.URGENT; + } else if (warningTime.isBefore(now)) { + level = levels.WARN; + } + + return level; +} + function checkLoopStatus (openapsStatus, sbx) { var status = {