diff --git a/lib/home_assistant.class.dart b/lib/home_assistant.class.dart index c33e428..4bcd7f7 100644 --- a/lib/home_assistant.class.dart +++ b/lib/home_assistant.class.dart @@ -296,31 +296,25 @@ class HomeAssistant { List result = []; rawCards.forEach((rawCard){ try { - bool isThereCardOptionsInside = rawCard["card"] != null; + //bool isThereCardOptionsInside = rawCard["card"] != null; + var rawCardInfo = rawCard["card"] ?? rawCard; HACard card = HACard( id: "card", - name: isThereCardOptionsInside ? rawCard["card"]["title"] ?? - rawCard["card"]["name"] : rawCard["title"] ?? rawCard["name"], - type: isThereCardOptionsInside - ? rawCard["card"]['type'] - : rawCard['type'], - columnsCount: isThereCardOptionsInside - ? rawCard["card"]['columns'] ?? 4 - : rawCard['columns'] ?? 4, - showName: isThereCardOptionsInside ? rawCard["card"]['show_name'] ?? - true : rawCard['show_name'] ?? true, - showState: isThereCardOptionsInside - ? rawCard["card"]['show_state'] ?? true - : rawCard['show_state'] ?? true, - showEmpty: rawCard['show_empty'] ?? true, - stateFilter: rawCard['state_filter'] ?? [], - states: rawCard['states'], - content: rawCard['content'] + name: rawCardInfo["title"] ?? rawCardInfo["name"], + type: rawCardInfo['type'], + columnsCount: rawCardInfo['columns'] ?? 4, + showName: rawCardInfo['show_name'] ?? true, + showState: rawCardInfo['show_state'] ?? true, + showEmpty: rawCardInfo['show_empty'] ?? true, + stateFilter: rawCardInfo['state_filter'] ?? [], + states: rawCardInfo['states'], + conditions: rawCard['conditions'] ?? [], + content: rawCardInfo['content'] ); - if (rawCard["cards"] != null) { - card.childCards = _createLovelaceCards(rawCard["cards"]); + if (rawCardInfo["cards"] != null) { + card.childCards = _createLovelaceCards(rawCardInfo["cards"]); } - rawCard["entities"]?.forEach((rawEntity) { + rawCardInfo["entities"]?.forEach((rawEntity) { if (rawEntity is String) { if (entities.isExist(rawEntity)) { card.entities.add(EntityWrapper(entity: entities.get(rawEntity))); @@ -383,15 +377,15 @@ class HomeAssistant { } } }); - if (rawCard["entity"] != null) { - var en = rawCard["entity"]; + if (rawCardInfo["entity"] != null) { + var en = rawCardInfo["entity"]; if (en is String) { if (entities.isExist(en)) { Entity e = entities.get(en); card.linkedEntityWrapper = EntityWrapper( entity: e, - icon: rawCard["icon"], - displayName: rawCard["name"], + icon: rawCardInfo["icon"], + displayName: rawCardInfo["name"], uiAction: EntityUIAction(rawEntityData: rawCard) ); } else { diff --git a/lib/ui_class/card.class.dart b/lib/ui_class/card.class.dart index ea85224..c7ba1cb 100644 --- a/lib/ui_class/card.class.dart +++ b/lib/ui_class/card.class.dart @@ -13,6 +13,7 @@ class HACard { int columnsCount; List stateFilter; List states; + List conditions; String content; HACard({ @@ -26,6 +27,7 @@ class HACard { this.showEmpty: true, this.content, this.states, + this.conditions, @required this.type }); diff --git a/lib/ui_widgets/card_widget.dart b/lib/ui_widgets/card_widget.dart index db7ffb1..ad9c6ab 100644 --- a/lib/ui_widgets/card_widget.dart +++ b/lib/ui_widgets/card_widget.dart @@ -24,6 +24,22 @@ class CardWidget extends StatelessWidget { } } + if (card.conditions.isNotEmpty) { + bool showCardByConditions = false; + for (var condition in card.conditions) { + Entity conditionEntity = HomeAssistant().entities.get(condition['entity']); + if (conditionEntity != null && + (condition['state'] != null && conditionEntity.state == condition['state']) || + (condition['state_not'] != null && conditionEntity.state != condition['state_not']) + ) { + showCardByConditions = true; + } + } + if (!showCardByConditions) { + return Container(width: 0.0, height: 0.0,); + } + } + switch (card.type) { case CardType.entities: {