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

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