2019-09-07 18:23:04 +03:00
|
|
|
part of '../main.dart';
|
2018-12-07 22:04:14 +02:00
|
|
|
|
2020-04-25 20:38:21 +03:00
|
|
|
class LovelaceCard extends StatelessWidget {
|
2018-12-07 22:04:14 +02:00
|
|
|
|
|
|
|
final HACard card;
|
|
|
|
|
2020-04-25 20:38:21 +03:00
|
|
|
const LovelaceCard({
|
2018-12-07 22:04:14 +02:00
|
|
|
Key key,
|
|
|
|
this.card
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-03-12 23:35:33 +02:00
|
|
|
if (card.linkedEntityWrapper!= null) {
|
|
|
|
if (card.linkedEntityWrapper.entity.isHidden) {
|
|
|
|
return Container(width: 0.0, height: 0.0,);
|
|
|
|
}
|
2019-03-13 00:56:57 +02:00
|
|
|
if (card.linkedEntityWrapper.entity.statelessType == StatelessEntityType.MISSED) {
|
2019-03-12 23:35:33 +02:00
|
|
|
return EntityModel(
|
|
|
|
entityWrapper: card.linkedEntityWrapper,
|
|
|
|
child: MissedEntityWidget(),
|
|
|
|
handleTap: false,
|
|
|
|
);
|
|
|
|
}
|
2018-12-07 22:04:14 +02:00
|
|
|
}
|
|
|
|
|
2019-08-27 20:05:33 +03:00
|
|
|
if (card.conditions.isNotEmpty) {
|
2019-09-09 13:36:33 +03:00
|
|
|
bool showCardByConditions = true;
|
2019-08-26 17:03:28 +03:00
|
|
|
for (var condition in card.conditions) {
|
|
|
|
Entity conditionEntity = HomeAssistant().entities.get(condition['entity']);
|
|
|
|
if (conditionEntity != null &&
|
2019-09-09 13:36:33 +03:00
|
|
|
((condition['state'] != null && conditionEntity.state != condition['state']) ||
|
|
|
|
(condition['state_not'] != null && conditionEntity.state == condition['state_not']))
|
2019-08-26 17:03:28 +03:00
|
|
|
) {
|
2019-09-09 13:36:33 +03:00
|
|
|
showCardByConditions = false;
|
|
|
|
break;
|
2019-08-26 17:03:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!showCardByConditions) {
|
|
|
|
return Container(width: 0.0, height: 0.0,);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:04:14 +02:00
|
|
|
switch (card.type) {
|
|
|
|
|
2019-09-07 15:47:09 +03:00
|
|
|
case CardType.ENTITIES: {
|
2020-04-25 20:38:21 +03:00
|
|
|
return EntitiesCard(card: card);
|
2018-12-07 22:04:14 +02:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:47:09 +03:00
|
|
|
case CardType.GLANCE: {
|
2020-04-25 18:59:07 +03:00
|
|
|
return GlanceCard(card: card);
|
2018-12-07 22:04:14 +02:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:47:09 +03:00
|
|
|
case CardType.MEDIA_CONTROL: {
|
2020-04-25 20:38:21 +03:00
|
|
|
return MediaControlsCard(card: card);
|
2018-12-07 22:04:14 +02:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:47:09 +03:00
|
|
|
case CardType.ENTITY_BUTTON: {
|
2020-04-25 18:59:07 +03:00
|
|
|
return EntityButtonCard(card: card);
|
2020-04-13 21:17:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case CardType.BUTTON: {
|
2020-04-25 18:59:07 +03:00
|
|
|
return EntityButtonCard(card: card);
|
2018-12-07 22:04:14 +02:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:47:09 +03:00
|
|
|
case CardType.GAUGE: {
|
2020-04-25 18:59:07 +03:00
|
|
|
return GaugeCard(card: card);
|
2019-09-07 15:47:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case CardType.MARKDOWN: {
|
2020-04-25 20:38:21 +03:00
|
|
|
return MarkdownCard(card: card);
|
2019-01-23 23:34:45 +02:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:47:09 +03:00
|
|
|
case CardType.ALARM_PANEL: {
|
2020-04-25 20:38:21 +03:00
|
|
|
return AlarmPanelCard(card: card);
|
2019-01-29 15:00:15 +02:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:47:09 +03:00
|
|
|
case CardType.HORIZONTAL_STACK: {
|
2020-04-25 20:38:21 +03:00
|
|
|
return HorizontalStackCard(card: card);
|
2018-12-07 22:04:14 +02:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:47:09 +03:00
|
|
|
case CardType.VERTICAL_STACK: {
|
2020-04-25 20:38:21 +03:00
|
|
|
return VerticalStackCard(card: card);
|
2018-12-07 22:04:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default: {
|
|
|
|
if ((card.linkedEntityWrapper == null) && (card.entities.isNotEmpty)) {
|
2020-04-25 20:38:21 +03:00
|
|
|
return EntitiesCard(card: card);
|
2018-12-07 22:04:14 +02:00
|
|
|
} else {
|
2020-04-25 20:38:21 +03:00
|
|
|
return UnsupportedCard(card: card);
|
2018-12-07 22:04:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:05:33 +03:00
|
|
|
}
|