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/view.class.dart

84 lines
2.1 KiB
Dart
Raw Normal View History

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;
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) {
if (iconName != null && iconName.isNotEmpty) {
2018-11-04 22:19:45 +02:00
return
Tab(
icon:
Icon(
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(
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,
);
}
}