WIP #523 Change device name for integration
This commit is contained in:
parent
f28e5493dc
commit
163338ea75
@ -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";
|
||||
|
@ -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...");
|
||||
|
@ -14,6 +14,9 @@ class _IntegrationSettingsPageState extends State<IntegrationSettingsPage> {
|
||||
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<IntegrationSettingsPage> {
|
||||
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<IntegrationSettingsPage> {
|
||||
],
|
||||
),
|
||||
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: <Widget>[
|
||||
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)
|
||||
),
|
||||
]
|
||||
);
|
||||
|
Reference in New Issue
Block a user