This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/ui.dart
2020-04-21 09:01:21 +00:00

71 lines
1.7 KiB
Dart

part of 'main.dart';
class HomeAssistantUI {
List<HAView> views;
String title;
bool get isEmpty => views == null || views.isEmpty;
HomeAssistantUI({rawLovelaceConfig}) {
if (rawLovelaceConfig == null) {
rawLovelaceConfig = _generateLovelaceConfig();
}
views = [];
Logger.d("--Title: ${rawLovelaceConfig["title"]}");
title = rawLovelaceConfig["title"];
int viewCounter = 0;
Logger.d("--Views count: ${rawLovelaceConfig['views'].length}");
rawLovelaceConfig["views"].forEach((rawView){
Logger.d("----view id: ${rawView['id']}");
HAView view = HAView(
count: viewCounter,
rawData: rawView
);
views.add(
view
);
viewCounter += 1;
});
}
Map _generateLovelaceConfig() {
Map result = {};
result['title'] = 'Home';
result['views'] = [
{
'icon': 'mdi:home',
'badges': HomeAssistant().entities.getByDomains(
includeDomains: ['sensor', 'binary_sensor', 'device_tracker', 'person', 'sun']
).map(
(en) => en.entityId
).toList(),
'cards': [{
'type': 'entities',
'entities': HomeAssistant().entities.getByDomains(
excludeDomains: ['sensor','binary_sensor', 'device_tracker', 'person', 'sun']
).map(
(en) => en.entityId
).toList()
}]
}
];
return result;
}
Widget build(BuildContext context, TabController tabController) {
return TabBarView(
controller: tabController,
children: _buildViews(context)
);
}
List<Widget> _buildViews(BuildContext context) {
return views.map((view) => view.build(context)).toList();
}
void clear() {
views.clear();
}
}