part of 'main.dart'; class HAView { List cards = []; List badges = []; Entity linkedEntity; final String name; final String id; final String iconName; final int count; final bool panel; HAView({ this.name, this.id, this.count, this.iconName, this.panel: false, List childEntities }) { if (childEntities != null) { _fillView(childEntities); } } void _fillView(List childEntities) { List autoGeneratedCards = []; 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, linkedEntityWrapper: EntityWrapper(entity: e), type: CardType.MEDIA_CONTROL ); 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 )) { HACard card = HACard( id: groupIdToAdd, name: entity.domain, type: CardType.ENTITIES ); card.entities.add(EntityWrapper(entity: entity)); autoGeneratedCards.add(card); } else { autoGeneratedCards.firstWhere((card) => card.id == groupIdToAdd).entities.add(EntityWrapper(entity: entity)); } } else { HACard card = HACard( name: entity.displayName, id: entity.entityId, linkedEntityWrapper: EntityWrapper(entity: entity), type: CardType.ENTITIES ); card.entities.addAll(entity.childEntities.where((entity) {return entity.domain != "media_player";}).map((e) {return EntityWrapper(entity: e);})); entity.childEntities.where((entity) {return entity.domain == "media_player";}).forEach((entity){ HACard mediaCard = HACard( name: entity.displayName, id: entity.entityId, linkedEntityWrapper: EntityWrapper(entity: entity), type: CardType.MEDIA_CONTROL ); cards.add(mediaCard); }); cards.add(card); } }); cards.addAll(autoGeneratedCards); } Widget buildTab() { if (linkedEntity == null) { if (iconName != null) { return Tab( icon: Icon( MaterialDesignIcons.getIconDataFromIconName( 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.getIconDataFromIconName( linkedEntity.icon), size: 24.0, ) ); } else { return Tab( text: linkedEntity.displayName.toUpperCase(), ); } } } Widget build(BuildContext context) { return ViewWidget( view: this, ); } }