Skip to content

Commit 505e375

Browse files
committed
Fix mmol BG display in OpenAPS tooltips
1 parent eb10594 commit 505e375

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

lib/plugins/openaps.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
var _ = require('lodash');
44
var times = require('../times');
5-
var consts = require('../constants');
65

76
// var ALL_STATUS_FIELDS = ['status-symbol', 'status-label', 'iob', 'meal-assist', 'freq', 'rssi']; Unused variable
87

@@ -387,16 +386,15 @@ function init (ctx) {
387386
return value ? prefix + value : '';
388387
}
389388

389+
function displayBg (bg) {
390+
return sbx.roundBGToDisplayFormat(sbx.scaleMgdl(bg));
391+
}
392+
390393
var events = [];
391394

392395
function addSuggestion () {
393396
if (prop.lastSuggested) {
394-
var bg = prop.lastSuggested.bg;
395-
var units = sbx.settings.units;
396-
397-
if (units === 'mmol') {
398-
bg = Math.round(bg / consts.MMOL_TO_MGDL * 10) / 10;
399-
}
397+
var bg = displayBg(prop.lastSuggested.bg);
400398

401399
var valueParts = [
402400
valueString('BG: ', bg)
@@ -478,12 +476,7 @@ function init (ctx) {
478476

479477
if ('enacted' === prop.status.code) {
480478
var canceled = prop.lastEnacted.rate === 0 && prop.lastEnacted.duration === 0;
481-
var bg = prop.lastEnacted.bg;
482-
var units = sbx.settings.units;
483-
484-
if (units === 'mmol') {
485-
bg = Math.round(bg / consts.MMOL_TO_MGDL * 10) / 10;
486-
}
479+
var bg = displayBg(prop.lastEnacted.bg);
487480

488481
var valueParts = [
489482
valueString('BG: ', bg)

lib/report_plugins/daytoday.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio
303303
.on('mouseover', function(d) {
304304
if (options.openAps && d.openaps) {
305305
client.tooltip.style('display', 'block');
306-
var text = '<b>BG:</b> ' + d.openaps.suggested.bg +
306+
var bg = client.utils.roundBGForDisplay(client.utils.scaleMgdl(d.openaps.suggested.bg));
307+
var text = '<b>BG:</b> ' + bg +
307308
', ' + d.openaps.suggested.reason +
308309
(d.openaps.suggested.mealAssist ? ' <b>Meal Assist:</b> ' + d.openaps.suggested.mealAssist : '');
309310
client.tooltip.html(text)

tests/openaps.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,34 @@ describe('openaps', function ( ) {
297297

298298
});
299299

300+
it('format OpenAPS pill BG in mmol when display units are mmol', function (done) {
301+
var ctx = {
302+
settings: {
303+
units: 'mmol'
304+
}
305+
, pluginBase: {
306+
updatePillText: function mockedUpdatePillText (plugin, options) {
307+
var bgEvent = _.find(options.info, function(entry) {
308+
return entry.value.indexOf('BG: ') === 0;
309+
});
310+
311+
should.exist(bgEvent);
312+
bgEvent.value.should.startWith('BG: 8.2');
313+
bgEvent.value.should.not.startWith('BG: 147');
314+
}
315+
, addForecastPoints: function mockAddForecastPoints () {
316+
done();
317+
}
318+
}
319+
, language: language
320+
};
321+
322+
var sbx = sandbox.clientInit(ctx, now.valueOf(), {devicestatus: statuses});
323+
324+
openaps.setProperties(sbx);
325+
openaps.updateVisualisation(sbx);
326+
});
327+
300328
it('check the recieved flag to see if it was received', function (done) {
301329
var ctx = {
302330
settings: {

0 commit comments

Comments
 (0)