Resolves #539 Fix button card without entity
This commit is contained in:
parent
05c1427aa8
commit
2c3335ebf3
@ -22,6 +22,7 @@ class HACard {
|
||||
int max;
|
||||
int depth;
|
||||
Map severity;
|
||||
EntityUIAction action;
|
||||
|
||||
HACard({
|
||||
this.name,
|
||||
@ -117,5 +118,4 @@ class HACard {
|
||||
return showByFilter;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ class LovelaceCard extends StatelessWidget {
|
||||
if (card.linkedEntityWrapper.entity.isHidden) {
|
||||
return Container(width: 0.0, height: 0.0,);
|
||||
}
|
||||
if (card.linkedEntityWrapper.entity.statelessType == StatelessEntityType.MISSED) {
|
||||
if (card.linkedEntityWrapper.entity.statelessType == StatelessEntityType.missed) {
|
||||
return EntityModel(
|
||||
entityWrapper: card.linkedEntityWrapper,
|
||||
child: MissedEntityWidget(),
|
||||
|
@ -10,39 +10,45 @@ class EntityButtonCard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
card.linkedEntityWrapper.overrideName = card.name?.toUpperCase() ??
|
||||
card.linkedEntityWrapper.displayName.toUpperCase();
|
||||
//card.linkedEntityWrapper.overrideName = card.name?.toUpperCase() ??
|
||||
// card.linkedEntityWrapper.displayName.toUpperCase();
|
||||
EntityWrapper entityWrapper = card.linkedEntityWrapper;
|
||||
if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) {
|
||||
if (entityWrapper.entity.statelessType == StatelessEntityType.missed) {
|
||||
return MissedEntityWidget();
|
||||
}
|
||||
if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) {
|
||||
} else if (entityWrapper.entity.statelessType != StatelessEntityType.ghost && entityWrapper.entity.statelessType != StatelessEntityType.none) {
|
||||
return Container(width: 0.0, height: 0.0,);
|
||||
}
|
||||
double widthBase = math.min(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height) / 6;
|
||||
|
||||
|
||||
Widget buttonIcon;
|
||||
if (entityWrapper.icon == null || entityWrapper.icon.isEmpty) {
|
||||
buttonIcon = Container(height: Sizes.rowPadding, width: 10);
|
||||
} else {
|
||||
buttonIcon = EntityIcon(
|
||||
padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0),
|
||||
size: widthBase / (card.depth * 0.5),
|
||||
);
|
||||
}
|
||||
|
||||
return CardWrapper(
|
||||
child: Center(
|
||||
child: EntityModel(
|
||||
entityWrapper: card.linkedEntityWrapper,
|
||||
child: InkWell(
|
||||
onTap: () => entityWrapper.handleTap(),
|
||||
onLongPress: () => entityWrapper.handleHold(),
|
||||
onDoubleTap: () => entityWrapper.handleDoubleTap(),
|
||||
child: EntityModel(
|
||||
entityWrapper: card.linkedEntityWrapper,
|
||||
child: InkWell(
|
||||
onTap: () => entityWrapper.handleTap(),
|
||||
onLongPress: () => entityWrapper.handleHold(),
|
||||
onDoubleTap: () => entityWrapper.handleDoubleTap(),
|
||||
child: Container(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
EntityIcon(
|
||||
padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0),
|
||||
size: widthBase / (card.depth * 0.5),
|
||||
),
|
||||
buttonIcon,
|
||||
_buildName()
|
||||
],
|
||||
),
|
||||
)
|
||||
),
|
||||
handleTap: true
|
||||
),
|
||||
handleTap: true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -59,10 +59,9 @@ class GlanceCard extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildEntityContainer(BuildContext context, EntityWrapper entityWrapper) {
|
||||
if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) {
|
||||
if (entityWrapper.entity.statelessType == StatelessEntityType.missed) {
|
||||
return MissedEntityWidget();
|
||||
}
|
||||
if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) {
|
||||
} else if (entityWrapper.entity.statelessType != StatelessEntityType.none) {
|
||||
return Container(width: 0.0, height: 0.0,);
|
||||
}
|
||||
List<Widget> result = [];
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -14,7 +14,6 @@ class BottomInfoBarController {
|
||||
List<HAErrorAction> actions = [];
|
||||
|
||||
void hideBottomBar() {
|
||||
//_scaffoldKey?.currentState?.hideCurrentSnackBar();
|
||||
_bottomBarTimer?.cancel();
|
||||
if (hide == null) {
|
||||
initialState = false;
|
||||
@ -32,7 +31,6 @@ class BottomInfoBarController {
|
||||
if (show == null) {
|
||||
initialState = true;
|
||||
} else {
|
||||
Logger.d("Calling show() - ${bottomBarProgress}");
|
||||
show();
|
||||
}
|
||||
if (duration != null) {
|
||||
@ -78,7 +76,6 @@ class _BottomInfoBarState extends State<BottomInfoBar> {
|
||||
void initState() {
|
||||
_show = widget.controller.initialState;
|
||||
widget.controller.show = () {
|
||||
Logger.d('Set state in show() - ${widget.controller.bottomBarProgress}');
|
||||
setState(() {
|
||||
_show = true;
|
||||
});
|
||||
|
@ -66,72 +66,73 @@ class HAView {
|
||||
card.childCards = _createLovelaceCards(rawCardInfo["cards"], depth + 1);
|
||||
}
|
||||
var rawEntities = rawCard["entities"] ?? rawCardInfo["entities"];
|
||||
rawEntities?.forEach((rawEntity) {
|
||||
if (rawEntity is String) {
|
||||
if (HomeAssistant().entities.isExist(rawEntity)) {
|
||||
card.entities.add(EntityWrapper(entity: HomeAssistant().entities.get(rawEntity)));
|
||||
var rawSingleEntity = rawCard["entity"] ?? rawCardInfo["entity"];
|
||||
if (rawEntities != null) {
|
||||
rawEntities.forEach((rawEntity) {
|
||||
if (rawEntity is String) {
|
||||
if (HomeAssistant().entities.isExist(rawEntity)) {
|
||||
card.entities.add(EntityWrapper(entity: HomeAssistant().entities.get(rawEntity)));
|
||||
} else {
|
||||
card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity)));
|
||||
}
|
||||
} else {
|
||||
card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity)));
|
||||
}
|
||||
} else {
|
||||
if (rawEntity["type"] == "divider") {
|
||||
card.entities.add(EntityWrapper(entity: Entity.divider()));
|
||||
} else if (rawEntity["type"] == "section") {
|
||||
card.entities.add(EntityWrapper(entity: Entity.section(rawEntity["label"] ?? "")));
|
||||
} else if (rawEntity["type"] == "call-service") {
|
||||
Map uiActionData = {
|
||||
"tap_action": {
|
||||
"action": EntityUIAction.callService,
|
||||
"service": rawEntity["service"],
|
||||
"service_data": rawEntity["service_data"]
|
||||
},
|
||||
"hold_action": EntityUIAction.none
|
||||
};
|
||||
card.entities.add(EntityWrapper(
|
||||
if (rawEntity["type"] == "divider") {
|
||||
card.entities.add(EntityWrapper(entity: Entity.divider()));
|
||||
} else if (rawEntity["type"] == "section") {
|
||||
card.entities.add(EntityWrapper(entity: Entity.section(rawEntity["label"] ?? "")));
|
||||
} else if (rawEntity["type"] == "call-service") {
|
||||
Map uiActionData = {
|
||||
"tap_action": {
|
||||
"action": EntityUIAction.callService,
|
||||
"service": rawEntity["service"],
|
||||
"service_data": rawEntity["service_data"]
|
||||
},
|
||||
"hold_action": EntityUIAction.none
|
||||
};
|
||||
card.entities.add(EntityWrapper(
|
||||
entity: Entity.callService(
|
||||
icon: rawEntity["icon"],
|
||||
name: rawEntity["name"],
|
||||
service: rawEntity["service"],
|
||||
actionName: rawEntity["action_name"]
|
||||
),
|
||||
uiAction: EntityUIAction(rawEntityData: uiActionData)
|
||||
)
|
||||
);
|
||||
} else if (rawEntity["type"] == "weblink") {
|
||||
Map uiActionData = {
|
||||
"tap_action": {
|
||||
"action": EntityUIAction.navigate,
|
||||
"service": rawEntity["url"]
|
||||
},
|
||||
"hold_action": EntityUIAction.none
|
||||
};
|
||||
card.entities.add(EntityWrapper(
|
||||
entity: Entity.weblink(
|
||||
icon: rawEntity["icon"],
|
||||
name: rawEntity["name"],
|
||||
url: rawEntity["url"]
|
||||
),
|
||||
uiAction: EntityUIAction(rawEntityData: uiActionData)
|
||||
)
|
||||
);
|
||||
} else if (HomeAssistant().entities.isExist(rawEntity["entity"])) {
|
||||
Entity e = HomeAssistant().entities.get(rawEntity["entity"]);
|
||||
card.entities.add(
|
||||
EntityWrapper(
|
||||
entity: e,
|
||||
overrideName: rawEntity["name"],
|
||||
overrideIcon: rawEntity["icon"],
|
||||
stateFilter: rawEntity['state_filter'] ?? [],
|
||||
uiAction: EntityUIAction(rawEntityData: rawEntity)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity["entity"])));
|
||||
)
|
||||
);
|
||||
} else if (rawEntity["type"] == "weblink") {
|
||||
Map uiActionData = {
|
||||
"tap_action": {
|
||||
"action": EntityUIAction.navigate,
|
||||
"service": rawEntity["url"]
|
||||
},
|
||||
"hold_action": EntityUIAction.none
|
||||
};
|
||||
card.entities.add(EntityWrapper(
|
||||
entity: Entity.weblink(
|
||||
icon: rawEntity["icon"],
|
||||
name: rawEntity["name"],
|
||||
url: rawEntity["url"]
|
||||
),
|
||||
uiAction: EntityUIAction(rawEntityData: uiActionData)
|
||||
)
|
||||
);
|
||||
} else if (HomeAssistant().entities.isExist(rawEntity["entity"])) {
|
||||
Entity e = HomeAssistant().entities.get(rawEntity["entity"]);
|
||||
card.entities.add(
|
||||
EntityWrapper(
|
||||
entity: e,
|
||||
overrideName: rawEntity["name"],
|
||||
overrideIcon: rawEntity["icon"],
|
||||
stateFilter: rawEntity['state_filter'] ?? [],
|
||||
uiAction: EntityUIAction(rawEntityData: rawEntity)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity["entity"])));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
var rawSingleEntity = rawCard["entity"] ?? rawCardInfo["entity"];
|
||||
if (rawSingleEntity != null) {
|
||||
});
|
||||
} else if (rawSingleEntity != null) {
|
||||
var en = rawSingleEntity;
|
||||
if (en is String) {
|
||||
if (HomeAssistant().entities.isExist(en)) {
|
||||
@ -159,6 +160,16 @@ class HAView {
|
||||
card.linkedEntityWrapper = EntityWrapper(entity: Entity.missed(en["entity"]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
card.linkedEntityWrapper = EntityWrapper(
|
||||
entity: Entity.ghost(
|
||||
card.name,
|
||||
card.icon,
|
||||
),
|
||||
uiAction: EntityUIAction(
|
||||
rawEntityData: rawCardInfo
|
||||
)
|
||||
);
|
||||
}
|
||||
result.add(card);
|
||||
} catch (e) {
|
||||
|
Reference in New Issue
Block a user