2019-09-07 18:23:04 +03:00
|
|
|
part of 'main.dart';
|
2018-10-27 17:28:47 +03:00
|
|
|
|
|
|
|
class HAView {
|
|
|
|
List<HACard> cards = [];
|
|
|
|
List<Entity> badges = [];
|
|
|
|
Entity linkedEntity;
|
2019-09-07 17:58:00 +03:00
|
|
|
final String name;
|
|
|
|
final String id;
|
|
|
|
final String iconName;
|
|
|
|
final int count;
|
|
|
|
final bool panel;
|
2018-10-27 17:28:47 +03:00
|
|
|
|
|
|
|
HAView({
|
|
|
|
this.name,
|
|
|
|
this.id,
|
|
|
|
this.count,
|
|
|
|
this.iconName,
|
2019-09-07 17:58:00 +03:00
|
|
|
this.panel: false,
|
2018-10-27 17:28:47 +03:00
|
|
|
List<Entity> childEntities
|
|
|
|
}) {
|
|
|
|
if (childEntities != null) {
|
|
|
|
_fillView(childEntities);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _fillView(List<Entity> childEntities) {
|
|
|
|
List<HACard> autoGeneratedCards = [];
|
2018-11-11 19:51:02 +02:00
|
|
|
badges.addAll(childEntities.where((entity){ return entity.isBadge;}));
|
|
|
|
childEntities.where((entity){ return entity.domain == "media_player";}).forEach((e){
|
|
|
|
HACard card = HACard(
|
|
|
|
name: e.displayName,
|
|
|
|
id: e.entityId,
|
2018-11-25 18:09:06 +02:00
|
|
|
linkedEntityWrapper: EntityWrapper(entity: e),
|
2019-09-07 15:47:09 +03:00
|
|
|
type: CardType.MEDIA_CONTROL
|
2018-11-11 19:51:02 +02:00
|
|
|
);
|
|
|
|
cards.add(card);
|
|
|
|
});
|
|
|
|
childEntities.where((e){return (!e.isBadge && e.domain != "media_player");}).forEach((entity) {
|
|
|
|
if (!entity.isGroup) {
|
|
|
|
String groupIdToAdd = "${entity.domain}.${entity.domain}$count";
|
|
|
|
if (autoGeneratedCards.every((HACard card) => card.id != groupIdToAdd )) {
|
2018-10-27 17:28:47 +03:00
|
|
|
HACard card = HACard(
|
2018-11-11 19:51:02 +02:00
|
|
|
id: groupIdToAdd,
|
|
|
|
name: entity.domain,
|
2019-09-07 15:47:09 +03:00
|
|
|
type: CardType.ENTITIES
|
2018-11-11 19:51:02 +02:00
|
|
|
);
|
2018-11-15 19:08:47 +02:00
|
|
|
card.entities.add(EntityWrapper(entity: entity));
|
2018-11-11 19:51:02 +02:00
|
|
|
autoGeneratedCards.add(card);
|
|
|
|
} else {
|
2018-11-15 19:08:47 +02:00
|
|
|
autoGeneratedCards.firstWhere((card) => card.id == groupIdToAdd).entities.add(EntityWrapper(entity: entity));
|
2018-11-11 19:51:02 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
HACard card = HACard(
|
|
|
|
name: entity.displayName,
|
|
|
|
id: entity.entityId,
|
2018-11-25 18:09:06 +02:00
|
|
|
linkedEntityWrapper: EntityWrapper(entity: entity),
|
2019-09-07 15:47:09 +03:00
|
|
|
type: CardType.ENTITIES
|
2018-11-11 19:51:02 +02:00
|
|
|
);
|
2018-11-17 22:52:06 +02:00
|
|
|
card.entities.addAll(entity.childEntities.where((entity) {return entity.domain != "media_player";}).map((e) {return EntityWrapper(entity: e);}));
|
2018-11-11 19:51:02 +02:00
|
|
|
entity.childEntities.where((entity) {return entity.domain == "media_player";}).forEach((entity){
|
|
|
|
HACard mediaCard = HACard(
|
2018-10-27 17:28:47 +03:00
|
|
|
name: entity.displayName,
|
|
|
|
id: entity.entityId,
|
2018-11-25 18:09:06 +02:00
|
|
|
linkedEntityWrapper: EntityWrapper(entity: entity),
|
2019-09-07 15:47:09 +03:00
|
|
|
type: CardType.MEDIA_CONTROL
|
2018-10-27 17:28:47 +03:00
|
|
|
);
|
2018-11-11 19:51:02 +02:00
|
|
|
cards.add(mediaCard);
|
|
|
|
});
|
|
|
|
cards.add(card);
|
2018-10-27 17:28:47 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
cards.addAll(autoGeneratedCards);
|
|
|
|
}
|
|
|
|
|
2018-11-04 22:19:45 +02:00
|
|
|
Widget buildTab() {
|
|
|
|
if (linkedEntity == null) {
|
|
|
|
if (iconName != null) {
|
|
|
|
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(
|
|
|
|
text: name.toUpperCase(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} 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(
|
|
|
|
text: linkedEntity.displayName.toUpperCase(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-27 17:28:47 +03:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ViewWidget(
|
|
|
|
view: this,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|