Resolves #277 Remove legacy password support
This commit is contained in:
		| @@ -3,7 +3,6 @@ part of 'main.dart'; | ||||
| class HomeAssistant { | ||||
|   String _webSocketAPIEndpoint; | ||||
|   String _password; | ||||
|   String _authType; | ||||
|   bool _useLovelace = false; | ||||
|  | ||||
|   IOWebSocketChannel _hassioChannel; | ||||
| @@ -56,10 +55,9 @@ class HomeAssistant { | ||||
|     _messageQueue = SendMessageQueue(messageExpirationTime); | ||||
|   } | ||||
|  | ||||
|   void updateSettings(String url, String password, String authType, bool useLovelace) { | ||||
|   void updateSettings(String url, String password, bool useLovelace) { | ||||
|     _webSocketAPIEndpoint = url; | ||||
|     _password = password; | ||||
|     _authType = authType; | ||||
|     _useLovelace = useLovelace; | ||||
|     Logger.d( "Use lovelace is $_useLovelace"); | ||||
|   } | ||||
| @@ -213,7 +211,7 @@ class HomeAssistant { | ||||
|   _handleMessage(String message) { | ||||
|     var data = json.decode(message); | ||||
|     if (data["type"] == "auth_required") { | ||||
|       _sendAuthMessageRaw('{"type": "auth","$_authType": "$_password"}'); | ||||
|       _sendAuthMessageRaw('{"type": "auth","access_token": "$_password"}'); | ||||
|     } else if (data["type"] == "auth_ok") { | ||||
|       _completeConnecting(null); | ||||
|       _sendSubscribe(); | ||||
| @@ -550,17 +548,10 @@ class HomeAssistant { | ||||
|     String url = "$homeAssistantWebHost/api/history/period/$startTime?&filter_entity_id=$entityId"; | ||||
|     Logger.d("[Sending] ==> $url"); | ||||
|     http.Response historyResponse; | ||||
|     if (_authType == "access_token") { | ||||
|       historyResponse = await http.get(url, headers: { | ||||
|     historyResponse = await http.get(url, headers: { | ||||
|         "authorization": "Bearer $_password", | ||||
|         "Content-Type": "application/json" | ||||
|       }); | ||||
|     } else { | ||||
|       historyResponse = await http.get(url, headers: { | ||||
|         "X-HA-Access": "$_password", | ||||
|         "Content-Type": "application/json" | ||||
|       }); | ||||
|     } | ||||
|     }); | ||||
|     var history = json.decode(historyResponse.body); | ||||
|     if (history is List) { | ||||
|       Logger.d( "[Received] <== ${history.first.length} history recors"); | ||||
|   | ||||
| @@ -142,7 +142,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|   //Map _instanceConfig; | ||||
|   String _webSocketApiEndpoint; | ||||
|   String _password; | ||||
|   String _authType; | ||||
|   //int _uiViewsCount = 0; | ||||
|   String _instanceHost; | ||||
|   StreamSubscription _stateSubscription; | ||||
| @@ -200,7 +199,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|     _webSocketApiEndpoint = "${prefs.getString('hassio-protocol')}://$domain:$port/api/websocket"; | ||||
|     homeAssistantWebHost = "${prefs.getString('hassio-res-protocol')}://$domain:$port"; | ||||
|     _password = prefs.getString('hassio-password'); | ||||
|     _authType = prefs.getString('hassio-auth-type'); | ||||
|     _useLovelaceUI = prefs.getBool('use-lovelace') ?? false; | ||||
|     if ((domain == null) || (port == null) || (_password == null) || | ||||
|         (domain.length == 0) || (port.length == 0) || (_password.length == 0)) { | ||||
| @@ -250,7 +248,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | ||||
|   } | ||||
|  | ||||
|   _refreshData() async { | ||||
|     _homeAssistant.updateSettings(_webSocketApiEndpoint, _password, _authType, _useLovelaceUI); | ||||
|     _homeAssistant.updateSettings(_webSocketApiEndpoint, _password, _useLovelaceUI); | ||||
|     _hideBottomBar(); | ||||
|     _showInfoBottomBar(progress: true,); | ||||
|     await _homeAssistant.fetch().then((result) { | ||||
|   | ||||
| @@ -18,8 +18,6 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> { | ||||
|   String _newHassioPassword = ""; | ||||
|   String _socketProtocol = "wss"; | ||||
|   String _newSocketProtocol = "wss"; | ||||
|   String _authType = "access_token"; | ||||
|   String _newAuthType = "access_token"; | ||||
|   bool _useLovelace = false; | ||||
|   bool _newUseLovelace = false; | ||||
|  | ||||
| @@ -37,7 +35,6 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> { | ||||
|       _hassioPort = _newHassioPort = prefs.getString("hassio-port") ?? ""; | ||||
|       _hassioPassword = _newHassioPassword = prefs.getString("hassio-password") ?? ""; | ||||
|       _socketProtocol = _newSocketProtocol = prefs.getString("hassio-protocol") ?? 'wss'; | ||||
|       _authType = _newAuthType = prefs.getString("hassio-auth-type") ?? 'access_token'; | ||||
|       try { | ||||
|         _useLovelace = _newUseLovelace = prefs.getBool("use-lovelace") ?? false; | ||||
|       } catch (e) { | ||||
| @@ -51,7 +48,6 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> { | ||||
|       (_newHassioPort != _hassioPort) || | ||||
|       (_newHassioDomain != _hassioDomain) || | ||||
|       (_newSocketProtocol != _socketProtocol) || | ||||
|       (_newAuthType != _authType) || | ||||
|       (_newUseLovelace != _useLovelace)); | ||||
|  | ||||
|   } | ||||
| @@ -66,7 +62,6 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> { | ||||
|     prefs.setString("hassio-password", _newHassioPassword); | ||||
|     prefs.setString("hassio-protocol", _newSocketProtocol); | ||||
|     prefs.setString("hassio-res-protocol", _newSocketProtocol == "wss" ? "https" : "http"); | ||||
|     prefs.setString("hassio-auth-type", _newAuthType); | ||||
|     prefs.setBool("use-lovelace", _newUseLovelace); | ||||
|   } | ||||
|  | ||||
| @@ -154,33 +149,9 @@ class _ConnectionSettingsPageState extends State<ConnectionSettingsPage> { | ||||
|             "Try ports 80 and 443 if default is not working and you don't know why.", | ||||
|             style: TextStyle(color: Colors.grey), | ||||
|           ), | ||||
|           new Row( | ||||
|             mainAxisSize: MainAxisSize.min, | ||||
|             children: [ | ||||
|               Flexible( | ||||
|                 child: Text( | ||||
|                   "Login with access token (HA >= 0.78.0)", | ||||
|                   softWrap: true, | ||||
|                   maxLines: 2, | ||||
|                 ), | ||||
|               ), | ||||
|               Switch( | ||||
|                 value: (_newAuthType == "access_token"), | ||||
|                 onChanged: (value) { | ||||
|                   setState(() { | ||||
|                     _newAuthType = value ? "access_token" : "api_password"; | ||||
|                   }); | ||||
|                 }, | ||||
|               ) | ||||
|             ], | ||||
|           ), | ||||
|           new Text( | ||||
|             "You should use access token for HA >= 0.84.1. Legacy password will not work there.", | ||||
|             style: TextStyle(color: Colors.grey), | ||||
|           ), | ||||
|           new TextField( | ||||
|             decoration: InputDecoration( | ||||
|                 labelText: _newAuthType == "access_token" ? "Access token" : "API password" | ||||
|                 labelText: "Access token" | ||||
|             ), | ||||
|             controller: new TextEditingController.fromValue( | ||||
|                 new TextEditingValue( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user