Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix/improve error handling #205

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,16 @@ let dataToSend = {
steps: userActivity.get().steps,
};
dismiss.onclick = function (evt) {
console.log("DISMISS");
popup.style.display = "none";
popupTitle.style.display = "none";
vibration.stop();
DISABLE_ALERTS = true;
let currentBgFromBloodSugars = getFistBgNonpredictiveBG(data.bloodSugars.bgs);

if (currentBgFromBloodSugars.sgv >= parseInt(data.settings.highThreshold)) {
console.log("HIGH " + dismissHighFor);
setTimeout(disableAlertsFalse, dismissHighFor * 1000 * 60);
} else {
// 15 mins
console.log("LOW " + dismissLowFor);

setTimeout(disableAlertsFalse, dismissLowFor * 1000 * 60);
}
Expand Down Expand Up @@ -140,7 +137,6 @@ largeGraphTime.text = dateTime.getTime();
batteryLevel.width = batteryLevels.get().level;

inbox.onnewfile = () => {
console.log("New file!");
let fileName;
do {
// If there is a file, move it from staging into the application folder
Expand All @@ -153,8 +149,6 @@ inbox.onnewfile = () => {
};

function update() {
console.log("app - update()");
console.warn("JS memory: " + memory.js.used + "/" + memory.js.total);
let heartrate = userActivity.get().heartRate;
if (!heartrate) {
heartrate = 0;
Expand All @@ -166,7 +160,6 @@ function update() {
};

if (data) {
console.warn("GOT DATA");
batteryLevel.width = batteryLevels.get().level;
batteryLevel.style.fill = batteryLevels.get().color;
batteryPercent.text = "" + batteryLevels.get().percent + "%";
Expand Down Expand Up @@ -315,7 +308,6 @@ function update() {
currentBgFromBloodSugars.sgv < parseInt(data.settings.highThreshold)
) {
// if the BG is between the threshold
console.error("here", DISABLE_ALERTS, parseInt(timeSenseLastSGV, 10));
disableAlertsFalse();
}
}
Expand Down Expand Up @@ -420,21 +412,18 @@ function setTextColor(color) {
}

goToLargeGraph.onclick = (e) => {
console.log("goToLargeGraph Activated!");
vibration.start("bump");
largeGraphView.style.display = "inline";
main.style.display = "none";
};

exitLargeGraph.onclick = (e) => {
console.log("exitLargeGraph Activated!");
vibration.start("bump");
largeGraphView.style.display = "none";
main.style.display = "inline";
};

timeElement.onclick = (e) => {
console.log("FORCE Activated!");
transfer.send(dataToSend);
vibration.start("bump");
arrows.href = "../resources/img/arrows/loading.png";
Expand Down
88 changes: 57 additions & 31 deletions companion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*
* ------------------------------------------------
*/
import { localStorage } from "local-storage";

import { settingsStorage } from "settings";

Expand Down Expand Up @@ -53,84 +54,109 @@ async function sendData() {
let dexcomUsername = store.dexcomUsername
? store.dexcomUsername.replace(/\s+/g, "")
: "";

let dexcomPassword = store.dexcomPassword
? store.dexcomPassword.replace(/\s+/g, "")
: "";
let sessionId = await dexcom.getSessionId(
dexcomUsername,
dexcomPassword,
subDomain
);

if (store.dexcomUsername && store.dexcomPassword) {
bloodsugars = await dexcom.getData(sessionId, subDomain);
try {
let sessionId = await dexcom.getSessionId(
dexcomUsername,
dexcomPassword,
subDomain
)
if (sessionId) {
bloodsugars = await dexcom.getData(sessionId, subDomain);
}
} catch (e) {
// Error with auth
let status = e?.Code
let message = e?.Message
if (e?.Code === "AccountPasswordInvalid") {
status = "ATH"
message = e?.Code
}
bloodsugars = {
error: {
status: status,
message: message
},
};
}
} else {
bloodsugars = {
error: {
status: "500",
status: "DM",
message: "Dexcom auth missing"
},
};
}
} else {
bloodsugars = await fetch.get(store.url);
await fetch.get(store.url).then((res) => {
bloodsugars = res
}).catch((err) => {
bloodsugars = {
error: {
status: err.status,
},
};
})
if (store.extraDataUrl) {
extraData = await fetch.get(store.extraDataUrl);
}
}


// Get weather data
// let weather = await fetch.get(await weatherURL.get(store.tempType));
Promise.all([bloodsugars, extraData]).then(function (values) {
let dataToSend = {
bloodSugars: standardize.bloodsugars(values[0], values[1], store),
settings: standardize.settings(store),
// weather: values[2].query.results.channel.item.condition,
};
logs.add(
"Line 59: companion - sendData - DataToSend size: " +
sizeof.size(dataToSend) +
" bytes"
);
logs.add(
"Line 60: companion - sendData - DataToSend: " +
JSON.stringify(dataToSend)
);
transfer.send(dataToSend);
});
let dataToSend = {
bloodSugars: standardize.bloodsugars(bloodsugars, extraData, store),
settings: standardize.settings(store),
// weather: values[2].query.results.channel.item.condition,
};


transfer.send(dataToSend);
}

// Listen for messages from the device
messaging.peerSocket.onmessage = function (evt) {
if (evt.data.command === "forceCompanionTransfer") {
logs.add("Line 58: companion - Watch to Companion Transfer request");
// pass in data that was recieved from the watch
console.log(JSON.stringify(evt.data.data));
dataReceivedFromWatch = evt.data.data;
sendData();
}
};

// Listen for the onerror event
messaging.peerSocket.onerror = function (err) {
// Handle any errors
console.log("Connection error: " + err.code + " - " + err.message);
// TODO: Handle errors
console.error("Connection error: " + err.code + " - " + err.message);
};

settingsStorage.onchange = function (evt) {
logs.add("Line 70: companion - Settings changed send to watch");
sendData();
let data = JSON.parse(evt.newValue);
logs.add(`Line 70: companion - Settings changed send to watch ${evt.newValue}`);

if (evt.key === "authorizationCode") {
// Settings page sent us an oAuth token
let data = JSON.parse(evt.newValue);
dexcom.getAccessToken(data.name);
}

// This is a way to reset the timeout if it gets messed up in testing
if (data.name === "Resyncing") {
localStorage.removeItem("timeout")
}
};

const MINUTE = 1000 * 60;
me.wakeInterval = 5 * MINUTE;

if (me.launchReasons.wokenUp) {
// The companion started due to a periodic timer
console.error("Started due to wake interval!");
sendData();
} else {
// Close the companion and wait to be awoken
Expand Down
7 changes: 0 additions & 7 deletions modules/app/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default class alerts {

alertArrows.href = "../resources/img/arrows/" + bg.direction + ".png";
alertArrows.style.display = "inline";
console.log("app - Alerts - Check()");
sgv.style.fill = "#75bd78";
largeGraphsSgv.style.fill = "#75bd78";
errorLine.style.fill = "#75bd78";
Expand All @@ -54,7 +53,6 @@ export default class alerts {
if (!DISABLE_ALERTS) {
if (settings.lowAlerts) {
if (timeSenseLastSGV <= 8) {
console.log("low BG");
vibration.start("ring");
popup.style.display = "inline";
popupTitle.style.display = "inline";
Expand All @@ -75,7 +73,6 @@ export default class alerts {
if (!DISABLE_ALERTS) {
if (settings.highAlerts) {
if (timeSenseLastSGV <= 8) {
console.log("high BG");
vibration.start("ring");
popup.style.display = "inline";
popupTitle.style.display = "inline";
Expand Down Expand Up @@ -106,7 +103,6 @@ export default class alerts {
if (!settings.disableAlert) {
if (!DISABLE_ALERTS) {
if (settings.loopstatus) {
console.log("loopstatus");
alertArrows.style.display = "none";
popupTitle.style.fill = "#de4430";
vibration.start("ring");
Expand All @@ -125,7 +121,6 @@ export default class alerts {
if (!DISABLE_ALERTS) {
if (settings.rapidFall) {
alertArrows.style.display = "none";
console.log("Double Down");
popupTitle.style.fill = "#de4430";
vibration.start("ring");
popup.style.display = "inline";
Expand All @@ -139,7 +134,6 @@ export default class alerts {
if (!DISABLE_ALERTS) {
if (settings.rapidRise) {
alertArrows.style.display = "none";
console.log("Double Up");
popupTitle.style.fill = "#de4430";
vibration.start("ring");
popup.style.display = "inline";
Expand Down Expand Up @@ -167,7 +161,6 @@ export default class alerts {
}
}
stop() {
console.log("app - Alerts - stop()");
vibration.stop();
}
}
7 changes: 3 additions & 4 deletions modules/app/batteryLevels.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@

import { charger, battery } from "power";

export default class batteryLevels {
export default class batteryLevels {
get() {
console.log('app - batteryLevels - get()')
let percent = Math.floor(battery.chargeLevel)
let level = .3 * percent;
let color = '#75bd78';
if(percent <= 30 && percent >= 15) {
if (percent <= 30 && percent >= 15) {
color = 'orange';
} else if( percent <= 15) {
} else if (percent <= 15) {
color = 'red';
}
return {
Expand Down
Loading