mirror of
				https://github.com/house-of-abbey/GarminHomeAssistant.git
				synced 2025-11-04 00:48:14 +00:00 
			
		
		
		
	Added null checking to activity stats
Position.getInfo().* might return null sometimes, so best check and avoid a numerical error.
This commit is contained in:
		@@ -30,3 +30,4 @@
 | 
				
			|||||||
|   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. |
 | 
					|   2.17  | Bug fix for reporting activity metrics that are not found on some devices. |
 | 
				
			||||||
 | 
					|   2.18  | Bug fix for reporting activity metrics that might be `null` sometimes. This is unsimulatable situation, so this version is a change based on an informed guess. |
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,13 +79,13 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
 | 
				
			|||||||
    private function doUpdate(activity as Lang.Number or Null, sub_activity as Lang.Number or Null) {
 | 
					    private function doUpdate(activity as Lang.Number or Null, sub_activity as Lang.Number or Null) {
 | 
				
			||||||
        // System.println("BackgroundServiceDelegate onTemporalEvent(): Making API call.");
 | 
					        // System.println("BackgroundServiceDelegate onTemporalEvent(): Making API call.");
 | 
				
			||||||
        var position = Position.getInfo();
 | 
					        var position = Position.getInfo();
 | 
				
			||||||
        // System.println("BackgroundServiceDelegate onTemporalEvent(): gps: " + position.position.toDegrees());
 | 
					        // System.println("BackgroundServiceDelegate onTemporalEvent(): GPS      : " + position.position.toDegrees());
 | 
				
			||||||
        // System.println("BackgroundServiceDelegate onTemporalEvent(): speed: " + position.speed);
 | 
					        // System.println("BackgroundServiceDelegate onTemporalEvent(): Speed    : " + position.speed);
 | 
				
			||||||
        // System.println("BackgroundServiceDelegate onTemporalEvent(): course: " + position.heading + "rad (" + (position.heading * 180 / Math.PI) + "°)");
 | 
					        // System.println("BackgroundServiceDelegate onTemporalEvent(): Course   : " + position.heading + " radians (" + (position.heading * 180 / Math.PI) + "°)");
 | 
				
			||||||
        // System.println("BackgroundServiceDelegate onTemporalEvent(): altitude: " + position.altitude);
 | 
					        // System.println("BackgroundServiceDelegate onTemporalEvent(): Altitude : " + position.altitude);
 | 
				
			||||||
        // System.println("BackgroundServiceDelegate onTemporalEvent(): battery: " + System.getSystemStats().battery);
 | 
					        // System.println("BackgroundServiceDelegate onTemporalEvent(): Battery  : " + System.getSystemStats().battery);
 | 
				
			||||||
        // System.println("BackgroundServiceDelegate onTemporalEvent(): charging: " + System.getSystemStats().charging);
 | 
					        // System.println("BackgroundServiceDelegate onTemporalEvent(): Charging : " + System.getSystemStats().charging);
 | 
				
			||||||
        // System.println("BackgroundServiceDelegate onTemporalEvent(): activity: " + Activity.getProfileInfo().name);
 | 
					        // System.println("BackgroundServiceDelegate onTemporalEvent(): Activity : " + Activity.getProfileInfo().name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Don't use Settings.* here as the object lasts < 30 secs and is recreated each time the background service is run
 | 
					        // Don't use Settings.* here as the object lasts < 30 secs and is recreated each time the background service is run
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -107,11 +107,11 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                    "type" => "update_location",
 | 
					                    "type" => "update_location",
 | 
				
			||||||
                    "data" => {
 | 
					                    "data" => {
 | 
				
			||||||
                        "gps"          => position.position.toDegrees(),
 | 
					                        "gps"          => position.position == null ? [0.0, 0.0] : position.position.toDegrees(),
 | 
				
			||||||
                        "gps_accuracy" => accuracy,
 | 
					                        "gps_accuracy" => accuracy,
 | 
				
			||||||
                        "speed"        => Math.round(position.speed),
 | 
					                        "speed"        => Math.round(position.speed    == null ? 0 : position.speed),
 | 
				
			||||||
                        "course"       => Math.round(position.heading * 180 / Math.PI),
 | 
					                        "course"       => Math.round(position.heading  == null ? 0 : position.heading * 180 / Math.PI),
 | 
				
			||||||
                        "altitude"     => Math.round(position.altitude),
 | 
					                        "altitude"     => Math.round(position.altitude == null ? 0 : position.altitude),
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user