2018-10-27 17:28:47 +03:00
|
|
|
part of '../main.dart';
|
|
|
|
|
|
|
|
class HACard {
|
2018-11-15 19:08:47 +02:00
|
|
|
List<EntityWrapper> entities = [];
|
2018-11-25 20:44:19 +02:00
|
|
|
List<HACard> childCards = [];
|
2018-11-25 18:09:06 +02:00
|
|
|
EntityWrapper linkedEntityWrapper;
|
2018-10-27 17:28:47 +03:00
|
|
|
String name;
|
|
|
|
String id;
|
|
|
|
String type;
|
2018-11-15 19:08:47 +02:00
|
|
|
bool showName;
|
|
|
|
bool showState;
|
2018-12-07 22:04:14 +02:00
|
|
|
bool showEmpty;
|
2020-02-19 12:17:08 +02:00
|
|
|
bool showHeaderToggle;
|
2018-11-14 19:52:17 +02:00
|
|
|
int columnsCount;
|
2018-12-07 22:04:14 +02:00
|
|
|
List stateFilter;
|
2019-01-29 15:00:15 +02:00
|
|
|
List states;
|
2019-08-26 17:03:28 +03:00
|
|
|
List conditions;
|
2019-01-23 23:34:45 +02:00
|
|
|
String content;
|
2019-09-07 15:47:09 +03:00
|
|
|
String unit;
|
|
|
|
int min;
|
|
|
|
int max;
|
2020-04-25 17:15:19 +03:00
|
|
|
int depth;
|
2019-09-07 15:47:09 +03:00
|
|
|
Map severity;
|
2018-10-27 17:28:47 +03:00
|
|
|
|
|
|
|
HACard({
|
|
|
|
this.name,
|
|
|
|
this.id,
|
2018-11-25 18:09:06 +02:00
|
|
|
this.linkedEntityWrapper,
|
2018-11-14 19:52:17 +02:00
|
|
|
this.columnsCount: 4,
|
2018-11-15 19:08:47 +02:00
|
|
|
this.showName: true,
|
2020-02-19 12:17:08 +02:00
|
|
|
this.showHeaderToggle: true,
|
2018-11-15 19:08:47 +02:00
|
|
|
this.showState: true,
|
2018-12-07 22:04:14 +02:00
|
|
|
this.stateFilter: const [],
|
|
|
|
this.showEmpty: true,
|
2019-01-23 23:34:45 +02:00
|
|
|
this.content,
|
2019-01-29 15:00:15 +02:00
|
|
|
this.states,
|
2019-08-27 20:05:33 +03:00
|
|
|
this.conditions: const [],
|
2019-09-07 15:47:09 +03:00
|
|
|
this.unit,
|
|
|
|
this.min,
|
|
|
|
this.max,
|
2020-04-25 17:15:19 +03:00
|
|
|
this.depth: 1,
|
2019-09-07 15:47:09 +03:00
|
|
|
this.severity,
|
2018-10-27 17:28:47 +03:00
|
|
|
@required this.type
|
2019-09-04 23:42:19 +03:00
|
|
|
}) {
|
|
|
|
if (this.columnsCount <= 0) {
|
|
|
|
this.columnsCount = 4;
|
|
|
|
}
|
|
|
|
}
|
2018-10-27 17:28:47 +03:00
|
|
|
|
2018-12-07 22:04:14 +02:00
|
|
|
List<EntityWrapper> getEntitiesToShow() {
|
|
|
|
return entities.where((entityWrapper) {
|
2020-03-20 12:14:14 +02:00
|
|
|
if (HomeAssistant().autoUi && entityWrapper.entity.isHidden) {
|
2018-12-07 22:04:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-03-12 23:16:07 +02:00
|
|
|
List currentStateFilter;
|
|
|
|
if (entityWrapper.stateFilter != null && entityWrapper.stateFilter.isNotEmpty) {
|
|
|
|
currentStateFilter = entityWrapper.stateFilter;
|
|
|
|
} else {
|
|
|
|
currentStateFilter = stateFilter;
|
2018-10-27 17:28:47 +03:00
|
|
|
}
|
2020-03-12 23:16:07 +02:00
|
|
|
bool showByFilter = currentStateFilter.isEmpty;
|
|
|
|
for (var allowedState in currentStateFilter) {
|
|
|
|
if (allowedState is String && allowedState == entityWrapper.entity.state) {
|
|
|
|
showByFilter = true;
|
|
|
|
break;
|
|
|
|
} else if (allowedState is Map) {
|
|
|
|
try {
|
|
|
|
var tmpVal = allowedState['attribute'] != null ? entityWrapper.entity.getAttribute(allowedState['attribute']) : entityWrapper.entity.state;
|
|
|
|
var valToCompareWith = allowedState['value'];
|
|
|
|
var valToCompare;
|
2020-03-12 23:19:39 +02:00
|
|
|
if (valToCompareWith is! String && tmpVal is String) {
|
2020-03-12 23:16:07 +02:00
|
|
|
valToCompare = double.tryParse(tmpVal);
|
|
|
|
} else {
|
|
|
|
valToCompare = tmpVal;
|
|
|
|
}
|
|
|
|
if (valToCompare != null) {
|
|
|
|
bool result;
|
|
|
|
switch (allowedState['operator']) {
|
|
|
|
case '<=': { result = valToCompare <= valToCompareWith;}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '<': { result = valToCompare < valToCompareWith;}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '>=': { result = valToCompare >= valToCompareWith;}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '>': { result = valToCompare > valToCompareWith;}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '!=': { result = valToCompare != valToCompareWith;}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'regex': {
|
|
|
|
RegExp regExp = RegExp(valToCompareWith.toString());
|
|
|
|
result = regExp.hasMatch(valToCompare.toString());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
result = valToCompare == valToCompareWith;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result) {
|
|
|
|
showByFilter = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
Logger.e('Error filtering ${entityWrapper.entity.entityId} by $allowedState');
|
|
|
|
Logger.e('$e');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return showByFilter;
|
2018-12-07 22:04:14 +02:00
|
|
|
}).toList();
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return CardWidget(
|
|
|
|
card: this,
|
|
|
|
);
|
2018-10-27 17:28:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|