Skip to content

Commit

Permalink
Merge pull request #1363 from tidepool-org/truemetrix-checksum
Browse files Browse the repository at this point in the history
Don't deduplicate TrueMetrix BG values prior to checksum calculation (UPLOAD-522)
  • Loading branch information
gniezen authored Mar 11, 2021
2 parents 433b7db + 45bcf36 commit 33eb510
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/drivers/trividia/trueMetrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,29 @@ class TrueMetrix {
}

static filterByType(results, type) {
const filtered = _.filter(results, (result, index, self) =>
result != null &&
_.startsWith(result, type) && // check type
self.indexOf(result) === index); // remove duplicates
const filtered = _.filter(results, (result) =>
result != null && _.startsWith(result, type)); // check type
return _.map(filtered, (element) => element.slice(type.length));
}

static removeDuplicates(results) {
return _.filter(results, (result, index, self) =>
self.indexOf(result) === index); // remove duplicates
}

async getDeviceId() {
let results = await this.commandResponse(COMMANDS.IDENTIFY);
if (!_.isArray(results)) {
results = [];
}
results = results.concat(await this.commandResponse(COMMANDS.GET_SERIAL));

const modelId = TrueMetrix.filterByType(results, TYPES.MODEL);
const modelId = TrueMetrix.removeDuplicates(TrueMetrix.filterByType(results, TYPES.MODEL));
const model = MODELS[modelId];
const [serialNumber] = TrueMetrix.filterByType(results, TYPES.SERIAL);
const [serialNumber] = TrueMetrix.removeDuplicates(TrueMetrix.filterByType(results, TYPES.SERIAL));

if (modelId == null || serialNumber == null) {
if (TrueMetrix.filterByType(results, TYPES.MODEL).length > 0) {
if (model == null || serialNumber == null) {
if (modelId.length > 0) {
throw Error('Sorry, but we do not support this meter yet.');
} else {
throw Error('Failed to connect to device. Is it in the cradle?');
Expand Down Expand Up @@ -294,7 +297,7 @@ module.exports = (config) => {
results = await driver.commandResponse(COMMANDS.GET_RESULTS);
})().then(() => {
data.glucose = TrueMetrix.filterByType(results, TYPES.GLUCOSE);
[data.checksum] = TrueMetrix.filterByType(results, TYPES.CHECKSUM);
[data.checksum] = TrueMetrix.removeDuplicates(TrueMetrix.filterByType(results, TYPES.CHECKSUM));
return cb(null, data);
}).catch((error) => {
debug('Error in connect: ', error);
Expand Down

0 comments on commit 33eb510

Please sign in to comment.