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:
Philip Abbey
2024-01-27 13:57:21 +00:00
parent 1ec80a1704
commit 4ff1509046
4 changed files with 34 additions and 32 deletions

View File

@ -25,8 +25,7 @@
Use "Monkey C: Edit Application" from the Visual Studio Code command palette
to update the application attributes.
-->
<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
the build targets:

View File

@ -28,11 +28,9 @@
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
-->
<iq:application id="98c36259-498a-4458-9cef-74a273ad2bc3" type="watch-app" 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">
<iq:application id="98c36259-498a-4458-9cef-74a273ad2bc3" type="watch-app" 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

View File

@ -75,27 +75,30 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
},
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(
(Properties.getValue("api_url") as Lang.String) + "/webhook/" + (Properties.getValue("webhook_id") as Lang.String),
{
"type" => "update_sensor_states",
"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"
}
]
"data" => data
},
{
:method => Communications.HTTP_REQUEST_METHOD_POST,

View File

@ -182,14 +182,16 @@ class WebhookManager {
break;
case 1:
// System.println("WebhookManager onReturnRegisterWebhookSensor(): Registering next sensor: Activity");
registerWebhookSensor({
"name" => "Activity",
"state" => Activity.getProfileInfo().name,
"type" => "sensor",
"unique_id" => "activity",
"disabled" => false
}, 2);
break;
if (Activity has :getProfileInfo) {
registerWebhookSensor({
"name" => "Activity",
"state" => Activity.getProfileInfo().name,
"type" => "sensor",
"unique_id" => "activity",
"disabled" => false
}, 2);
break;
}
default:
}
} else {