mirror of
https://github.com/house-of-abbey/GarminHomeAssistant.git
synced 2025-04-30 12:42:27 +00:00
Update WebhookManager.mc (#179)
Speculative fix to handle the callback data from webhook generation perhaps not being Lang.Dict.
This commit is contained in:
@ -160,18 +160,28 @@ class WebhookManager {
|
|||||||
|
|
||||||
case 200:
|
case 200:
|
||||||
case 201:
|
case 201:
|
||||||
var d = data as Lang.Dictionary;
|
if (data instanceof Lang.Dictionary) {
|
||||||
if ((d.get("success") as Lang.Boolean or Null) != false) {
|
var d = data as Lang.Dictionary;
|
||||||
if (sensors.size() == 0) {
|
var b = d.get("success") as Lang.Boolean or Null;
|
||||||
getApp().startUpdates();
|
if (b != null and b != false) {
|
||||||
|
if (sensors.size() == 0) {
|
||||||
|
getApp().startUpdates();
|
||||||
|
} else {
|
||||||
|
registerWebhookSensor(sensors);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
registerWebhookSensor(sensors);
|
// System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure, no 'success'.");
|
||||||
|
Settings.unsetWebhookId();
|
||||||
|
Settings.unsetIsSensorsLevelEnabled();
|
||||||
|
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure");
|
// !! Speculative code for an application crash !!
|
||||||
|
// System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure, not a Lang.Dict");
|
||||||
|
// Webhook ID might have been deleted on Home Assistant server and a Lang.String is trying to tell us an error message
|
||||||
Settings.unsetWebhookId();
|
Settings.unsetWebhookId();
|
||||||
Settings.unsetIsSensorsLevelEnabled();
|
Settings.unsetIsSensorsLevelEnabled();
|
||||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String);
|
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + data.toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -179,7 +189,7 @@ class WebhookManager {
|
|||||||
// System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
|
// System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
|
||||||
Settings.unsetWebhookId();
|
Settings.unsetWebhookId();
|
||||||
Settings.unsetIsSensorsLevelEnabled();
|
Settings.unsetIsSensorsLevelEnabled();
|
||||||
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + responseCode);
|
ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + WatchUi.loadResource($.Rez.Strings.UnhandledHttpErr) as Lang.String + " " + responseCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user