Resolves#413 Handling removed mobile_app integration
This commit is contained in:
parent
fadfefd836
commit
7ca4b02e6d
@ -147,45 +147,37 @@ class HomeAssistant {
|
|||||||
includeAuthHeader: false,
|
includeAuthHeader: false,
|
||||||
data: json.encode(updateData)
|
data: json.encode(updateData)
|
||||||
).then((response) {
|
).then((response) {
|
||||||
Logger.d("App registration works fine");
|
if (response == null || response.isEmpty) {
|
||||||
if (showOkDialog) {
|
Logger.d("No registration data in response. MobileApp integration was removed");
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
_askToRegisterApp();
|
||||||
title: "All good",
|
} else {
|
||||||
body: "HA Client integration with your Home Assistant server works fine",
|
Logger.d("App registration works fine");
|
||||||
positiveText: "Nice!",
|
if (showOkDialog) {
|
||||||
negativeText: "Ok"
|
eventBus.fire(ShowPopupDialogEvent(
|
||||||
));
|
title: "All good",
|
||||||
|
body: "HA Client integration with your Home Assistant server works fine",
|
||||||
|
positiveText: "Nice!",
|
||||||
|
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");
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
_askToRegisterApp();
|
||||||
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.",
|
|
||||||
positiveText: "Register now",
|
|
||||||
negativeText: "Cancel",
|
|
||||||
onPositive: () {
|
|
||||||
SharedPreferences.getInstance().then((prefs) {
|
|
||||||
prefs.remove("app-webhook-id");
|
|
||||||
Connection().webhookId = null;
|
|
||||||
HomeAssistant().checkAppRegistration();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
Logger.e("Error updating app registration: ${e.toString()}");
|
Logger.e("Error updating app registration: ${e.toString()}");
|
||||||
eventBus.fire(ShowPopupDialogEvent(
|
eventBus.fire(ShowPopupDialogEvent(
|
||||||
title: "App integration is not working properly",
|
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.",
|
body: "Something wrong with HA Client integration on your Home Assistant server. Please report this issue.",
|
||||||
positiveText: "Ok",
|
positiveText: "Report to GitHub",
|
||||||
negativeText: "I'll handle it",
|
negativeText: "Report to Discord",
|
||||||
onPositive: () {
|
onPositive: () {
|
||||||
SharedPreferences.getInstance().then((prefs) {
|
HAUtils.launchURL("https://github.com/estevez-dev/ha_client/issues/new");
|
||||||
prefs.remove("app-webhook-id");
|
},
|
||||||
Connection().webhookId = null;
|
onNegative: () {
|
||||||
HAUtils.launchURL(Connection().httpWebHost+"/config/integrations/dashboard");
|
HAUtils.launchURL("https://discord.gg/AUzEvwn");
|
||||||
});
|
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -195,6 +187,22 @@ class HomeAssistant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _askToRegisterApp() {
|
||||||
|
eventBus.fire(ShowPopupDialogEvent(
|
||||||
|
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.",
|
||||||
|
positiveText: "Register now",
|
||||||
|
negativeText: "Cancel",
|
||||||
|
onPositive: () {
|
||||||
|
SharedPreferences.getInstance().then((prefs) {
|
||||||
|
prefs.remove("app-webhook-id");
|
||||||
|
Connection().webhookId = null;
|
||||||
|
HomeAssistant().checkAppRegistration();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Future _getConfig() async {
|
Future _getConfig() async {
|
||||||
await Connection().sendSocketMessage(type: "get_config").then((data) {
|
await Connection().sendSocketMessage(type: "get_config").then((data) {
|
||||||
_instanceConfig = Map.from(data);
|
_instanceConfig = Map.from(data);
|
||||||
|
Reference in New Issue
Block a user