Resolves #11 Add Panels fetching

This commit is contained in:
estevez-dev
2019-03-13 16:39:23 +02:00
parent 736b38b64c
commit 3504d3276c
5 changed files with 156 additions and 48 deletions

View File

@ -19,6 +19,8 @@ class HomeAssistant {
Map _rawLovelaceData;
List<Panel> panels = [];
Completer _fetchCompleter;
Completer _connectionCompleter;
Timer _connectionTimer;
@ -159,6 +161,7 @@ class HomeAssistant {
futures.add(_getConfig());
futures.add(_getServices());
futures.add(_getUserInfo());
futures.add(_getPanels());
try {
await Future.wait(futures);
_createUI();
@ -254,6 +257,28 @@ class HomeAssistant {
await _sendInitialMessage("get_services").then((data) => Logger.d("We actually don`t need the list of servcies for now"));
}
Future _getPanels() async {
panels.clear();
await _sendInitialMessage("get_panels").then((data) {
if (data["success"]) {
data["result"].forEach((k,v) {
if (k != "lovelace" && !v["component_name"].startsWith("dev-") && v["component_name"]!="profile" && v["component_name"]!="states" && v["component_name"]!="kiosk") {
String title = v['title'] == null ? "${k[0].toUpperCase()}${k.substring(1)}" : "${v['title'][0].toUpperCase()}${v['title'].substring(1)}";
panels.add(Panel(
id: k,
type: v["component_name"],
title: title,
urlPath: v["url_path"],
config: v["config"],
icon: v["icon"]
)
);
}
});
}
});
}
_incrementMessageId() {
_currentMessageId += 1;
}