From b31aff652fbd92f8071e35f53148c8760357de4b Mon Sep 17 00:00:00 2001 From: Philip Abbey Date: Sun, 28 Jan 2024 18:54:47 +0000 Subject: [PATCH] Update BackgroundServiceDelegate.mc Amended detection of no activity reporting. --- source/BackgroundServiceDelegate.mc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source/BackgroundServiceDelegate.mc b/source/BackgroundServiceDelegate.mc index 13e72d8..bbfff4e 100644 --- a/source/BackgroundServiceDelegate.mc +++ b/source/BackgroundServiceDelegate.mc @@ -102,16 +102,24 @@ class BackgroundServiceDelegate extends System.ServiceDelegate { "unique_id" => "battery_is_charging" } ]; - if (Activity has :getProfileInfo) { - var activity = Activity.getProfileInfo().sport; + if ((Activity has :getActivityInfo) and (Activity has :getProfileInfo)) { + var activity = Activity.getProfileInfo().sport; var sub_activity = Activity.getProfileInfo().subSport; + // We need to check if we are actually tracking any activity + if (Activity.getActivityInfo().elapsedTime == 0) { + // Indicate no activity with -1, not part of Garmin's activity codes. + // https://developer.garmin.com/connect-iq/api-docs/Toybox/Activity.html#Sport-module + activity = -1; + sub_activity = -1; + } + System.println("activity = " + activity); data.add({ - "state" => activity != null ? activity : -1, + "state" => activity, "type" => "sensor", "unique_id" => "activity" }); data.add({ - "state" => sub_activity != null ? sub_activity : -1, + "state" => sub_activity, "type" => "sensor", "unique_id" => "sub_activity" });