Fix dashboard switching and dashboard icons
This commit is contained in:
parent
5ced01463f
commit
8e31eaf8bb
@ -47,7 +47,7 @@ class HACard {
|
|||||||
|
|
||||||
List<EntityWrapper> getEntitiesToShow() {
|
List<EntityWrapper> getEntitiesToShow() {
|
||||||
return entities.where((entityWrapper) {
|
return entities.where((entityWrapper) {
|
||||||
if (!ConnectionManager().useLovelace && entityWrapper.entity.isHidden) {
|
if (HomeAssistant().autoUi && entityWrapper.entity.isHidden) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List currentStateFilter;
|
List currentStateFilter;
|
||||||
|
@ -20,6 +20,7 @@ class HomeAssistant {
|
|||||||
String sendToPlayerId;
|
String sendToPlayerId;
|
||||||
String sendFromPlayerId;
|
String sendFromPlayerId;
|
||||||
Map services;
|
Map services;
|
||||||
|
bool autoUi = false;
|
||||||
|
|
||||||
String fcmToken;
|
String fcmToken;
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ class HomeAssistant {
|
|||||||
Duration fetchTimeout = Duration(seconds: 30);
|
Duration fetchTimeout = Duration(seconds: 30);
|
||||||
|
|
||||||
String get locationName {
|
String get locationName {
|
||||||
if (ConnectionManager().useLovelace) {
|
if (!autoUi) {
|
||||||
return ui?.title ?? "";
|
return ui?.title ?? "";
|
||||||
} else {
|
} else {
|
||||||
return _instanceConfig["location_name"] ?? "";
|
return _instanceConfig["location_name"] ?? "";
|
||||||
@ -64,7 +65,7 @@ class HomeAssistant {
|
|||||||
_fetchCompleter = Completer();
|
_fetchCompleter = Completer();
|
||||||
List<Future> futures = [];
|
List<Future> futures = [];
|
||||||
futures.add(_getStates(null));
|
futures.add(_getStates(null));
|
||||||
if (ConnectionManager().useLovelace) {
|
if (!autoUi) {
|
||||||
futures.add(_getLovelace(null));
|
futures.add(_getLovelace(null));
|
||||||
}
|
}
|
||||||
futures.add(_getConfig(null));
|
futures.add(_getConfig(null));
|
||||||
@ -93,7 +94,7 @@ class HomeAssistant {
|
|||||||
if (entities == null) entities = EntityCollection(ConnectionManager().httpWebHost);
|
if (entities == null) entities = EntityCollection(ConnectionManager().httpWebHost);
|
||||||
try {
|
try {
|
||||||
_getStates(prefs);
|
_getStates(prefs);
|
||||||
if (ConnectionManager().useLovelace) {
|
if (!autoUi) {
|
||||||
_getLovelace(prefs);
|
_getLovelace(prefs);
|
||||||
}
|
}
|
||||||
_getConfig(prefs);
|
_getConfig(prefs);
|
||||||
@ -183,7 +184,7 @@ class HomeAssistant {
|
|||||||
var data = json.decode(sharedPrefs.getString('cached_lovelace'));
|
var data = json.decode(sharedPrefs.getString('cached_lovelace'));
|
||||||
_rawLovelaceData = data;
|
_rawLovelaceData = data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ConnectionManager().useLovelace = false;
|
autoUi = true;
|
||||||
}
|
}
|
||||||
return Future.value();
|
return Future.value();
|
||||||
} else {
|
} else {
|
||||||
@ -198,7 +199,7 @@ class HomeAssistant {
|
|||||||
completer.complete();
|
completer.complete();
|
||||||
}).catchError((e) {
|
}).catchError((e) {
|
||||||
if ("$e" == "config_not_found") {
|
if ("$e" == "config_not_found") {
|
||||||
ConnectionManager().useLovelace = false;
|
autoUi = true;
|
||||||
completer.complete();
|
completer.complete();
|
||||||
} else {
|
} else {
|
||||||
completer.completeError(HAError("Error getting lovelace config: $e"));
|
completer.completeError(HAError("Error getting lovelace config: $e"));
|
||||||
@ -263,22 +264,22 @@ class HomeAssistant {
|
|||||||
dashboards.add(
|
dashboards.add(
|
||||||
Panel(
|
Panel(
|
||||||
id: k,
|
id: k,
|
||||||
componentName: v["component_name"],
|
componentName: v['component_name'],
|
||||||
title: title,
|
title: title,
|
||||||
urlPath: v["url_path"],
|
urlPath: v['url_path'],
|
||||||
config: v["config"],
|
config: v['config'],
|
||||||
icon: v["icon"] ?? 'mdi:view-dashboard'
|
icon: (v['icon'] == null || v['icon'] == 'hass:view-dashboard') ? 'mdi:view-dashboard' : v['icon']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
panels.add(
|
panels.add(
|
||||||
Panel(
|
Panel(
|
||||||
id: k,
|
id: k,
|
||||||
componentName: v["component_name"],
|
componentName: v['component_name'],
|
||||||
title: title,
|
title: title,
|
||||||
urlPath: v["url_path"],
|
urlPath: v['url_path'],
|
||||||
config: v["config"],
|
config: v['config'],
|
||||||
icon: v["icon"]
|
icon: v['icon']
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -488,7 +489,7 @@ class HomeAssistant {
|
|||||||
|
|
||||||
void _createUI() {
|
void _createUI() {
|
||||||
ui = HomeAssistantUI();
|
ui = HomeAssistantUI();
|
||||||
if ((ConnectionManager().useLovelace) && (_rawLovelaceData != null)) {
|
if (!autoUi && (_rawLovelaceData != null)) {
|
||||||
Logger.d("Creating Lovelace UI");
|
Logger.d("Creating Lovelace UI");
|
||||||
_parseLovelace();
|
_parseLovelace();
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,7 +19,6 @@ class ConnectionManager {
|
|||||||
String _tempToken;
|
String _tempToken;
|
||||||
String oauthUrl;
|
String oauthUrl;
|
||||||
String webhookId;
|
String webhookId;
|
||||||
bool useLovelace = true;
|
|
||||||
bool settingsLoaded = false;
|
bool settingsLoaded = false;
|
||||||
bool get isAuthenticated => _token != null;
|
bool get isAuthenticated => _token != null;
|
||||||
StreamSubscription _socketSubscription;
|
StreamSubscription _socketSubscription;
|
||||||
@ -41,8 +40,6 @@ class ConnectionManager {
|
|||||||
if (loadSettings) {
|
if (loadSettings) {
|
||||||
Logger.d("Loading settings...");
|
Logger.d("Loading settings...");
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
Logger.d("..done");
|
|
||||||
useLovelace = prefs.getBool('use-lovelace') ?? true;
|
|
||||||
_domain = prefs.getString('hassio-domain');
|
_domain = prefs.getString('hassio-domain');
|
||||||
_port = prefs.getString('hassio-port');
|
_port = prefs.getString('hassio-port');
|
||||||
webhookId = prefs.getString('app-webhook-id');
|
webhookId = prefs.getString('app-webhook-id');
|
||||||
|
@ -36,6 +36,7 @@ class Panel {
|
|||||||
);
|
);
|
||||||
} else if (componentName == 'lovelace') {
|
} else if (componentName == 'lovelace') {
|
||||||
HomeAssistant().lovelaceDashboardUrl = this.urlPath;
|
HomeAssistant().lovelaceDashboardUrl = this.urlPath;
|
||||||
|
HomeAssistant().autoUi = false;
|
||||||
SharedPreferences.getInstance().then((prefs) {
|
SharedPreferences.getInstance().then((prefs) {
|
||||||
prefs.setString('lovelace_dashboard_url', this.urlPath);
|
prefs.setString('lovelace_dashboard_url', this.urlPath);
|
||||||
eventBus.fire(ReloadUIEvent());
|
eventBus.fire(ReloadUIEvent());
|
||||||
|
Reference in New Issue
Block a user