diff --git a/lib/managers/connection_manager.class.dart b/lib/managers/connection_manager.class.dart index 3a2b383..b2cfe10 100644 --- a/lib/managers/connection_manager.class.dart +++ b/lib/managers/connection_manager.class.dart @@ -19,6 +19,7 @@ class ConnectionManager { String _tempToken; String oauthUrl; String webhookId; + String mobileAppDeviceName; bool settingsLoaded = false; int appIntegrationVersion; bool get isAuthenticated => _token != null; @@ -45,6 +46,7 @@ class ConnectionManager { _port = prefs.getString('hassio-port'); webhookId = prefs.getString('app-webhook-id'); appIntegrationVersion = prefs.getInt('app-integration-version') ?? 0; + mobileAppDeviceName = prefs.getString('app-integration-device-name'); displayHostname = "$_domain:$_port"; _webSocketAPIEndpoint = "${prefs.getString('hassio-protocol')}://$_domain:$_port/api/websocket"; diff --git a/lib/managers/mobile_app_integration_manager.class.dart b/lib/managers/mobile_app_integration_manager.class.dart index b6133b3..20aebb2 100644 --- a/lib/managers/mobile_app_integration_manager.class.dart +++ b/lib/managers/mobile_app_integration_manager.class.dart @@ -16,9 +16,13 @@ class MobileAppIntegrationManager { } }; + static String getDefaultDeviceName() { + return '${HomeAssistant().userName}\'s ${DeviceInfoManager().model}'; + } + static Future checkAppRegistration({bool forceRegister: false, bool showOkDialog: false}) { Completer completer = Completer(); - _appRegistrationData["device_name"] = "${HomeAssistant().userName}'s ${DeviceInfoManager().model}"; + _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..."); diff --git a/lib/pages/settings/integration_settings.part.dart b/lib/pages/settings/integration_settings.part.dart index a3ad8b6..12888d2 100644 --- a/lib/pages/settings/integration_settings.part.dart +++ b/lib/pages/settings/integration_settings.part.dart @@ -14,6 +14,9 @@ class _IntegrationSettingsPageState extends State { int _locationInterval = LocationManager().defaultUpdateIntervalMinutes; bool _locationTrackingEnabled = false; bool _wait = false; + String _deviceName = ''; + bool _applyNameEnabled = false; + String _newDeviceName = ''; @override void initState() { @@ -27,6 +30,7 @@ class _IntegrationSettingsPageState extends State { await prefs.reload(); SharedPreferences.getInstance().then((prefs) { setState(() { + _deviceName = _newDeviceName = ConnectionManager().mobileAppDeviceName ?? MobileAppIntegrationManager.getDefaultDeviceName(); _locationTrackingEnabled = prefs.getBool("location-enabled") ?? false; _locationInterval = prefs.getInt("location-interval") ?? LocationManager().defaultUpdateIntervalMinutes; if (_locationInterval % 5 != 0) { @@ -157,30 +161,25 @@ class _IntegrationSettingsPageState extends State { ], ), Divider(), - Text("Integration status", style: Theme.of(context).textTheme.title), + Text("Device name", style: Theme.of(context).textTheme.title), Container(height: Sizes.rowPadding,), - Text( - "${HomeAssistant().userName}'s ${DeviceInfoManager().model}, ${DeviceInfoManager().osName} ${DeviceInfoManager().osVersion}", - style: Theme.of(context).textTheme.subtitle, - ), + TextField( + /*decoration: InputDecoration( + labelText: "Long-lived token" + ),*/ + controller: TextEditingController.fromValue(TextEditingValue(text: _newDeviceName)), + onChanged: (value) { + setState(() { + _newDeviceName = value; + _applyNameEnabled = _newDeviceName != _deviceName; + }); + } + ), Container(height: 6.0,), - Text("Here you can manually check if HA Client integration with your Home Assistant works fine. As mobileApp integration in Home Assistant is still in development, this is not 100% correct check."), - //Divider(), - Row( - mainAxisSize: MainAxisSize.max, - children: [ - RaisedButton( - color: Colors.blue, - onPressed: () => updateRegistration(), - child: Text("Check integration", style: Theme.of(context).textTheme.button) - ), - Container(width: 10.0,), - RaisedButton( - color: Colors.redAccent, - onPressed: () => resetRegistration(), - child: Text("Reset integration", style: Theme.of(context).textTheme.button) - ) - ], + RaisedButton( + color: Colors.blue, + onPressed: () => _applyNameEnabled ? updateRegistration() : null, + child: Text("Update device name", style: Theme.of(context).textTheme.button) ), ] );