mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-05-02 13:42:32 +00:00
Update BackgroundServiceDelegate.mc
Put check for methods with 'has' back in.
This commit is contained in:
@ -56,8 +56,11 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
|
|||||||
} else if (!System.getDeviceSettings().connectionAvailable) {
|
} else if (!System.getDeviceSettings().connectionAvailable) {
|
||||||
// System.println("BackgroundServiceDelegate onTemporalEvent(): No Internet connection, skipping API call.");
|
// System.println("BackgroundServiceDelegate onTemporalEvent(): No Internet connection, skipping API call.");
|
||||||
} else {
|
} else {
|
||||||
var activity = Activity.getProfileInfo().sport;
|
var activity = null;
|
||||||
var sub_activity = Activity.getProfileInfo().subSport;
|
var sub_activity = null;
|
||||||
|
if ((Activity has :getActivityInfo) and (Activity has :getProfileInfo)) {
|
||||||
|
activity = Activity.getProfileInfo().sport;
|
||||||
|
sub_activity = Activity.getProfileInfo().subSport;
|
||||||
// We need to check if we are actually tracking any activity as the enumerated type does not include "No Sport".
|
// We need to check if we are actually tracking any activity as the enumerated type does not include "No Sport".
|
||||||
if ((Activity.getActivityInfo() != null) and
|
if ((Activity.getActivityInfo() != null) and
|
||||||
((Activity.getActivityInfo().elapsedTime == null) or
|
((Activity.getActivityInfo().elapsedTime == null) or
|
||||||
@ -67,12 +70,13 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
|
|||||||
activity = -1;
|
activity = -1;
|
||||||
sub_activity = -1;
|
sub_activity = -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// System.println("BackgroundServiceDelegate onTemporalEvent(): Event triggered, activity = " + activity + " sub_activity = " + sub_activity);
|
// System.println("BackgroundServiceDelegate onTemporalEvent(): Event triggered, activity = " + activity + " sub_activity = " + sub_activity);
|
||||||
doUpdate(activity, sub_activity);
|
doUpdate(activity, sub_activity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function doUpdate(activity as Lang.Number, sub_activity as Lang.Number) {
|
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());
|
||||||
@ -132,12 +136,14 @@ class BackgroundServiceDelegate extends System.ServiceDelegate {
|
|||||||
"unique_id" => "battery_is_charging"
|
"unique_id" => "battery_is_charging"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
if ((Activity has :getActivityInfo) and (Activity has :getProfileInfo)) {
|
if (activity != null) {
|
||||||
data.add({
|
data.add({
|
||||||
"state" => activity,
|
"state" => activity,
|
||||||
"type" => "sensor",
|
"type" => "sensor",
|
||||||
"unique_id" => "activity"
|
"unique_id" => "activity"
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
if (sub_activity != null) {
|
||||||
data.add({
|
data.add({
|
||||||
"state" => sub_activity,
|
"state" => sub_activity,
|
||||||
"type" => "sensor",
|
"type" => "sensor",
|
||||||
|
Reference in New Issue
Block a user