2019-09-07 18:23:04 +03:00
|
|
|
part of 'main.dart';
|
2018-10-27 17:28:47 +03:00
|
|
|
|
|
|
|
class HAView {
|
2020-04-27 01:46:37 +03:00
|
|
|
List<CardData> cards = [];
|
2018-10-27 17:28:47 +03:00
|
|
|
List<Entity> badges = [];
|
|
|
|
Entity linkedEntity;
|
2020-03-22 01:11:00 +02:00
|
|
|
String name;
|
|
|
|
String id;
|
|
|
|
String iconName;
|
2019-09-07 17:58:00 +03:00
|
|
|
final int count;
|
2020-03-22 01:11:00 +02:00
|
|
|
bool isPanel;
|
2018-10-27 17:28:47 +03:00
|
|
|
|
2020-03-22 01:11:00 +02:00
|
|
|
HAView({@required this.count, @required rawData}) {
|
|
|
|
id = "${rawData['id']}";
|
|
|
|
name = rawData['title'];
|
|
|
|
iconName = rawData['icon'];
|
|
|
|
isPanel = rawData['panel'] ?? false;
|
|
|
|
|
|
|
|
if (rawData['badges'] != null && rawData['badges'] is List) {
|
|
|
|
rawData['badges'].forEach((entity) {
|
|
|
|
if (entity is String) {
|
|
|
|
if (HomeAssistant().entities.isExist(entity)) {
|
|
|
|
Entity e = HomeAssistant().entities.get(entity);
|
|
|
|
badges.add(e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String eId = '${entity['entity']}';
|
|
|
|
if (HomeAssistant().entities.isExist(eId)) {
|
|
|
|
Entity e = HomeAssistant().entities.get(eId);
|
|
|
|
badges.add(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-27 01:46:37 +03:00
|
|
|
(rawData["cards"] ?? []).forEach((rawCardData) {
|
|
|
|
cards.add(CardData.parse(rawCardData));
|
|
|
|
});
|
2018-10-27 17:28:47 +03:00
|
|
|
|
2020-04-27 01:46:37 +03:00
|
|
|
//cards.addAll(_createLovelaceCards(rawData["cards"] ?? [], 1));
|
2018-10-27 17:28:47 +03:00
|
|
|
}
|
|
|
|
|
2018-11-04 22:19:45 +02:00
|
|
|
Widget buildTab() {
|
|
|
|
if (linkedEntity == null) {
|
2020-03-12 23:16:07 +02:00
|
|
|
if (iconName != null && iconName.isNotEmpty) {
|
2018-11-04 22:19:45 +02:00
|
|
|
return
|
|
|
|
Tab(
|
|
|
|
icon:
|
|
|
|
Icon(
|
2019-02-22 15:15:27 +02:00
|
|
|
MaterialDesignIcons.getIconDataFromIconName(
|
2018-11-04 22:19:45 +02:00
|
|
|
iconName ?? "mdi:home-assistant"),
|
|
|
|
size: 24.0,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return
|
|
|
|
Tab(
|
2019-09-18 21:14:21 +03:00
|
|
|
text: "${name?.toUpperCase() ?? "UNNAMED VIEW"}",
|
2018-11-04 22:19:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (linkedEntity.icon != null && linkedEntity.icon.length > 0) {
|
|
|
|
return Tab(
|
|
|
|
icon: Icon(
|
2019-02-22 15:15:27 +02:00
|
|
|
MaterialDesignIcons.getIconDataFromIconName(
|
2018-11-04 22:19:45 +02:00
|
|
|
linkedEntity.icon),
|
|
|
|
size: 24.0,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Tab(
|
2019-09-18 21:14:21 +03:00
|
|
|
text: "${linkedEntity.displayName?.toUpperCase()}",
|
2018-11-04 22:19:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-27 17:28:47 +03:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ViewWidget(
|
|
|
|
view: this,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|