Resolves #11 Add Panels fetching
This commit is contained in:
parent
736b38b64c
commit
3504d3276c
@ -19,6 +19,8 @@ class HomeAssistant {
|
|||||||
|
|
||||||
Map _rawLovelaceData;
|
Map _rawLovelaceData;
|
||||||
|
|
||||||
|
List<Panel> panels = [];
|
||||||
|
|
||||||
Completer _fetchCompleter;
|
Completer _fetchCompleter;
|
||||||
Completer _connectionCompleter;
|
Completer _connectionCompleter;
|
||||||
Timer _connectionTimer;
|
Timer _connectionTimer;
|
||||||
@ -159,6 +161,7 @@ class HomeAssistant {
|
|||||||
futures.add(_getConfig());
|
futures.add(_getConfig());
|
||||||
futures.add(_getServices());
|
futures.add(_getServices());
|
||||||
futures.add(_getUserInfo());
|
futures.add(_getUserInfo());
|
||||||
|
futures.add(_getPanels());
|
||||||
try {
|
try {
|
||||||
await Future.wait(futures);
|
await Future.wait(futures);
|
||||||
_createUI();
|
_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"));
|
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() {
|
_incrementMessageId() {
|
||||||
_currentMessageId += 1;
|
_currentMessageId += 1;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ part 'entity_widgets/controls/media_player_widgets.dart';
|
|||||||
part 'entity_widgets/controls/fan_controls.dart';
|
part 'entity_widgets/controls/fan_controls.dart';
|
||||||
part 'entity_widgets/controls/alarm_control_panel_controls.dart';
|
part 'entity_widgets/controls/alarm_control_panel_controls.dart';
|
||||||
part 'settings.page.dart';
|
part 'settings.page.dart';
|
||||||
part 'configuration.page.dart';
|
part 'panel.page.dart';
|
||||||
part 'home_assistant.class.dart';
|
part 'home_assistant.class.dart';
|
||||||
part 'log.page.dart';
|
part 'log.page.dart';
|
||||||
part 'entity.page.dart';
|
part 'entity.page.dart';
|
||||||
@ -88,9 +88,11 @@ part 'ui_class/ui.dart';
|
|||||||
part 'ui_class/view.class.dart';
|
part 'ui_class/view.class.dart';
|
||||||
part 'ui_class/card.class.dart';
|
part 'ui_class/card.class.dart';
|
||||||
part 'ui_class/sizes_class.dart';
|
part 'ui_class/sizes_class.dart';
|
||||||
|
part 'ui_class/panel_class.dart';
|
||||||
part 'ui_widgets/view.dart';
|
part 'ui_widgets/view.dart';
|
||||||
part 'ui_widgets/card_widget.dart';
|
part 'ui_widgets/card_widget.dart';
|
||||||
part 'ui_widgets/card_header_widget.dart';
|
part 'ui_widgets/card_header_widget.dart';
|
||||||
|
part 'ui_widgets/config_panel_widget.dart';
|
||||||
|
|
||||||
|
|
||||||
EventBus eventBus = new EventBus();
|
EventBus eventBus = new EventBus();
|
||||||
@ -131,7 +133,7 @@ class HAClientApp extends StatelessWidget {
|
|||||||
routes: {
|
routes: {
|
||||||
"/": (context) => MainPage(title: 'HA Client'),
|
"/": (context) => MainPage(title: 'HA Client'),
|
||||||
"/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"),
|
"/connection-settings": (context) => ConnectionSettingsPage(title: "Settings"),
|
||||||
"/configuration": (context) => ConfigurationPage(title: "Configuration"),
|
"/configuration": (context) => PanelPage(title: "Configuration"),
|
||||||
"/log-view": (context) => LogViewPage(title: "Log")
|
"/log-view": (context) => LogViewPage(title: "Log")
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -302,6 +304,15 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _showPanelPage(Panel panel) {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => PanelPage(title: "${panel.title}", panel: panel),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
List<Tab> buildUIViewTabs() {
|
List<Tab> buildUIViewTabs() {
|
||||||
List<Tab> result = [];
|
List<Tab> result = [];
|
||||||
|
|
||||||
@ -348,15 +359,19 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
Divider(),
|
Divider(),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
menuItems.addAll([
|
if (_homeAssistant != null && _homeAssistant.panels.isNotEmpty) {
|
||||||
|
_homeAssistant.panels.forEach((Panel panel) {
|
||||||
|
menuItems.add(
|
||||||
new ListTile(
|
new ListTile(
|
||||||
leading: Icon(Icons.settings),
|
leading: Icon(MaterialDesignIcons.getIconDataFromIconName(panel.icon)),
|
||||||
title: Text("Configuration"),
|
title: Text("${panel.title}(${panel.urlPath})"),
|
||||||
onTap: () {
|
onTap: () =>_showPanelPage(panel)
|
||||||
Navigator.of(context).pop();
|
)
|
||||||
Navigator.of(context).pushNamed('/configuration');
|
);
|
||||||
},
|
});
|
||||||
),
|
menuItems.add(Divider());
|
||||||
|
}
|
||||||
|
menuItems.addAll([
|
||||||
new ListTile(
|
new ListTile(
|
||||||
leading: Icon(Icons.insert_drive_file),
|
leading: Icon(Icons.insert_drive_file),
|
||||||
title: Text("Log"),
|
title: Text("Log"),
|
||||||
|
40
lib/panel.page.dart
Normal file
40
lib/panel.page.dart
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
part of 'main.dart';
|
||||||
|
|
||||||
|
class PanelPage extends StatefulWidget {
|
||||||
|
PanelPage({Key key, this.title, this.panel}) : super(key: key);
|
||||||
|
|
||||||
|
final String title;
|
||||||
|
final Panel panel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
_PanelPageState createState() => new _PanelPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PanelPageState extends State<PanelPage> {
|
||||||
|
|
||||||
|
List<ConfigurationItem> _items;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
|
return new Scaffold(
|
||||||
|
appBar: new AppBar(
|
||||||
|
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
|
||||||
|
Navigator.pop(context);
|
||||||
|
}),
|
||||||
|
title: new Text(widget.title),
|
||||||
|
),
|
||||||
|
body: widget.panel.getWidget(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
38
lib/ui_class/panel_class.dart
Normal file
38
lib/ui_class/panel_class.dart
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
part of '../main.dart';
|
||||||
|
|
||||||
|
class Panel {
|
||||||
|
|
||||||
|
static const iconsByComponent = {
|
||||||
|
"config": "mdi:settings",
|
||||||
|
"history": "mdi:poll-box",
|
||||||
|
"map": "mdi:tooltip-account",
|
||||||
|
"logbook": "mdi:format-list-bulleted-type",
|
||||||
|
"custom": "mdi:home-assistant"
|
||||||
|
};
|
||||||
|
|
||||||
|
final String id;
|
||||||
|
final String type;
|
||||||
|
final String title;
|
||||||
|
final String urlPath;
|
||||||
|
final Map config;
|
||||||
|
String icon;
|
||||||
|
|
||||||
|
Panel({this.id, this.type, this.title, this.urlPath, this.icon, this.config}) {
|
||||||
|
if (icon == null || !icon.startsWith("mdi:")) {
|
||||||
|
icon = Panel.iconsByComponent[type];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget getWidget() {
|
||||||
|
switch (type) {
|
||||||
|
case "config": {
|
||||||
|
return ConfigPanelWidget();
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
return Text("Unsupported panel component: $type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,12 +1,10 @@
|
|||||||
part of 'main.dart';
|
part of '../main.dart';
|
||||||
|
|
||||||
class ConfigurationPage extends StatefulWidget {
|
class ConfigPanelWidget extends StatefulWidget {
|
||||||
ConfigurationPage({Key key, this.title}) : super(key: key);
|
ConfigPanelWidget({Key key}) : super(key: key);
|
||||||
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_ConfigurationPageState createState() => new _ConfigurationPageState();
|
_ConfigPanelWidgetState createState() => new _ConfigPanelWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConfigurationItem {
|
class ConfigurationItem {
|
||||||
@ -17,7 +15,7 @@ class ConfigurationItem {
|
|||||||
final Widget body;
|
final Widget body;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ConfigurationPageState extends State<ConfigurationPage> {
|
class _ConfigPanelWidgetState extends State<ConfigPanelWidget> {
|
||||||
|
|
||||||
List<ConfigurationItem> _items;
|
List<ConfigurationItem> _items;
|
||||||
|
|
||||||
@ -64,14 +62,7 @@ class _ConfigurationPageState extends State<ConfigurationPage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return new Scaffold(
|
return ListView(
|
||||||
appBar: new AppBar(
|
|
||||||
leading: IconButton(icon: Icon(Icons.arrow_back), onPressed: (){
|
|
||||||
Navigator.pop(context);
|
|
||||||
}),
|
|
||||||
title: new Text(widget.title),
|
|
||||||
),
|
|
||||||
body: ListView(
|
|
||||||
children: [
|
children: [
|
||||||
new ExpansionPanelList(
|
new ExpansionPanelList(
|
||||||
expansionCallback: (int index, bool isExpanded) {
|
expansionCallback: (int index, bool isExpanded) {
|
||||||
@ -94,7 +85,6 @@ class _ConfigurationPageState extends State<ConfigurationPage> {
|
|||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user