From 8e31eaf8bb9be0f9a8b321d442ce7a10ea2cfe55 Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Fri, 20 Mar 2020 10:14:14 +0000 Subject: [PATCH] Fix dashboard switching and dashboard icons --- lib/cards/card.class.dart | 2 +- lib/home_assistant.class.dart | 29 +++++++++++----------- lib/managers/connection_manager.class.dart | 3 --- lib/panels/panel_class.dart | 1 + 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/cards/card.class.dart b/lib/cards/card.class.dart index 71db7b2..15ca032 100644 --- a/lib/cards/card.class.dart +++ b/lib/cards/card.class.dart @@ -47,7 +47,7 @@ class HACard { List getEntitiesToShow() { return entities.where((entityWrapper) { - if (!ConnectionManager().useLovelace && entityWrapper.entity.isHidden) { + if (HomeAssistant().autoUi && entityWrapper.entity.isHidden) { return false; } List currentStateFilter; diff --git a/lib/home_assistant.class.dart b/lib/home_assistant.class.dart index 3c6d400..ec8fa46 100644 --- a/lib/home_assistant.class.dart +++ b/lib/home_assistant.class.dart @@ -20,6 +20,7 @@ class HomeAssistant { String sendToPlayerId; String sendFromPlayerId; Map services; + bool autoUi = false; String fcmToken; @@ -35,7 +36,7 @@ class HomeAssistant { Duration fetchTimeout = Duration(seconds: 30); String get locationName { - if (ConnectionManager().useLovelace) { + if (!autoUi) { return ui?.title ?? ""; } else { return _instanceConfig["location_name"] ?? ""; @@ -64,7 +65,7 @@ class HomeAssistant { _fetchCompleter = Completer(); List futures = []; futures.add(_getStates(null)); - if (ConnectionManager().useLovelace) { + if (!autoUi) { futures.add(_getLovelace(null)); } futures.add(_getConfig(null)); @@ -93,7 +94,7 @@ class HomeAssistant { if (entities == null) entities = EntityCollection(ConnectionManager().httpWebHost); try { _getStates(prefs); - if (ConnectionManager().useLovelace) { + if (!autoUi) { _getLovelace(prefs); } _getConfig(prefs); @@ -183,7 +184,7 @@ class HomeAssistant { var data = json.decode(sharedPrefs.getString('cached_lovelace')); _rawLovelaceData = data; } catch (e) { - ConnectionManager().useLovelace = false; + autoUi = true; } return Future.value(); } else { @@ -198,7 +199,7 @@ class HomeAssistant { completer.complete(); }).catchError((e) { if ("$e" == "config_not_found") { - ConnectionManager().useLovelace = false; + autoUi = true; completer.complete(); } else { completer.completeError(HAError("Error getting lovelace config: $e")); @@ -263,22 +264,22 @@ class HomeAssistant { dashboards.add( Panel( id: k, - componentName: v["component_name"], + componentName: v['component_name'], title: title, - urlPath: v["url_path"], - config: v["config"], - icon: v["icon"] ?? 'mdi:view-dashboard' + urlPath: v['url_path'], + config: v['config'], + icon: (v['icon'] == null || v['icon'] == 'hass:view-dashboard') ? 'mdi:view-dashboard' : v['icon'] ) ); } else { panels.add( Panel( id: k, - componentName: v["component_name"], + componentName: v['component_name'], title: title, - urlPath: v["url_path"], - config: v["config"], - icon: v["icon"] + urlPath: v['url_path'], + config: v['config'], + icon: v['icon'] ) ); } @@ -488,7 +489,7 @@ class HomeAssistant { void _createUI() { ui = HomeAssistantUI(); - if ((ConnectionManager().useLovelace) && (_rawLovelaceData != null)) { + if (!autoUi && (_rawLovelaceData != null)) { Logger.d("Creating Lovelace UI"); _parseLovelace(); } else { diff --git a/lib/managers/connection_manager.class.dart b/lib/managers/connection_manager.class.dart index dc554bb..a94d9c8 100644 --- a/lib/managers/connection_manager.class.dart +++ b/lib/managers/connection_manager.class.dart @@ -19,7 +19,6 @@ class ConnectionManager { String _tempToken; String oauthUrl; String webhookId; - bool useLovelace = true; bool settingsLoaded = false; bool get isAuthenticated => _token != null; StreamSubscription _socketSubscription; @@ -41,8 +40,6 @@ class ConnectionManager { if (loadSettings) { Logger.d("Loading settings..."); SharedPreferences prefs = await SharedPreferences.getInstance(); - Logger.d("..done"); - useLovelace = prefs.getBool('use-lovelace') ?? true; _domain = prefs.getString('hassio-domain'); _port = prefs.getString('hassio-port'); webhookId = prefs.getString('app-webhook-id'); diff --git a/lib/panels/panel_class.dart b/lib/panels/panel_class.dart index fb8017e..ec01871 100644 --- a/lib/panels/panel_class.dart +++ b/lib/panels/panel_class.dart @@ -36,6 +36,7 @@ class Panel { ); } else if (componentName == 'lovelace') { HomeAssistant().lovelaceDashboardUrl = this.urlPath; + HomeAssistant().autoUi = false; SharedPreferences.getInstance().then((prefs) { prefs.setString('lovelace_dashboard_url', this.urlPath); eventBus.fire(ReloadUIEvent());