2018-09-10 03:06:35 +03:00
|
|
|
part of 'main.dart';
|
|
|
|
|
2018-09-17 00:28:19 +03:00
|
|
|
class ConnectionSettingsPage extends StatefulWidget {
|
|
|
|
ConnectionSettingsPage({Key key, this.title}) : super(key: key);
|
2018-09-10 03:06:35 +03:00
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
@override
|
2018-09-17 00:28:19 +03:00
|
|
|
_ConnectionSettingsPageState createState() => new _ConnectionSettingsPageState();
|
2018-09-10 03:06:35 +03:00
|
|
|
}
|
|
|
|
|
2018-09-17 00:28:19 +03:00
|
|
|
class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> {
|
2018-09-10 03:06:35 +03:00
|
|
|
String _hassioDomain = "";
|
2018-09-20 23:21:03 +03:00
|
|
|
String _hassioPort = "8123";
|
2018-09-10 03:06:35 +03:00
|
|
|
String _hassioPassword = "";
|
2018-09-16 21:27:16 +03:00
|
|
|
String _socketProtocol = "wss";
|
2018-09-21 00:39:49 +03:00
|
|
|
String _authType = "access_token";
|
2018-09-10 03:06:35 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_loadSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
_loadSettings() async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_hassioDomain = prefs.getString("hassio-domain");
|
2018-09-20 23:21:03 +03:00
|
|
|
_hassioPort = prefs.getString("hassio-port") ?? '8123';
|
2018-09-10 03:06:35 +03:00
|
|
|
_hassioPassword = prefs.getString("hassio-password");
|
2018-09-20 23:21:03 +03:00
|
|
|
_socketProtocol = prefs.getString("hassio-protocol") ?? 'wss';
|
2018-09-21 00:39:49 +03:00
|
|
|
_authType = prefs.getString("hassio-auth-type") ?? 'access_token';
|
2018-09-10 03:06:35 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_saveSettings() async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
2018-09-16 21:27:16 +03:00
|
|
|
prefs.setString("hassio-domain", _hassioDomain);
|
|
|
|
prefs.setString("hassio-port", _hassioPort);
|
|
|
|
prefs.setString("hassio-password", _hassioPassword);
|
|
|
|
prefs.setString("hassio-protocol", _socketProtocol);
|
2018-09-21 00:39:49 +03:00
|
|
|
prefs.setString("hassio-auth-type", _authType);
|
2018-09-10 03:06:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return new Scaffold(
|
|
|
|
appBar: new AppBar(
|
|
|
|
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
|
2018-09-20 23:21:03 +03:00
|
|
|
_saveSettings().then((r){
|
|
|
|
Navigator.pop(context);
|
|
|
|
});
|
|
|
|
eventBus.fire(SettingsChangedEvent(true));
|
2018-09-10 03:06:35 +03:00
|
|
|
}),
|
|
|
|
// Here we take the value from the MyHomePage object that was created by
|
|
|
|
// the App.build method, and use it to set our appbar title.
|
|
|
|
title: new Text(widget.title),
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
padding: const EdgeInsets.all(20.0),
|
|
|
|
children: <Widget>[
|
2018-09-16 21:27:16 +03:00
|
|
|
new Row(
|
|
|
|
children: [
|
|
|
|
Text("HTTPS"),
|
|
|
|
Switch(
|
|
|
|
value: (_socketProtocol == "wss"),
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_socketProtocol = value ? "wss" : "ws";
|
|
|
|
});
|
|
|
|
_saveSettings();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2018-09-10 03:06:35 +03:00
|
|
|
new TextField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: "Home Assistant domain or ip address"
|
|
|
|
),
|
|
|
|
controller: TextEditingController(
|
|
|
|
text: _hassioDomain
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
_hassioDomain = value;
|
2018-09-16 21:27:16 +03:00
|
|
|
_saveSettings();
|
2018-09-10 03:06:35 +03:00
|
|
|
},
|
|
|
|
),
|
|
|
|
new TextField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: "Home Assistant port"
|
|
|
|
),
|
|
|
|
controller: TextEditingController(
|
|
|
|
text: _hassioPort
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
_hassioPort = value;
|
2018-09-16 21:27:16 +03:00
|
|
|
_saveSettings();
|
2018-09-10 03:06:35 +03:00
|
|
|
},
|
|
|
|
),
|
2018-09-21 00:39:49 +03:00
|
|
|
new Row(
|
|
|
|
children: [
|
|
|
|
Text("Login with access token (HA >= 0.78.0)"),
|
|
|
|
Switch(
|
|
|
|
value: (_authType == "access_token"),
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_authType = value ? "access_token" : "api_password";
|
|
|
|
});
|
|
|
|
_saveSettings();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2018-09-10 03:06:35 +03:00
|
|
|
new TextField(
|
|
|
|
decoration: InputDecoration(
|
2018-09-21 00:39:49 +03:00
|
|
|
labelText: _authType == "access_token" ? "Access token" : "API password"
|
2018-09-10 03:06:35 +03:00
|
|
|
),
|
|
|
|
controller: TextEditingController(
|
|
|
|
text: _hassioPassword
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
_hassioPassword = value;
|
2018-09-16 21:27:16 +03:00
|
|
|
_saveSettings();
|
2018-09-10 03:06:35 +03:00
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|