Using System.getDeviceSettings().activityTrackingOn

Instead of activity elapsed time. Also forgot to update the WebhookManager class code.
This commit is contained in:
Philip Abbey
2024-01-28 19:52:20 +00:00
parent 66193f080a
commit 55423c4eb7
2 changed files with 21 additions and 8 deletions

View File

@ -105,8 +105,9 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
if ((Activity has :getActivityInfo) and (Activity has :getProfileInfo)) { if ((Activity has :getActivityInfo) and (Activity has :getProfileInfo)) {
var activity = Activity.getProfileInfo().sport; var activity = Activity.getProfileInfo().sport;
var sub_activity = Activity.getProfileInfo().subSport; var sub_activity = Activity.getProfileInfo().subSport;
// We need to check if we are actually tracking any activity // We need to check if we are actually tracking any activity as the enumerated type does not include "No Sport".
if (Activity.getActivityInfo().elapsedTime == 0) { System.println("activityTrackingOn = " + System.getDeviceSettings().activityTrackingOn);
if (!System.getDeviceSettings().activityTrackingOn) {
// Indicate no activity with -1, not part of Garmin's activity codes. // 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 // https://developer.garmin.com/connect-iq/api-docs/Toybox/Activity.html#Sport-module
activity = -1; activity = -1;

View File

@ -95,18 +95,20 @@ class WebhookManager {
function requestWebhookId() { function requestWebhookId() {
// System.println("WebhookManager requestWebhookId(): Requesting webhook id"); // System.println("WebhookManager requestWebhookId(): Requesting webhook id");
var deviceSettings = System.getDeviceSettings();
Communications.makeWebRequest( Communications.makeWebRequest(
Settings.getApiUrl() + "/mobile_app/registrations", Settings.getApiUrl() + "/mobile_app/registrations",
{ {
"device_id" => System.getDeviceSettings().uniqueIdentifier, "device_id" => deviceSettings.uniqueIdentifier,
"app_id" => "garmin_home_assistant", "app_id" => "garmin_home_assistant",
"app_name" => WatchUi.loadResource($.Rez.Strings.AppName) as Lang.String, "app_name" => WatchUi.loadResource($.Rez.Strings.AppName) as Lang.String,
"app_version" => "", "app_version" => "",
"device_name" => "Garmin Watch", "device_name" => "Garmin Device",
"manufacturer" => "Garmin", "manufacturer" => "Garmin",
"model" => "", // An unhelpful part number that can be translated to a familiar model name.
"model" => deviceSettings.partNumber,
"os_name" => "", "os_name" => "",
"os_version" => Lang.format("$1$.$2$", System.getDeviceSettings().firmwareVersion), "os_version" => Lang.format("$1$.$2$", deviceSettings.firmwareVersion),
"supports_encryption" => false, "supports_encryption" => false,
"app_data" => {} "app_data" => {}
}, },
@ -184,9 +186,14 @@ class WebhookManager {
// System.println("WebhookManager onReturnRegisterWebhookSensor(): Registering next sensor: Activity"); // System.println("WebhookManager onReturnRegisterWebhookSensor(): Registering next sensor: Activity");
if (Activity has :getProfileInfo) { if (Activity has :getProfileInfo) {
var activity = Activity.getProfileInfo().sport; var activity = Activity.getProfileInfo().sport;
if (!System.getDeviceSettings().activityTrackingOn) {
// 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;
}
registerWebhookSensor({ registerWebhookSensor({
"name" => "Activity", "name" => "Activity",
"state" => activity != null ? activity : -1, "state" => activity,
"type" => "sensor", "type" => "sensor",
"unique_id" => "activity", "unique_id" => "activity",
"disabled" => false "disabled" => false
@ -197,9 +204,14 @@ class WebhookManager {
// System.println("WebhookManager onReturnRegisterWebhookSensor(): Registering next sensor: Activity"); // System.println("WebhookManager onReturnRegisterWebhookSensor(): Registering next sensor: Activity");
if (Activity has :getProfileInfo) { if (Activity has :getProfileInfo) {
var sub_activity = Activity.getProfileInfo().subSport; var sub_activity = Activity.getProfileInfo().subSport;
if (!System.getDeviceSettings().activityTrackingOn) {
// 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
sub_activity = -1;
}
registerWebhookSensor({ registerWebhookSensor({
"name" => "Sub-activity", "name" => "Sub-activity",
"state" => sub_activity != null ? sub_activity : -1, "state" => sub_activity,
"type" => "sensor", "type" => "sensor",
"unique_id" => "sub_activity", "unique_id" => "sub_activity",
"disabled" => false "disabled" => false