Resolves #539 Fix button card without entity
This commit is contained in:
		| @@ -22,6 +22,7 @@ class HACard { | |||||||
|   int max; |   int max; | ||||||
|   int depth; |   int depth; | ||||||
|   Map severity; |   Map severity; | ||||||
|  |   EntityUIAction action; | ||||||
|  |  | ||||||
|   HACard({ |   HACard({ | ||||||
|     this.name, |     this.name, | ||||||
| @@ -117,5 +118,4 @@ class HACard { | |||||||
|       return showByFilter; |       return showByFilter; | ||||||
|     }).toList(); |     }).toList(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| } | } | ||||||
| @@ -15,7 +15,7 @@ class LovelaceCard extends StatelessWidget { | |||||||
|       if (card.linkedEntityWrapper.entity.isHidden) { |       if (card.linkedEntityWrapper.entity.isHidden) { | ||||||
|         return Container(width: 0.0, height: 0.0,); |         return Container(width: 0.0, height: 0.0,); | ||||||
|       } |       } | ||||||
|       if (card.linkedEntityWrapper.entity.statelessType == StatelessEntityType.MISSED) { |       if (card.linkedEntityWrapper.entity.statelessType == StatelessEntityType.missed) { | ||||||
|         return EntityModel( |         return EntityModel( | ||||||
|           entityWrapper: card.linkedEntityWrapper, |           entityWrapper: card.linkedEntityWrapper, | ||||||
|           child: MissedEntityWidget(), |           child: MissedEntityWidget(), | ||||||
|   | |||||||
| @@ -10,39 +10,45 @@ class EntityButtonCard extends StatelessWidget { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     card.linkedEntityWrapper.overrideName = card.name?.toUpperCase() ?? |     //card.linkedEntityWrapper.overrideName = card.name?.toUpperCase() ?? | ||||||
|         card.linkedEntityWrapper.displayName.toUpperCase(); |     //    card.linkedEntityWrapper.displayName.toUpperCase(); | ||||||
|     EntityWrapper entityWrapper = card.linkedEntityWrapper; |     EntityWrapper entityWrapper = card.linkedEntityWrapper; | ||||||
|     if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { |     if (entityWrapper.entity.statelessType == StatelessEntityType.missed) { | ||||||
|       return MissedEntityWidget(); |       return MissedEntityWidget(); | ||||||
|     } |     } else if (entityWrapper.entity.statelessType != StatelessEntityType.ghost && entityWrapper.entity.statelessType != StatelessEntityType.none) { | ||||||
|     if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) { |  | ||||||
|       return Container(width: 0.0, height: 0.0,); |       return Container(width: 0.0, height: 0.0,); | ||||||
|     } |     } | ||||||
|     double widthBase =  math.min(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height) / 6; |     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( |     return CardWrapper( | ||||||
|       child: Center( |  | ||||||
|       child: EntityModel( |       child: EntityModel( | ||||||
|         entityWrapper: card.linkedEntityWrapper, |         entityWrapper: card.linkedEntityWrapper, | ||||||
|         child: InkWell( |         child: InkWell( | ||||||
|           onTap: () => entityWrapper.handleTap(), |           onTap: () => entityWrapper.handleTap(), | ||||||
|           onLongPress: () => entityWrapper.handleHold(), |           onLongPress: () => entityWrapper.handleHold(), | ||||||
|           onDoubleTap: () => entityWrapper.handleDoubleTap(), |           onDoubleTap: () => entityWrapper.handleDoubleTap(), | ||||||
|  |           child: Container( | ||||||
|             child: Column( |             child: Column( | ||||||
|               mainAxisSize: MainAxisSize.min, |               mainAxisSize: MainAxisSize.min, | ||||||
|  |               crossAxisAlignment: CrossAxisAlignment.stretch, | ||||||
|               children: <Widget>[ |               children: <Widget>[ | ||||||
|                 EntityIcon( |                 buttonIcon, | ||||||
|                   padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0), |  | ||||||
|                   size: widthBase / (card.depth * 0.5), |  | ||||||
|                 ), |  | ||||||
|                 _buildName() |                 _buildName() | ||||||
|               ], |               ], | ||||||
|  |             ) | ||||||
|           ), |           ), | ||||||
|         ), |         ), | ||||||
|         handleTap: true |         handleTap: true | ||||||
|         ), |  | ||||||
|       ) |       ) | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -59,10 +59,9 @@ class GlanceCard extends StatelessWidget { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   Widget _buildEntityContainer(BuildContext context, EntityWrapper entityWrapper) { |   Widget _buildEntityContainer(BuildContext context, EntityWrapper entityWrapper) { | ||||||
|     if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { |     if (entityWrapper.entity.statelessType == StatelessEntityType.missed) { | ||||||
|       return MissedEntityWidget(); |       return MissedEntityWidget(); | ||||||
|     } |     } else if (entityWrapper.entity.statelessType != StatelessEntityType.none) { | ||||||
|     if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) { |  | ||||||
|       return Container(width: 0.0, height: 0.0,); |       return Container(width: 0.0, height: 0.0,); | ||||||
|     } |     } | ||||||
|     List<Widget> result = []; |     List<Widget> result = []; | ||||||
|   | |||||||
| @@ -11,13 +11,13 @@ class DefaultEntityContainer extends StatelessWidget { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final EntityModel entityModel = EntityModel.of(context); |     final EntityModel entityModel = EntityModel.of(context); | ||||||
|     if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { |     if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.missed) { | ||||||
|       return MissedEntityWidget(); |       return MissedEntityWidget(); | ||||||
|     } |     } | ||||||
|     if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.DIVIDER) { |     if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.divider) { | ||||||
|       return Divider(); |       return Divider(); | ||||||
|     } |     } | ||||||
|     if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.SECTION) { |     if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.section) { | ||||||
|       return Column( |       return Column( | ||||||
|         crossAxisAlignment: CrossAxisAlignment.start, |         crossAxisAlignment: CrossAxisAlignment.start, | ||||||
|         mainAxisSize: MainAxisSize.min, |         mainAxisSize: MainAxisSize.min, | ||||||
|   | |||||||
| @@ -1,13 +1,6 @@ | |||||||
| part of '../main.dart'; | part of '../main.dart'; | ||||||
|  |  | ||||||
| class StatelessEntityType { | enum StatelessEntityType {none, missed, ghost, divider, section, callService, webLink} | ||||||
|   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; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| class Entity { | class Entity { | ||||||
|  |  | ||||||
| @@ -77,7 +70,7 @@ class Entity { | |||||||
|   String state; |   String state; | ||||||
|   String displayState; |   String displayState; | ||||||
|   DateTime lastUpdatedTimestamp; |   DateTime lastUpdatedTimestamp; | ||||||
|   int statelessType = 0; |   StatelessEntityType statelessType = StatelessEntityType.none; | ||||||
|  |  | ||||||
|   List<Entity> childEntities = []; |   List<Entity> childEntities = []; | ||||||
|   String deviceClass; |   String deviceClass; | ||||||
| @@ -120,30 +113,35 @@ class Entity { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   Entity.missed(String entityId) { |   Entity.missed(String entityId) { | ||||||
|     statelessType = StatelessEntityType.MISSED; |     statelessType = StatelessEntityType.missed; | ||||||
|     attributes = {"hidden": false}; |     attributes = {"hidden": false}; | ||||||
|     this.entityId = entityId; |     this.entityId = entityId; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Entity.divider() { |   Entity.divider() { | ||||||
|     statelessType = StatelessEntityType.DIVIDER; |     statelessType = StatelessEntityType.divider; | ||||||
|     attributes = {"hidden": false}; |     attributes = {"hidden": false}; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Entity.section(String label) { |   Entity.section(String label) { | ||||||
|     statelessType = StatelessEntityType.SECTION; |     statelessType = StatelessEntityType.section; | ||||||
|     attributes = {"hidden": false, "friendly_name": "$label"}; |     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}) { |   Entity.callService({String icon, String name, String service, String actionName}) { | ||||||
|     statelessType = StatelessEntityType.CALL_SERVICE; |     statelessType = StatelessEntityType.callService; | ||||||
|     entityId = service; |     entityId = service; | ||||||
|     displayState = actionName?.toUpperCase() ?? "RUN"; |     displayState = actionName?.toUpperCase() ?? "RUN"; | ||||||
|     attributes = {"hidden": false, "friendly_name": "$name", "icon": "$icon"}; |     attributes = {"hidden": false, "friendly_name": "$name", "icon": "$icon"}; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Entity.weblink({String url, String name, String icon}) { |   Entity.weblink({String url, String name, String icon}) { | ||||||
|     statelessType = StatelessEntityType.WEBLINK; |     statelessType = StatelessEntityType.webLink; | ||||||
|     entityId = "custom.custom"; |     entityId = "custom.custom"; | ||||||
|     attributes = {"hidden": false, "friendly_name": "${name ?? url}", "icon": "${icon ?? 'mdi:link'}"}; |     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; |     final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; | ||||||
|     TextStyle tStyle; |     TextStyle tStyle; | ||||||
|     if (textStyle == null) { |     if (textStyle == null) { | ||||||
|       if (entityWrapper.entity.statelessType == StatelessEntityType.WEBLINK) { |       if (entityWrapper.entity.statelessType == StatelessEntityType.webLink) { | ||||||
|         tStyle = HAClientTheme().getLinkTextStyle(context); |         tStyle = HAClientTheme().getLinkTextStyle(context); | ||||||
|       } else { |       } else { | ||||||
|         tStyle = Theme.of(context).textTheme.body1; |         tStyle = Theme.of(context).textTheme.body1; | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ class EntityWrapper { | |||||||
|     this.uiAction, |     this.uiAction, | ||||||
|     this.stateFilter |     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) { |       if (uiAction == null) { | ||||||
|         uiAction = EntityUIAction(); |         uiAction = EntityUIAction(); | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ class SimpleEntityState extends StatelessWidget { | |||||||
|     TextStyle tStyle; |     TextStyle tStyle; | ||||||
|     if (textStyle != null) { |     if (textStyle != null) { | ||||||
|       tStyle = textStyle; |       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( |       tStyle = Theme.of(context).textTheme.subhead.copyWith( | ||||||
|         color: Colors.blue |         color: Colors.blue | ||||||
|       ); |       ); | ||||||
|   | |||||||
| @@ -14,7 +14,6 @@ class BottomInfoBarController { | |||||||
|   List<HAErrorAction> actions = []; |   List<HAErrorAction> actions = []; | ||||||
|  |  | ||||||
|   void hideBottomBar() { |   void hideBottomBar() { | ||||||
|     //_scaffoldKey?.currentState?.hideCurrentSnackBar(); |  | ||||||
|     _bottomBarTimer?.cancel(); |     _bottomBarTimer?.cancel(); | ||||||
|     if (hide == null) { |     if (hide == null) { | ||||||
|       initialState = false; |       initialState = false; | ||||||
| @@ -32,7 +31,6 @@ class BottomInfoBarController { | |||||||
|     if (show == null) { |     if (show == null) { | ||||||
|       initialState = true; |       initialState = true; | ||||||
|     } else { |     } else { | ||||||
|       Logger.d("Calling  show() - ${bottomBarProgress}"); |  | ||||||
|       show(); |       show(); | ||||||
|     } |     } | ||||||
|     if (duration != null) { |     if (duration != null) { | ||||||
| @@ -78,7 +76,6 @@ class _BottomInfoBarState extends State<BottomInfoBar> { | |||||||
|   void initState() { |   void initState() { | ||||||
|     _show = widget.controller.initialState; |     _show = widget.controller.initialState; | ||||||
|     widget.controller.show = () { |     widget.controller.show = () { | ||||||
|       Logger.d('Set state in show() - ${widget.controller.bottomBarProgress}'); |  | ||||||
|       setState(() { |       setState(() { | ||||||
|         _show = true; |         _show = true; | ||||||
|       }); |       }); | ||||||
|   | |||||||
| @@ -66,7 +66,9 @@ class HAView { | |||||||
|           card.childCards = _createLovelaceCards(rawCardInfo["cards"], depth + 1); |           card.childCards = _createLovelaceCards(rawCardInfo["cards"], depth + 1); | ||||||
|         } |         } | ||||||
|         var rawEntities = rawCard["entities"] ?? rawCardInfo["entities"]; |         var rawEntities = rawCard["entities"] ?? rawCardInfo["entities"]; | ||||||
|         rawEntities?.forEach((rawEntity) { |         var rawSingleEntity = rawCard["entity"] ?? rawCardInfo["entity"]; | ||||||
|  |         if (rawEntities != null) { | ||||||
|  |           rawEntities.forEach((rawEntity) { | ||||||
|             if (rawEntity is String) { |             if (rawEntity is String) { | ||||||
|               if (HomeAssistant().entities.isExist(rawEntity)) { |               if (HomeAssistant().entities.isExist(rawEntity)) { | ||||||
|                 card.entities.add(EntityWrapper(entity: HomeAssistant().entities.get(rawEntity))); |                 card.entities.add(EntityWrapper(entity: HomeAssistant().entities.get(rawEntity))); | ||||||
| @@ -130,8 +132,7 @@ class HAView { | |||||||
|               } |               } | ||||||
|             } |             } | ||||||
|           }); |           }); | ||||||
|         var rawSingleEntity = rawCard["entity"] ?? rawCardInfo["entity"]; |         } else if (rawSingleEntity != null) { | ||||||
|         if (rawSingleEntity != null) { |  | ||||||
|           var en = rawSingleEntity; |           var en = rawSingleEntity; | ||||||
|           if (en is String) { |           if (en is String) { | ||||||
|             if (HomeAssistant().entities.isExist(en)) { |             if (HomeAssistant().entities.isExist(en)) { | ||||||
| @@ -159,6 +160,16 @@ class HAView { | |||||||
|               card.linkedEntityWrapper = EntityWrapper(entity: Entity.missed(en["entity"])); |               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); |         result.add(card); | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user