Resolves #254 Missed entities
This commit is contained in:
		| @@ -67,6 +67,7 @@ class Entity { | |||||||
|   String state; |   String state; | ||||||
|   String displayState; |   String displayState; | ||||||
|   DateTime _lastUpdated; |   DateTime _lastUpdated; | ||||||
|  |   bool missed = false; | ||||||
|  |  | ||||||
|   List<Entity> childEntities = []; |   List<Entity> childEntities = []; | ||||||
|   List<String> attributesToShow = ["all"]; |   List<String> attributesToShow = ["all"]; | ||||||
| @@ -97,6 +98,12 @@ class Entity { | |||||||
|     update(rawData); |     update(rawData); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   Entity.missed(String entityId) { | ||||||
|  |     missed = true; | ||||||
|  |     attributes = {"hidden": false}; | ||||||
|  |     this.entityId = entityId; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   void update(Map rawData) { |   void update(Map rawData) { | ||||||
|     attributes = rawData["attributes"] ?? {}; |     attributes = rawData["attributes"] ?? {}; | ||||||
|     domain = rawData["entity_id"].split(".")[0]; |     domain = rawData["entity_id"].split(".")[0]; | ||||||
|   | |||||||
| @@ -14,10 +14,12 @@ class EntityWrapper { | |||||||
|     String displayName, |     String displayName, | ||||||
|     this.uiAction |     this.uiAction | ||||||
|   }) { |   }) { | ||||||
|  |     if (!entity.missed) { | ||||||
|       this.icon = icon ?? entity.icon; |       this.icon = icon ?? entity.icon; | ||||||
|       this.displayName = displayName ?? entity.displayName; |       this.displayName = displayName ?? entity.displayName; | ||||||
|     if (this.uiAction == null) { |       if (uiAction == null) { | ||||||
|       this.uiAction = EntityUIAction(); |         uiAction = EntityUIAction(); | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -9,7 +9,9 @@ class ButtonEntityContainer extends StatelessWidget { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; |     final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; | ||||||
|  |     if (entityWrapper.entity.missed) { | ||||||
|  |       return MissedEntityWidget(); | ||||||
|  |     } else { | ||||||
|       return InkWell( |       return InkWell( | ||||||
|         onTap: () => entityWrapper.handleTap(), |         onTap: () => entityWrapper.handleTap(), | ||||||
|         onLongPress: () => entityWrapper.handleHold(), |         onLongPress: () => entityWrapper.handleHold(), | ||||||
| @@ -31,6 +33,7 @@ class ButtonEntityContainer extends StatelessWidget { | |||||||
|         ), |         ), | ||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   Widget _buildName() { |   Widget _buildName() { | ||||||
|     return EntityName( |     return EntityName( | ||||||
|   | |||||||
| @@ -11,6 +11,9 @@ 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.missed) { | ||||||
|  |       return MissedEntityWidget(); | ||||||
|  |     } else { | ||||||
|       return InkWell( |       return InkWell( | ||||||
|         onLongPress: () { |         onLongPress: () { | ||||||
|           if (entityModel.handleTap) { |           if (entityModel.handleTap) { | ||||||
| @@ -40,3 +43,4 @@ class DefaultEntityContainer extends StatelessWidget { | |||||||
|       ); |       ); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | } | ||||||
| @@ -22,6 +22,9 @@ class GlanceEntityContainer extends StatelessWidget { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; |     final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; | ||||||
|  |     if (entityWrapper.entity.missed) { | ||||||
|  |       return MissedEntityWidget(); | ||||||
|  |     } | ||||||
|     List<Widget> result = []; |     List<Widget> result = []; | ||||||
|     if (!nameInTheBottom) { |     if (!nameInTheBottom) { | ||||||
|       if (showName) { |       if (showName) { | ||||||
|   | |||||||
							
								
								
									
										19
									
								
								lib/entity_widgets/missed_entity.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								lib/entity_widgets/missed_entity.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | |||||||
|  | part of '../main.dart'; | ||||||
|  |  | ||||||
|  | class MissedEntityWidget extends StatelessWidget { | ||||||
|  |   MissedEntityWidget({ | ||||||
|  |     Key key | ||||||
|  |   }) : super(key: key); | ||||||
|  |  | ||||||
|  |   @override | ||||||
|  |   Widget build(BuildContext context) { | ||||||
|  |     final EntityModel entityModel = EntityModel.of(context); | ||||||
|  |     return Container( | ||||||
|  |         child: Padding( | ||||||
|  |           padding: EdgeInsets.all(5.0), | ||||||
|  |           child: Text("Entity not available: ${entityModel.entityWrapper.entity.entityId}"), | ||||||
|  |         ), | ||||||
|  |         color: Colors.amber[100], | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -401,6 +401,8 @@ class HomeAssistant { | |||||||
|           if (rawEntity is String) { |           if (rawEntity is String) { | ||||||
|             if (entities.isExist(rawEntity)) { |             if (entities.isExist(rawEntity)) { | ||||||
|               card.entities.add(EntityWrapper(entity: entities.get(rawEntity))); |               card.entities.add(EntityWrapper(entity: entities.get(rawEntity))); | ||||||
|  |             } else { | ||||||
|  |               card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity))); | ||||||
|             } |             } | ||||||
|           } else { |           } else { | ||||||
|             if (entities.isExist(rawEntity["entity"])) { |             if (entities.isExist(rawEntity["entity"])) { | ||||||
| @@ -413,6 +415,8 @@ class HomeAssistant { | |||||||
|                       uiAction: EntityUIAction(rawEntityData: rawEntity) |                       uiAction: EntityUIAction(rawEntityData: rawEntity) | ||||||
|                   ) |                   ) | ||||||
|               ); |               ); | ||||||
|  |             } else { | ||||||
|  |               card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity["entity"]))); | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|         }); |         }); | ||||||
| @@ -427,6 +431,8 @@ class HomeAssistant { | |||||||
|                   displayName: rawCard["name"], |                   displayName: rawCard["name"], | ||||||
|                   uiAction: EntityUIAction(rawEntityData: rawCard) |                   uiAction: EntityUIAction(rawEntityData: rawCard) | ||||||
|               ); |               ); | ||||||
|  |             } else { | ||||||
|  |               card.linkedEntityWrapper = EntityWrapper(entity: Entity.missed(en)); | ||||||
|             } |             } | ||||||
|           } else { |           } else { | ||||||
|             if (entities.isExist(en["entity"])) { |             if (entities.isExist(en["entity"])) { | ||||||
| @@ -437,6 +443,8 @@ class HomeAssistant { | |||||||
|                   displayName: en["name"], |                   displayName: en["name"], | ||||||
|                   uiAction: EntityUIAction(rawEntityData: rawCard) |                   uiAction: EntityUIAction(rawEntityData: rawCard) | ||||||
|               ); |               ); | ||||||
|  |             } else { | ||||||
|  |               card.linkedEntityWrapper = EntityWrapper(entity: Entity.missed(en["entity"])); | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -40,6 +40,7 @@ part 'entity_class/alarm_control_panel.class.dart'; | |||||||
| part 'entity_widgets/common/badge.dart'; | part 'entity_widgets/common/badge.dart'; | ||||||
| part 'entity_widgets/model_widgets.dart'; | part 'entity_widgets/model_widgets.dart'; | ||||||
| part 'entity_widgets/default_entity_container.dart'; | part 'entity_widgets/default_entity_container.dart'; | ||||||
|  | part 'entity_widgets/missed_entity.dart'; | ||||||
| part 'entity_widgets/glance_entity_container.dart'; | part 'entity_widgets/glance_entity_container.dart'; | ||||||
| part 'entity_widgets/button_entity_container.dart'; | part 'entity_widgets/button_entity_container.dart'; | ||||||
| part 'entity_widgets/common/entity_attributes_list.dart'; | part 'entity_widgets/common/entity_attributes_list.dart'; | ||||||
|   | |||||||
| @@ -11,9 +11,18 @@ class CardWidget extends StatelessWidget { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     if ((card.linkedEntityWrapper!= null) && (card.linkedEntityWrapper.entity.isHidden)) { |     if (card.linkedEntityWrapper!= null) { | ||||||
|  |       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.missed) { | ||||||
|  |         return EntityModel( | ||||||
|  |           entityWrapper: card.linkedEntityWrapper, | ||||||
|  |           child: MissedEntityWidget(), | ||||||
|  |           handleTap: false, | ||||||
|  |         ); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     switch (card.type) { |     switch (card.type) { | ||||||
|  |  | ||||||
| @@ -133,9 +142,6 @@ class CardWidget extends StatelessWidget { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   Widget _buildAlarmPanelCard(BuildContext context) { |   Widget _buildAlarmPanelCard(BuildContext context) { | ||||||
|     if (card.linkedEntityWrapper == null || card.linkedEntityWrapper.entity == null) { |  | ||||||
|       return Container(width: 0, height: 0,); |  | ||||||
|     } else { |  | ||||||
|     List<Widget> body = []; |     List<Widget> body = []; | ||||||
|     body.add(CardHeaderWidget( |     body.add(CardHeaderWidget( | ||||||
|       name: card.name ?? "", |       name: card.name ?? "", | ||||||
| @@ -182,7 +188,6 @@ class CardWidget extends StatelessWidget { | |||||||
|         ) |         ) | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|   } |  | ||||||
|  |  | ||||||
|   Widget _buildGlanceCard(BuildContext context) { |   Widget _buildGlanceCard(BuildContext context) { | ||||||
|     List<EntityWrapper> entitiesToShow = card.getEntitiesToShow(); |     List<EntityWrapper> entitiesToShow = card.getEntitiesToShow(); | ||||||
| @@ -227,9 +232,6 @@ class CardWidget extends StatelessWidget { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   Widget _buildMediaControlsCard(BuildContext context) { |   Widget _buildMediaControlsCard(BuildContext context) { | ||||||
|     if (card.linkedEntityWrapper == null || card.linkedEntityWrapper.entity == null) { |  | ||||||
|       return Container(width: 0, height: 0,); |  | ||||||
|     } else { |  | ||||||
|     return Card( |     return Card( | ||||||
|         child: EntityModel( |         child: EntityModel( | ||||||
|             entityWrapper: card.linkedEntityWrapper, |             entityWrapper: card.linkedEntityWrapper, | ||||||
| @@ -238,12 +240,8 @@ class CardWidget extends StatelessWidget { | |||||||
|         ) |         ) | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|   } |  | ||||||
|  |  | ||||||
|   Widget _buildEntityButtonCard(BuildContext context) { |   Widget _buildEntityButtonCard(BuildContext context) { | ||||||
|     if (card.linkedEntityWrapper == null || card.linkedEntityWrapper.entity == null) { |  | ||||||
|       return Container(width: 0, height: 0,); |  | ||||||
|     } else { |  | ||||||
|     card.linkedEntityWrapper.displayName = card.name?.toUpperCase() ?? |     card.linkedEntityWrapper.displayName = card.name?.toUpperCase() ?? | ||||||
|         card.linkedEntityWrapper.displayName.toUpperCase(); |         card.linkedEntityWrapper.displayName.toUpperCase(); | ||||||
|     return Card( |     return Card( | ||||||
| @@ -254,7 +252,6 @@ class CardWidget extends StatelessWidget { | |||||||
|         ) |         ) | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|   } |  | ||||||
|  |  | ||||||
|   Widget _buildUnsupportedCard(BuildContext context) { |   Widget _buildUnsupportedCard(BuildContext context) { | ||||||
|     List<Widget> body = []; |     List<Widget> body = []; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user