Resolves#413 Handling removed mobile_app integration
This commit is contained in:
parent
fadfefd836
commit
7ca4b02e6d
@ -147,6 +147,10 @@ class HomeAssistant {
|
|||||||
includeAuthHeader: false,
|
includeAuthHeader: false,
|
||||||
data: json.encode(updateData)
|
data: json.encode(updateData)
|
||||||
).then((response) {
|
).then((response) {
|
||||||
|
if (response == null || response.isEmpty) {
|
||||||
|
Logger.d("No registration data in response. MobileApp integration was removed");
|
||||||
|
_askToRegisterApp();
|
||||||
|
} else {
|
||||||
Logger.d("App registration works fine");
|
Logger.d("App registration works fine");
|
||||||
if (showOkDialog) {
|
if (showOkDialog) {
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupDialogEvent(
|
||||||
@ -156,10 +160,34 @@ class HomeAssistant {
|
|||||||
negativeText: "Ok"
|
negativeText: "Ok"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
completer.complete();
|
completer.complete();
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
if (e['code'] != null && e['code'] == 410) {
|
if (e['code'] != null && e['code'] == 410) {
|
||||||
Logger.e("MobileApp integration was removed");
|
Logger.e("MobileApp integration was removed");
|
||||||
|
_askToRegisterApp();
|
||||||
|
} else {
|
||||||
|
Logger.e("Error updating app registration: ${e.toString()}");
|
||||||
|
eventBus.fire(ShowPopupDialogEvent(
|
||||||
|
title: "App integration is not working properly",
|
||||||
|
body: "Something wrong with HA Client integration on your Home Assistant server. Please report this issue.",
|
||||||
|
positiveText: "Report to GitHub",
|
||||||
|
negativeText: "Report to Discord",
|
||||||
|
onPositive: () {
|
||||||
|
HAUtils.launchURL("https://github.com/estevez-dev/ha_client/issues/new");
|
||||||
|
},
|
||||||
|
onNegative: () {
|
||||||
|
HAUtils.launchURL("https://discord.gg/AUzEvwn");
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
completer.complete();
|
||||||
|
});
|
||||||
|
return completer.future;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _askToRegisterApp() {
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupDialogEvent(
|
||||||
title: "App integration was removed",
|
title: "App integration was removed",
|
||||||
body: "Looks like app integration was removed from your Home Assistant. HA Client needs to be registered on your Home Assistant server to make it possible to use notifications and other useful stuff.",
|
body: "Looks like app integration was removed from your Home Assistant. HA Client needs to be registered on your Home Assistant server to make it possible to use notifications and other useful stuff.",
|
||||||
@ -173,26 +201,6 @@ class HomeAssistant {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
} else {
|
|
||||||
Logger.e("Error updating app registration: ${e.toString()}");
|
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
|
||||||
title: "App integration is not working properly",
|
|
||||||
body: "Something wrong with HA Client integration on your Home Assistant server. Try to remove current app integration from Configuration -> Integrationds using web UI, restart your Home Assistant and go back to the app. NOTE that after clicking 'Ok' current integration data will be removed from the app and new integration wll be created on Home Assistant side on next app launch.",
|
|
||||||
positiveText: "Ok",
|
|
||||||
negativeText: "I'll handle it",
|
|
||||||
onPositive: () {
|
|
||||||
SharedPreferences.getInstance().then((prefs) {
|
|
||||||
prefs.remove("app-webhook-id");
|
|
||||||
Connection().webhookId = null;
|
|
||||||
HAUtils.launchURL(Connection().httpWebHost+"/config/integrations/dashboard");
|
|
||||||
});
|
|
||||||
},
|
|
||||||
));
|
|
||||||
}
|
|
||||||
completer.complete();
|
|
||||||
});
|
|
||||||
return completer.future;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _getConfig() async {
|
Future _getConfig() async {
|
||||||
|
Reference in New Issue
Block a user