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 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:

View File

@ -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

View File

@ -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,

View File

@ -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 {