[SleepLog] Trigger returning undefined for prevStatus
Affected hardware version
Bangle 1, Bangle 2
Your firmware version
2v27
The bug
I'm trying to create an app that needs the ability to see any sleep status changes, and there is a built in way to do this in sleeplog using triggers. However, with that implemented, and logging for it set up, it always returns undefined for the prevStatus object, which is quite frustrating for me. In the source code for sleeplog, I can see that it returns undefined if the status is the same as the last one, however, for me, the status changes but still returns undefined. Here's the code I use to set the trigger in a boot.js file, any help is appreciated!
Trigger code:
// first ensure that the sleeplog trigger object is available (sleeplog is enabled)
if (typeof (global.sleeplog || {}).trigger === "object") {
// then add your parameters with the function to call as object into the trigger object
sleeplog.trigger["sleepsummary"] = {
onChange: true, // false as default, if true call fn only on a status change
from: 0, // 0 as default, in ms, first time fn will be called
to: 24*60*60*1000, // 24h as default, in ms, last time fn will be called
// reference time to from & to is rounded to full minutes
fn: function(data, thisTriggerEntry) {
//Run code here
logNow("checked, prev status: "+data.previousStatus+", current status: "+data.status+", promptLastShownDay: "+require("sleepsummary").getSummaryData().promptLastShownDay);
let today = new Date().getDay();
if(require("sleepsummary").getSummaryData().promptLastShownDay!=today){
if (data.status==2&&(data.previousStatus==3||data.previousStatus==4)) {
var settings=require("sleepsummary").getSettings();
//woke up
if(settings.showMessage) showSummary();
logNow("shown")
require("sleepsummary").recordData();
}
}
} // function to be executed
};
}
Installed apps
widlock (0.08), notify (0.14), boot (0.66), alarm (0.52), mylocation (0.11), clkinfosunrise (0.05), worldclkinfo (0.01), kbmulti (0.09), tictactoe (0.03), stacker (0.03), f9lander (0.04), reply (0.03), messages (0.67), locale (0.20), files (0.08), calculator (0.08), widbthide (0.01), chess (0.06), loadingscreen (0.01), kineticscroll (0.05), clkinfocal (0.05), widanclk (0.03), barometer (0.04), 2047pp (0.04), clkshortcuts (0.01), astrocalc (0.09), zambretti (0.01), themes (0.01), qmsched (0.10), widbattpwr (0.03), clkinfostopw (0.03), wid_edit (0.05), guitar (0.03), clkinfosec (0.02), taglaunch (0.08), myprofile (0.02), clkinfodist (0.01), autoreset (0.02), activityreminder (0.12), swatch (0.07), stlap (0.04), ctrlpad (0.02), setting (0.81), health (0.37), backlite (0.02), powermanager (0.13), magnav (0.07), ios (0.21), banglexercise (0.06), modclock (0.05), clock_info (0.20), antonclk (0.12), tinydraw (0.04), textfacts (0.02), messageicons (0.10), messagegui (0.89), weather (0.31), thermom (0.07), meridian (0.01), inspire (0.03), lato (0.04), bordle (0.04), sched (0.35), fileman (0.04), widmsggrid (0.07), sleepsummary (0.01), messagesmusic (0.05), smartbatt (0.03), smpltmr (0.12), slopeclockpp (0.12), clockbg (0.08), pebblepp (0.12), drained (0.08), sleeplog (0.22), popconlaunch (0.05)
Before I dive in - could it be a typo?
https://github.com/espruino/BangleApps/blob/6fd2057782e14fc2238fe788520dd3c46e21e4c3/apps/sleeplog/boot.js#L306-L306
vs. your code above:
data.previousStatus
I had tried that just in case there was a typo in the documentation as prevStatus did not work before. It's fixed now, I think the new sleeplog version at #4023 has fixed it. Thanks for your help!
This is reopened, as we'll make a new PR to address this. I'll test this some more with the new sleeplog version anyway and see if it's fixed now.
I believe this is fixed now after some testing.