Resolves #539 Fix button card without entity
This commit is contained in:
@ -11,13 +11,13 @@ class DefaultEntityContainer extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final EntityModel entityModel = EntityModel.of(context);
|
||||
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.MISSED) {
|
||||
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.missed) {
|
||||
return MissedEntityWidget();
|
||||
}
|
||||
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.DIVIDER) {
|
||||
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.divider) {
|
||||
return Divider();
|
||||
}
|
||||
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.SECTION) {
|
||||
if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.section) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
|
@ -1,13 +1,6 @@
|
||||
part of '../main.dart';
|
||||
|
||||
class StatelessEntityType {
|
||||
static const NONE = 0;
|
||||
static const MISSED = 1;
|
||||
static const DIVIDER = 2;
|
||||
static const SECTION = 3;
|
||||
static const CALL_SERVICE = 4;
|
||||
static const WEBLINK = 5;
|
||||
}
|
||||
enum StatelessEntityType {none, missed, ghost, divider, section, callService, webLink}
|
||||
|
||||
class Entity {
|
||||
|
||||
@ -77,7 +70,7 @@ class Entity {
|
||||
String state;
|
||||
String displayState;
|
||||
DateTime lastUpdatedTimestamp;
|
||||
int statelessType = 0;
|
||||
StatelessEntityType statelessType = StatelessEntityType.none;
|
||||
|
||||
List<Entity> childEntities = [];
|
||||
String deviceClass;
|
||||
@ -120,30 +113,35 @@ class Entity {
|
||||
}
|
||||
|
||||
Entity.missed(String entityId) {
|
||||
statelessType = StatelessEntityType.MISSED;
|
||||
statelessType = StatelessEntityType.missed;
|
||||
attributes = {"hidden": false};
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
Entity.divider() {
|
||||
statelessType = StatelessEntityType.DIVIDER;
|
||||
statelessType = StatelessEntityType.divider;
|
||||
attributes = {"hidden": false};
|
||||
}
|
||||
|
||||
Entity.section(String label) {
|
||||
statelessType = StatelessEntityType.SECTION;
|
||||
statelessType = StatelessEntityType.section;
|
||||
attributes = {"hidden": false, "friendly_name": "$label"};
|
||||
}
|
||||
|
||||
Entity.ghost(String name, String icon) {
|
||||
statelessType = StatelessEntityType.ghost;
|
||||
attributes = {"icon": icon, "hidden": false, "friendly_name": name};
|
||||
}
|
||||
|
||||
Entity.callService({String icon, String name, String service, String actionName}) {
|
||||
statelessType = StatelessEntityType.CALL_SERVICE;
|
||||
statelessType = StatelessEntityType.callService;
|
||||
entityId = service;
|
||||
displayState = actionName?.toUpperCase() ?? "RUN";
|
||||
attributes = {"hidden": false, "friendly_name": "$name", "icon": "$icon"};
|
||||
}
|
||||
|
||||
Entity.weblink({String url, String name, String icon}) {
|
||||
statelessType = StatelessEntityType.WEBLINK;
|
||||
statelessType = StatelessEntityType.webLink;
|
||||
entityId = "custom.custom";
|
||||
attributes = {"hidden": false, "friendly_name": "${name ?? url}", "icon": "${icon ?? 'mdi:link'}"};
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class EntityName extends StatelessWidget {
|
||||
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
|
||||
TextStyle tStyle;
|
||||
if (textStyle == null) {
|
||||
if (entityWrapper.entity.statelessType == StatelessEntityType.WEBLINK) {
|
||||
if (entityWrapper.entity.statelessType == StatelessEntityType.webLink) {
|
||||
tStyle = HAClientTheme().getLinkTextStyle(context);
|
||||
} else {
|
||||
tStyle = Theme.of(context).textTheme.body1;
|
||||
|
@ -21,7 +21,7 @@ class EntityWrapper {
|
||||
this.uiAction,
|
||||
this.stateFilter
|
||||
}) {
|
||||
if (entity.statelessType == StatelessEntityType.NONE || entity.statelessType == StatelessEntityType.CALL_SERVICE || entity.statelessType == StatelessEntityType.WEBLINK) {
|
||||
if (entity.statelessType == StatelessEntityType.ghost || entity.statelessType == StatelessEntityType.none || entity.statelessType == StatelessEntityType.callService || entity.statelessType == StatelessEntityType.webLink) {
|
||||
if (uiAction == null) {
|
||||
uiAction = EntityUIAction();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class SimpleEntityState extends StatelessWidget {
|
||||
TextStyle tStyle;
|
||||
if (textStyle != null) {
|
||||
tStyle = textStyle;
|
||||
} else if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.CALL_SERVICE) {
|
||||
} else if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.callService) {
|
||||
tStyle = Theme.of(context).textTheme.subhead.copyWith(
|
||||
color: Colors.blue
|
||||
);
|
||||
|
Reference in New Issue
Block a user