mirror of
				https://github.com/house-of-abbey/GarminHomeAssistant.git
				synced 2025-11-04 08:58:13 +00:00 
			
		
		
		
	API level fix
Added 'has' test for Activity.getProfileInfo(). Reverted automatic changes to XML prettiness. Co-Authored-By: Joseph Abbey <me@josephabbey.dev>
This commit is contained in:
		@@ -25,8 +25,7 @@
 | 
				
			|||||||
    Use "Monkey C: Edit Application" from the Visual Studio Code command palette
 | 
					    Use "Monkey C: Edit Application" from the Visual Studio Code command palette
 | 
				
			||||||
    to update the application attributes.
 | 
					    to update the application attributes.
 | 
				
			||||||
  -->
 | 
					  -->
 | 
				
			||||||
  <iq:application id="4901cdfb-b4a2-4f33-96c7-f5be5992809e" type="widget" name="@Strings.AppName"
 | 
					  <iq:application id="4901cdfb-b4a2-4f33-96c7-f5be5992809e" type="widget" name="@Strings.AppName" entry="HomeAssistantApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0">
 | 
				
			||||||
    entry="HomeAssistantApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0">
 | 
					 | 
				
			||||||
    <!--
 | 
					    <!--
 | 
				
			||||||
      Use the following from the Visual Studio Code comand palette to edit
 | 
					      Use the following from the Visual Studio Code comand palette to edit
 | 
				
			||||||
      the build targets:
 | 
					      the build targets:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,11 +28,9 @@
 | 
				
			|||||||
    Testing in VSCode requires monkey.jungle, so for convenience, swap between
 | 
					    Testing in VSCode requires monkey.jungle, so for convenience, swap between
 | 
				
			||||||
    watch-app and widget by changing which of the next two lines are commented out
 | 
					    watch-app and widget by changing which of the next two lines are commented out
 | 
				
			||||||
  -->
 | 
					  -->
 | 
				
			||||||
  <iq:application id="98c36259-498a-4458-9cef-74a273ad2bc3" type="watch-app" name="@Strings.AppName"
 | 
					  <iq:application id="98c36259-498a-4458-9cef-74a273ad2bc3" type="watch-app" name="@Strings.AppName" entry="HomeAssistantApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0">
 | 
				
			||||||
    entry="HomeAssistantApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0">
 | 
					  <!-- 
 | 
				
			||||||
    <!-- 
 | 
					  <iq:application id="4901cdfb-b4a2-4f33-96c7-f5be5992809e" type="widget" name="@Strings.AppName" entry="HomeAssistantApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0">
 | 
				
			||||||
  <iq:application id="4901cdfb-b4a2-4f33-96c7-f5be5992809e" type="widget" name="@Strings.AppName"
 | 
					 | 
				
			||||||
    entry="HomeAssistantApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0">
 | 
					 | 
				
			||||||
  -->
 | 
					  -->
 | 
				
			||||||
    <!--
 | 
					    <!--
 | 
				
			||||||
      Use the following from the Visual Studio Code comand palette to edit
 | 
					      Use the following from the Visual Studio Code comand palette to edit
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,27 +75,30 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
 | 
				
			|||||||
                },
 | 
					                },
 | 
				
			||||||
                method(:onReturnBatteryUpdate)
 | 
					                method(:onReturnBatteryUpdate)
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
					            var data = [
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "state"     => System.getSystemStats().battery,
 | 
				
			||||||
 | 
					                    "type"      => "sensor",
 | 
				
			||||||
 | 
					                    "unique_id" => "battery_level"
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    "state"     => System.getSystemStats().charging,
 | 
				
			||||||
 | 
					                    "type"      => "binary_sensor",
 | 
				
			||||||
 | 
					                    "unique_id" => "battery_is_charging"
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            ];
 | 
				
			||||||
 | 
					            if (Activity has :getProfileInfo) {
 | 
				
			||||||
 | 
					                data.add({
 | 
				
			||||||
 | 
					                    "state"     => Activity.getProfileInfo().name,
 | 
				
			||||||
 | 
					                    "type"      => "sensor",
 | 
				
			||||||
 | 
					                    "unique_id" => "activity"
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            Communications.makeWebRequest(
 | 
					            Communications.makeWebRequest(
 | 
				
			||||||
                (Properties.getValue("api_url") as Lang.String) + "/webhook/" + (Properties.getValue("webhook_id") as Lang.String),
 | 
					                (Properties.getValue("api_url") as Lang.String) + "/webhook/" + (Properties.getValue("webhook_id") as Lang.String),
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    "type" => "update_sensor_states",
 | 
					                    "type" => "update_sensor_states",
 | 
				
			||||||
                    "data" => [
 | 
					                    "data" => data
 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            "state"     => System.getSystemStats().battery,
 | 
					 | 
				
			||||||
                            "type"      => "sensor",
 | 
					 | 
				
			||||||
                            "unique_id" => "battery_level"
 | 
					 | 
				
			||||||
                        },
 | 
					 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            "state"     => System.getSystemStats().charging,
 | 
					 | 
				
			||||||
                            "type"      => "binary_sensor",
 | 
					 | 
				
			||||||
                            "unique_id" => "battery_is_charging"
 | 
					 | 
				
			||||||
                        },
 | 
					 | 
				
			||||||
                        {
 | 
					 | 
				
			||||||
                            "state"     => Activity.getProfileInfo().name,
 | 
					 | 
				
			||||||
                            "type"      => "sensor",
 | 
					 | 
				
			||||||
                            "unique_id" => "activity"
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    ]
 | 
					 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    :method       => Communications.HTTP_REQUEST_METHOD_POST,
 | 
					                    :method       => Communications.HTTP_REQUEST_METHOD_POST,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -182,14 +182,16 @@ class WebhookManager {
 | 
				
			|||||||
                            break;
 | 
					                            break;
 | 
				
			||||||
                        case 1:
 | 
					                        case 1:
 | 
				
			||||||
                            // System.println("WebhookManager onReturnRegisterWebhookSensor(): Registering next sensor: Activity");
 | 
					                            // System.println("WebhookManager onReturnRegisterWebhookSensor(): Registering next sensor: Activity");
 | 
				
			||||||
                            registerWebhookSensor({
 | 
					                            if (Activity has :getProfileInfo) {
 | 
				
			||||||
                                "name"                => "Activity",
 | 
					                                registerWebhookSensor({
 | 
				
			||||||
                                "state"               => Activity.getProfileInfo().name,
 | 
					                                    "name"                => "Activity",
 | 
				
			||||||
                                "type"                => "sensor",
 | 
					                                    "state"               => Activity.getProfileInfo().name,
 | 
				
			||||||
                                "unique_id"           => "activity",
 | 
					                                    "type"                => "sensor",
 | 
				
			||||||
                                "disabled"            => false
 | 
					                                    "unique_id"           => "activity",
 | 
				
			||||||
                            }, 2);
 | 
					                                    "disabled"            => false
 | 
				
			||||||
                            break;
 | 
					                                }, 2);
 | 
				
			||||||
 | 
					                                break;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
                        default:
 | 
					                        default:
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user