99 lines
2.3 KiB
Dart
99 lines
2.3 KiB
Dart
part of '../main.dart';
|
|
|
|
class HAView {
|
|
List<HACard> cards = [];
|
|
List<Entity> badges = [];
|
|
Entity linkedEntity;
|
|
String name;
|
|
String id;
|
|
String iconName;
|
|
int count;
|
|
|
|
HAView({
|
|
this.name,
|
|
this.id,
|
|
this.count,
|
|
this.iconName,
|
|
List<Entity> childEntities
|
|
}) {
|
|
if (childEntities != null) {
|
|
_fillView(childEntities);
|
|
}
|
|
}
|
|
|
|
void _fillView(List<Entity> childEntities) {
|
|
List<HACard> autoGeneratedCards = [];
|
|
childEntities.forEach((entity) {
|
|
if (entity.isBadge) {
|
|
badges.add(entity);
|
|
} else {
|
|
if (!entity.isGroup) {
|
|
String groupIdToAdd = "${entity.domain}.${entity.domain}$count";
|
|
if (autoGeneratedCards.every((HACard card) => card.id != groupIdToAdd )) {
|
|
HACard card = HACard(
|
|
id: groupIdToAdd,
|
|
name: entity.domain,
|
|
type: "entities"
|
|
);
|
|
card.entities.add(entity);
|
|
autoGeneratedCards.add(card);
|
|
} else {
|
|
autoGeneratedCards.firstWhere((card) => card.id == groupIdToAdd).entities.add(entity);
|
|
}
|
|
} else {
|
|
HACard card = HACard(
|
|
name: entity.displayName,
|
|
id: entity.entityId,
|
|
linkedEntity: entity,
|
|
type: "entities"
|
|
);
|
|
card.entities.addAll(entity.childEntities);
|
|
cards.add(card);
|
|
}
|
|
}
|
|
});
|
|
cards.addAll(autoGeneratedCards);
|
|
}
|
|
|
|
Widget buildTab() {
|
|
if (linkedEntity == null) {
|
|
if (iconName != null) {
|
|
return
|
|
Tab(
|
|
icon:
|
|
Icon(
|
|
MaterialDesignIcons.createIconDataFromIconName(
|
|
iconName ?? "mdi:home-assistant"),
|
|
size: 24.0,
|
|
)
|
|
);
|
|
} else {
|
|
return
|
|
Tab(
|
|
text: name.toUpperCase(),
|
|
);
|
|
}
|
|
} else {
|
|
if (linkedEntity.icon != null && linkedEntity.icon.length > 0) {
|
|
return Tab(
|
|
icon: Icon(
|
|
MaterialDesignIcons.createIconDataFromIconName(
|
|
linkedEntity.icon),
|
|
size: 24.0,
|
|
)
|
|
);
|
|
} else {
|
|
return Tab(
|
|
text: linkedEntity.displayName.toUpperCase(),
|
|
);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
Widget build(BuildContext context) {
|
|
return ViewWidget(
|
|
view: this,
|
|
);
|
|
}
|
|
} |