Skip to content

Commit

Permalink
fixed monment.add bug; set status class on openaps pill; clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Dec 6, 2015
1 parent f3e6784 commit 72217e3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/plugins/index.js
Expand Up @@ -21,6 +21,8 @@ function init() {
require('./rawbg')()
, require('./delta')()
, require('./direction')()
, require('./timeago')()
, require('./upbat')()
, require('./ar2')()
, require('./errorcodes')()
, require('./iob')()
Expand All @@ -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
];
Expand Down
43 changes: 33 additions & 10 deletions lib/plugins/openaps.js
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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({
Expand All @@ -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)
Expand Down Expand Up @@ -156,13 +151,41 @@ 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))
});
};

return openaps;

}

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 = {
Expand Down

0 comments on commit 72217e3

Please sign in to comment.