Resolves #369 Get actual entity data in entity wrapper
This commit is contained in:
		| @@ -306,7 +306,7 @@ class CardWidget extends StatelessWidget { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   Widget _buildEntityButtonCard(BuildContext context) { |   Widget _buildEntityButtonCard(BuildContext context) { | ||||||
|     card.linkedEntityWrapper.displayName = card.name?.toUpperCase() ?? |     card.linkedEntityWrapper.overrideName = card.name?.toUpperCase() ?? | ||||||
|         card.linkedEntityWrapper.displayName.toUpperCase(); |         card.linkedEntityWrapper.displayName.toUpperCase(); | ||||||
|     return Card( |     return Card( | ||||||
|         child: EntityModel( |         child: EntityModel( | ||||||
| @@ -320,9 +320,9 @@ class CardWidget extends StatelessWidget { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   Widget _buildGaugeCard(BuildContext context) { |   Widget _buildGaugeCard(BuildContext context) { | ||||||
|     card.linkedEntityWrapper.displayName = card.name ?? |     card.linkedEntityWrapper.overrideName = card.name ?? | ||||||
|         card.linkedEntityWrapper.displayName; |         card.linkedEntityWrapper.displayName; | ||||||
|     card.linkedEntityWrapper.unitOfMeasurement = card.unit ?? |     card.linkedEntityWrapper.unitOfMeasurementOverride = card.unit ?? | ||||||
|         card.linkedEntityWrapper.unitOfMeasurement; |         card.linkedEntityWrapper.unitOfMeasurement; | ||||||
|     return Card( |     return Card( | ||||||
|         child: EntityModel( |         child: EntityModel( | ||||||
| @@ -338,7 +338,7 @@ class CardWidget extends StatelessWidget { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   Widget _buildLightCard(BuildContext context) { |   Widget _buildLightCard(BuildContext context) { | ||||||
|     card.linkedEntityWrapper.displayName = card.name ?? |     card.linkedEntityWrapper.overrideName = card.name ?? | ||||||
|         card.linkedEntityWrapper.displayName; |         card.linkedEntityWrapper.displayName; | ||||||
|     return Card( |     return Card( | ||||||
|         child: EntityModel( |         child: EntityModel( | ||||||
|   | |||||||
| @@ -2,32 +2,29 @@ part of '../main.dart'; | |||||||
|  |  | ||||||
| class EntityWrapper { | class EntityWrapper { | ||||||
|  |  | ||||||
|   String displayName; |   String overrideName; | ||||||
|   String icon; |   final String overrideIcon; | ||||||
|   String unitOfMeasurement; |  | ||||||
|   String entityPicture; |  | ||||||
|   EntityUIAction uiAction; |   EntityUIAction uiAction; | ||||||
|   Entity entity; |   Entity entity; | ||||||
|   List stateFilter; |   String unitOfMeasurementOverride; | ||||||
|  |   final List stateFilter; | ||||||
|  |  | ||||||
|  |   String get icon => overrideIcon ?? entity.icon; | ||||||
|  |   String get entityPicture => entity.entityPicture; | ||||||
|  |   String get displayName => overrideName ?? entity.displayName; | ||||||
|  |   String get unitOfMeasurement => unitOfMeasurementOverride ?? entity.unitOfMeasurement; | ||||||
|  |  | ||||||
|   EntityWrapper({ |   EntityWrapper({ | ||||||
|     this.entity, |     this.entity, | ||||||
|     String icon, |     this.overrideIcon, | ||||||
|     String displayName, |     this.overrideName, | ||||||
|     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.NONE || entity.statelessType == StatelessEntityType.CALL_SERVICE || entity.statelessType == StatelessEntityType.WEBLINK) { | ||||||
|       this.icon = icon ?? entity.icon; |  | ||||||
|       if (icon == null) { |  | ||||||
|         entityPicture = entity.entityPicture; |  | ||||||
|       } |  | ||||||
|       this.displayName = displayName ?? entity.displayName; |  | ||||||
|       if (uiAction == null) { |       if (uiAction == null) { | ||||||
|         uiAction = EntityUIAction(); |         uiAction = EntityUIAction(); | ||||||
|       } |       } | ||||||
|       unitOfMeasurement = entity.unitOfMeasurement; |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -402,8 +402,8 @@ class HomeAssistant { | |||||||
|               card.entities.add( |               card.entities.add( | ||||||
|                   EntityWrapper( |                   EntityWrapper( | ||||||
|                       entity: e, |                       entity: e, | ||||||
|                       displayName: rawEntity["name"], |                       overrideName: rawEntity["name"], | ||||||
|                       icon: rawEntity["icon"], |                       overrideIcon: rawEntity["icon"], | ||||||
|                       stateFilter: rawEntity['state_filter'] ?? [], |                       stateFilter: rawEntity['state_filter'] ?? [], | ||||||
|                       uiAction: EntityUIAction(rawEntityData: rawEntity) |                       uiAction: EntityUIAction(rawEntityData: rawEntity) | ||||||
|                   ) |                   ) | ||||||
| @@ -421,8 +421,8 @@ class HomeAssistant { | |||||||
|               Entity e = entities.get(en); |               Entity e = entities.get(en); | ||||||
|               card.linkedEntityWrapper = EntityWrapper( |               card.linkedEntityWrapper = EntityWrapper( | ||||||
|                   entity: e, |                   entity: e, | ||||||
|                   icon: rawCardInfo["icon"], |                   overrideIcon: rawCardInfo["icon"], | ||||||
|                   displayName: rawCardInfo["name"], |                   overrideName: rawCardInfo["name"], | ||||||
|                   uiAction: EntityUIAction(rawEntityData: rawCard) |                   uiAction: EntityUIAction(rawEntityData: rawCard) | ||||||
|               ); |               ); | ||||||
|             } else { |             } else { | ||||||
| @@ -433,8 +433,8 @@ class HomeAssistant { | |||||||
|               Entity e = entities.get(en["entity"]); |               Entity e = entities.get(en["entity"]); | ||||||
|               card.linkedEntityWrapper = EntityWrapper( |               card.linkedEntityWrapper = EntityWrapper( | ||||||
|                   entity: e, |                   entity: e, | ||||||
|                   icon: en["icon"], |                   overrideIcon: en["icon"], | ||||||
|                   displayName: en["name"], |                   overrideName: en["name"], | ||||||
|                   stateFilter: en['state_filter'] ?? [], |                   stateFilter: en['state_filter'] ?? [], | ||||||
|                   uiAction: EntityUIAction(rawEntityData: rawCard) |                   uiAction: EntityUIAction(rawEntityData: rawCard) | ||||||
|               ); |               ); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user