@@ -160,26 +160,36 @@ class WebhookManager {
160
160
161
161
case 200 :
162
162
case 201 :
163
- var d = data as Lang .Dictionary ;
164
- if ((d .get (" success" ) as Lang .Boolean or Null ) != false ) {
165
- if (sensors .size () == 0 ) {
166
- getApp ().startUpdates ();
163
+ if (data instanceof Lang .Dictionary ) {
164
+ var d = data as Lang .Dictionary ;
165
+ var b = d .get (" success" ) as Lang .Boolean or Null ;
166
+ if (b != null and b != false ) {
167
+ if (sensors .size () == 0 ) {
168
+ getApp ().startUpdates ();
169
+ } else {
170
+ registerWebhookSensor (sensors );
171
+ }
167
172
} else {
168
- registerWebhookSensor (sensors );
173
+ // System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure, no 'success'.");
174
+ Settings .unsetWebhookId ();
175
+ Settings .unsetIsSensorsLevelEnabled ();
176
+ ErrorView .show (WatchUi .loadResource ($ .Rez .Strings .WebhookFailed ) as Lang .String );
169
177
}
170
178
} else {
171
- // System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure");
179
+ // !! Speculative code for an application crash !!
180
+ // System.println("WebhookManager onReturnRegisterWebhookSensor(): Failure, not a Lang.Dict");
181
+ // Webhook ID might have been deleted on Home Assistant server and a Lang.String is trying to tell us an error message
172
182
Settings .unsetWebhookId ();
173
183
Settings .unsetIsSensorsLevelEnabled ();
174
- ErrorView .show (WatchUi .loadResource ($ .Rez .Strings .WebhookFailed ) as Lang .String );
184
+ ErrorView .show (WatchUi .loadResource ($ .Rez .Strings .WebhookFailed ) as Lang .String + " \n " + data . toString () );
175
185
}
176
186
break ;
177
187
178
188
default :
179
189
// System.println("WebhookManager onReturnRequestWebhookId(): Unhandled HTTP response code = " + responseCode);
180
190
Settings .unsetWebhookId ();
181
191
Settings .unsetIsSensorsLevelEnabled ();
182
- ErrorView .show (WatchUi .loadResource ($ .Rez .Strings .WebhookFailed ) as Lang .String + " \n " + WatchUi .loadResource ($ .Rez .Strings .UnhandledHttpErr ) as Lang .String + responseCode );
192
+ ErrorView .show (WatchUi .loadResource ($ .Rez .Strings .WebhookFailed ) as Lang .String + " \n " + WatchUi .loadResource ($ .Rez .Strings .UnhandledHttpErr ) as Lang .String + " " + responseCode );
183
193
}
184
194
}
185
195
0 commit comments