mirror of
				https://github.com/house-of-abbey/GarminHomeAssistant.git
				synced 2025-11-04 00:48:14 +00:00 
			
		
		
		
	Bug fix for activity reporting
Added 'has' clauses around additional ActivityMonitor.Info fields that are not present on all devices.
This commit is contained in:
		@@ -29,3 +29,4 @@
 | 
				
			|||||||
|   2.14  | Cautionary bug fix for the background service code where refactorisation spoilt some API level guard clauses. |
 | 
					|   2.14  | Cautionary bug fix for the background service code where refactorisation spoilt some API level guard clauses. |
 | 
				
			||||||
|   2.15  | Better support for templates by isolating erroneous returns and marking the menu item. |
 | 
					|   2.15  | Better support for templates by isolating erroneous returns and marking the menu item. |
 | 
				
			||||||
|   2.16  | Bug fix for lack of phone connection when starting the application. Includes new activity reporting features from [KPWhiver](https://github.com/KPWhiver) covering steps, heart rate, floors climbed and descended, and respiration rate. |
 | 
					|   2.16  | Bug fix for lack of phone connection when starting the application. Includes new activity reporting features from [KPWhiver](https://github.com/KPWhiver) covering steps, heart rate, floors climbed and descended, and respiration rate. |
 | 
				
			||||||
 | 
					|   2.17  | Bug fix for reporting activity metrics that are not found on some devices. |
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -209,6 +209,7 @@ class WebhookManager {
 | 
				
			|||||||
    function registerWebhookSensors() {
 | 
					    function registerWebhookSensors() {
 | 
				
			||||||
        var activityInfo = ActivityMonitor.getInfo();
 | 
					        var activityInfo = ActivityMonitor.getInfo();
 | 
				
			||||||
        var heartRate    = Activity.getActivityInfo().currentHeartRate;
 | 
					        var heartRate    = Activity.getActivityInfo().currentHeartRate;
 | 
				
			||||||
 | 
					        var unavailable  = WatchUi.loadResource($.Rez.Strings.Unavailable) as Lang.String;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var sensors = [
 | 
					        var sensors = [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@@ -235,7 +236,7 @@ class WebhookManager {
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                "name"                => "Steps today",
 | 
					                "name"                => "Steps today",
 | 
				
			||||||
                "state"       => activityInfo.steps == null ? "unknown" : activityInfo.steps,
 | 
					                "state"               => activityInfo.steps == null ? unavailable : activityInfo.steps,
 | 
				
			||||||
                "type"                => "sensor",
 | 
					                "type"                => "sensor",
 | 
				
			||||||
                "unique_id"           => "steps_today",
 | 
					                "unique_id"           => "steps_today",
 | 
				
			||||||
                "icon"                => "mdi:walk",
 | 
					                "icon"                => "mdi:walk",
 | 
				
			||||||
@@ -244,39 +245,44 @@ class WebhookManager {
 | 
				
			|||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                "name"                => "Heart rate",
 | 
					                "name"                => "Heart rate",
 | 
				
			||||||
                "state"               => heartRate == null ? "unknown" : heartRate,
 | 
					                "state"               => heartRate == null ? unavailable : heartRate,
 | 
				
			||||||
                "type"                => "sensor",
 | 
					                "type"                => "sensor",
 | 
				
			||||||
                "unique_id"           => "heart_rate",
 | 
					                "unique_id"           => "heart_rate",
 | 
				
			||||||
                "icon"                => "mdi:heart-pulse",
 | 
					                "icon"                => "mdi:heart-pulse",
 | 
				
			||||||
                "unit_of_measurement" => "bpm",
 | 
					                "unit_of_measurement" => "bpm",
 | 
				
			||||||
                "state_class"         => "measurement",
 | 
					                "state_class"         => "measurement",
 | 
				
			||||||
                "disabled"            => !Settings.isSensorsLevelEnabled()
 | 
					                "disabled"            => !Settings.isSensorsLevelEnabled()
 | 
				
			||||||
            },
 | 
					            }
 | 
				
			||||||
            {
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (ActivityMonitor.Info has :floorsClimbed) {
 | 
				
			||||||
 | 
					            sensors.add({
 | 
				
			||||||
                "name"                => "Floors climbed today",
 | 
					                "name"                => "Floors climbed today",
 | 
				
			||||||
                "state"       => activityInfo.floorsClimbed == null ? "unknown" : activityInfo.floorsClimbed,
 | 
					                "state"               => activityInfo.floorsClimbed == null ? unavailable : activityInfo.floorsClimbed,
 | 
				
			||||||
                "type"                => "sensor",
 | 
					                "type"                => "sensor",
 | 
				
			||||||
                "unique_id"           => "floors_climbed_today",
 | 
					                "unique_id"           => "floors_climbed_today",
 | 
				
			||||||
                "icon"                => "mdi:stairs-up",
 | 
					                "icon"                => "mdi:stairs-up",
 | 
				
			||||||
                "state_class"         => "total",
 | 
					                "state_class"         => "total",
 | 
				
			||||||
                "disabled"            => !Settings.isSensorsLevelEnabled()
 | 
					                "disabled"            => !Settings.isSensorsLevelEnabled()
 | 
				
			||||||
            },
 | 
					            });
 | 
				
			||||||
            {
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (ActivityMonitor.Info has :floorsDescended) {
 | 
				
			||||||
 | 
					            sensors.add({
 | 
				
			||||||
                "name"                => "Floors descended today",
 | 
					                "name"                => "Floors descended today",
 | 
				
			||||||
                "state"       => activityInfo.floorsDescended == null ? "unknown" : activityInfo.floorsDescended,
 | 
					                "state"               => activityInfo.floorsDescended == null ? unavailable : activityInfo.floorsDescended,
 | 
				
			||||||
                "type"                => "sensor",
 | 
					                "type"                => "sensor",
 | 
				
			||||||
                "unique_id"           => "floors_descended_today",
 | 
					                "unique_id"           => "floors_descended_today",
 | 
				
			||||||
                "icon"                => "mdi:stairs-down",
 | 
					                "icon"                => "mdi:stairs-down",
 | 
				
			||||||
                "state_class"         => "total",
 | 
					                "state_class"         => "total",
 | 
				
			||||||
                "disabled"            => !Settings.isSensorsLevelEnabled()
 | 
					                "disabled"            => !Settings.isSensorsLevelEnabled()
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        ];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (ActivityMonitor.Info has :respirationRate) {
 | 
					        if (ActivityMonitor.Info has :respirationRate) {
 | 
				
			||||||
            sensors.add({
 | 
					            sensors.add({
 | 
				
			||||||
                "name"                => "Respiration rate",
 | 
					                "name"                => "Respiration rate",
 | 
				
			||||||
                "state"               => activityInfo.respirationRate == null ? "unknown" : activityInfo.respirationRate,
 | 
					                "state"               => activityInfo.respirationRate == null ? unavailable : activityInfo.respirationRate,
 | 
				
			||||||
                "type"                => "sensor",
 | 
					                "type"                => "sensor",
 | 
				
			||||||
                "unique_id"           => "respiration_rate",
 | 
					                "unique_id"           => "respiration_rate",
 | 
				
			||||||
                "icon"                => "mdi:lungs",
 | 
					                "icon"                => "mdi:lungs",
 | 
				
			||||||
@@ -289,6 +295,7 @@ class WebhookManager {
 | 
				
			|||||||
        if (Activity has :getProfileInfo) {
 | 
					        if (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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ((Activity.getActivityInfo() != null) and
 | 
					            if ((Activity.getActivityInfo() != null) and
 | 
				
			||||||
                ((Activity.getActivityInfo().elapsedTime == null) or
 | 
					                ((Activity.getActivityInfo().elapsedTime == null) or
 | 
				
			||||||
                    (Activity.getActivityInfo().elapsedTime == 0))) {
 | 
					                    (Activity.getActivityInfo().elapsedTime == 0))) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user