Resolves #523 Change device name for integration

This commit is contained in:
Yegor Vialov
2020-05-03 13:36:40 +00:00
parent a87943da27
commit 536cbf9445
4 changed files with 130 additions and 113 deletions

View File

@ -23,12 +23,12 @@ class MobileAppIntegrationManager {
return '${HomeAssistant().userName}\'s ${DeviceInfoManager().model}';
}
static Future checkAppRegistration({bool forceRegister: false, bool showOkDialog: false}) {
static Future checkAppRegistration({bool showOkDialog: false}) {
Completer completer = Completer();
_appRegistrationData["device_name"] = ConnectionManager().mobileAppDeviceName ?? getDefaultDeviceName();
(_appRegistrationData["app_data"] as Map)["push_token"] = "${HomeAssistant().fcmToken}";
if (ConnectionManager().webhookId == null || forceRegister) {
Logger.d("Mobile app was not registered yet or need to be reseted. Registering...");
if (ConnectionManager().webhookId == null) {
Logger.d("Mobile app was not registered yet. Registering...");
var registrationData = Map.from(_appRegistrationData);
registrationData.addAll({
"device_id": "${DeviceInfoManager().unicDeviceId}",
@ -86,7 +86,7 @@ class MobileAppIntegrationManager {
registrationData = null;
}
if (registrationData == null || registrationData.isEmpty) {
Logger.d("No registration data in response. MobileApp integration was removed or broken");
Logger.e("No registration data in response. MobileApp integration was removed or broken");
_askToRegisterApp();
} else {
if (INTEGRATION_VERSION > ConnectionManager().appIntegrationVersion) {
@ -112,20 +112,7 @@ class MobileAppIntegrationManager {
_askToRegisterApp();
} else {
Logger.e("Error updating app registration: $e");
eventBus.fire(ShowPopupEvent(
Popup(
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: () {
Launcher.launchURLInBrowser("https://github.com/estevez-dev/ha_client/issues/new");
},
onNegative: () {
Launcher.launchURLInBrowser("https://discord.gg/AUzEvwn");
},
)
));
_showError();
}
completer.complete();
});
@ -133,6 +120,23 @@ class MobileAppIntegrationManager {
}
}
static void _showError() {
eventBus.fire(ShowPopupEvent(
Popup(
title: "App integration is not working properly",
body: "Something wrong with HA Client integration on your Home Assistant server. Please report this issue. You can try to remove Mobile App integration from Home Assistant and restart server to fix this issue.",
positiveText: "Report to GitHub",
negativeText: "Report to Discord",
onPositive: () {
Launcher.launchURLInBrowser("https://github.com/estevez-dev/ha_client/issues/new");
},
onNegative: () {
Launcher.launchURLInBrowser("https://discord.gg/AUzEvwn");
},
)
));
}
static void _askToRemoveAndRegisterApp() {
eventBus.fire(ShowPopupEvent(
Popup(
@ -149,18 +153,9 @@ class MobileAppIntegrationManager {
static void _askToRegisterApp() {
eventBus.fire(ShowPopupEvent(
Popup(
title: "App integration is broken",
body: "Looks like app integration was removed from your Home Assistant or it needs to be updated. HA Client needs to be registered on your Home Assistant server to make it possible to use notifications and location tracking. Please remove 'Mobile App' integration for this device from your Home Assistant before registering and restart Home Assistant. Then go back here.",
positiveText: "Register now",
negativeText: "Cancel",
onPositive: () {
SharedPreferences.getInstance().then((prefs) {
prefs.remove("app-webhook-id");
ConnectionManager().webhookId = null;
checkAppRegistration();
});
},
RegisterAppPopup(
title: "Mobile App integration is missing",
body: "Looks like mobile app integration was removed from your Home Assistant or it needs to be updated.",
)
));
}