mirror of
				https://github.com/house-of-abbey/GarminHomeAssistant.git
				synced 2025-11-04 00:48:14 +00:00 
			
		
		
		
	Update WebhookManager.mc
Speculative fix to handle the callback data from webhook generation perhaps not being Lang.Dict.
This commit is contained in:
		@@ -160,26 +160,36 @@ class WebhookManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            case 200:
 | 
					            case 200:
 | 
				
			||||||
            case 201:
 | 
					            case 201:
 | 
				
			||||||
 | 
					                if (data instanceof Lang.Dictionary) {
 | 
				
			||||||
                    var d = data as Lang.Dictionary;
 | 
					                    var d = data as Lang.Dictionary;
 | 
				
			||||||
                if ((d.get("success") as Lang.Boolean or Null) != false) {
 | 
					                    var b = d.get("success") as Lang.Boolean or Null;
 | 
				
			||||||
 | 
					                    if (b != null and b != false) {
 | 
				
			||||||
                        if (sensors.size() == 0) {
 | 
					                        if (sensors.size() == 0) {
 | 
				
			||||||
                            getApp().startUpdates();
 | 
					                            getApp().startUpdates();
 | 
				
			||||||
                        } else {
 | 
					                        } else {
 | 
				
			||||||
                            registerWebhookSensor(sensors);
 | 
					                            registerWebhookSensor(sensors);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    } else {
 | 
					                    } else {
 | 
				
			||||||
                    // System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure");
 | 
					                        // System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure, no 'success'.");
 | 
				
			||||||
                        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);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    // !! 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.unsetIsSensorsLevelEnabled();
 | 
				
			||||||
 | 
					                    ErrorView.show(WatchUi.loadResource($.Rez.Strings.WebhookFailed) as Lang.String + "\n" + data.toString());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                // 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