WIP #183 Custom names and icons
This commit is contained in:
		| @@ -77,20 +77,15 @@ class Entity { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   Widget buildDefaultWidget(BuildContext context) { |   Widget buildDefaultWidget(BuildContext context) { | ||||||
|     return EntityModel( |     return DefaultEntityContainer( | ||||||
|       entity: this, |  | ||||||
|       child: DefaultEntityContainer( |  | ||||||
|         state: _buildStatePart(context) |         state: _buildStatePart(context) | ||||||
|       ), |  | ||||||
|       handleTap: true, |  | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   Widget buildGlanceWidget(BuildContext context) { |   Widget buildGlanceWidget(BuildContext context, bool showName, bool showState) { | ||||||
|     return EntityModel( |     return GlanceEntityContainer( | ||||||
|       entity: this, |       showName: showName, | ||||||
|       child: GlanceEntityContainer(), |       showState: showState, | ||||||
|       handleTap: true, |  | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -111,7 +106,7 @@ class Entity { | |||||||
|  |  | ||||||
|   Widget buildEntityPageWidget(BuildContext context) { |   Widget buildEntityPageWidget(BuildContext context) { | ||||||
|     return EntityModel( |     return EntityModel( | ||||||
|       entity: this, |       entity: EntityWrapper(entity: this), | ||||||
|       child: EntityPageContainer(children: <Widget>[ |       child: EntityPageContainer(children: <Widget>[ | ||||||
|         DefaultEntityContainer(state: _buildStatePartForPage(context)), |         DefaultEntityContainer(state: _buildStatePartForPage(context)), | ||||||
|         LastUpdatedWidget(), |         LastUpdatedWidget(), | ||||||
| @@ -133,7 +128,7 @@ class Entity { | |||||||
|  |  | ||||||
|   Widget buildBadgeWidget(BuildContext context) { |   Widget buildBadgeWidget(BuildContext context) { | ||||||
|     return EntityModel( |     return EntityModel( | ||||||
|       entity: this, |       entity: EntityWrapper(entity: this), | ||||||
|       child: BadgeWidget(), |       child: BadgeWidget(), | ||||||
|       handleTap: true, |       handleTap: true, | ||||||
|     ); |     ); | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								lib/entity_class/entity_wrapper.class.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								lib/entity_class/entity_wrapper.class.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | |||||||
|  | part of '../main.dart'; | ||||||
|  |  | ||||||
|  | class EntityWrapper { | ||||||
|  |  | ||||||
|  |   String displayName; | ||||||
|  |   String icon; | ||||||
|  |   Entity entity; | ||||||
|  |  | ||||||
|  |   EntityWrapper({this.entity, String icon, String displayName}) { | ||||||
|  |     this.icon = icon ?? entity.icon; | ||||||
|  |     this.displayName = displayName ?? entity.displayName; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -7,12 +7,12 @@ class BadgeWidget extends StatelessWidget { | |||||||
|     double iconSize = 26.0; |     double iconSize = 26.0; | ||||||
|     Widget badgeIcon; |     Widget badgeIcon; | ||||||
|     String onBadgeTextValue; |     String onBadgeTextValue; | ||||||
|     Color iconColor = EntityColor.badgeColors[entityModel.entity.domain] ?? |     Color iconColor = EntityColor.badgeColors[entityModel.entity.entity.domain] ?? | ||||||
|         EntityColor.badgeColors["default"]; |         EntityColor.badgeColors["default"]; | ||||||
|     switch (entityModel.entity.domain) { |     switch (entityModel.entity.entity.domain) { | ||||||
|       case "sun": |       case "sun": | ||||||
|         { |         { | ||||||
|           badgeIcon = entityModel.entity.state == "below_horizon" |           badgeIcon = entityModel.entity.entity.state == "below_horizon" | ||||||
|               ? Icon( |               ? Icon( | ||||||
|             MaterialDesignIcons.createIconDataFromIconCode(0xf0dc), |             MaterialDesignIcons.createIconDataFromIconCode(0xf0dc), | ||||||
|             size: iconSize, |             size: iconSize, | ||||||
| @@ -25,10 +25,10 @@ class BadgeWidget extends StatelessWidget { | |||||||
|         } |         } | ||||||
|       case "sensor": |       case "sensor": | ||||||
|         { |         { | ||||||
|           onBadgeTextValue = entityModel.entity.unitOfMeasurement; |           onBadgeTextValue = entityModel.entity.entity.unitOfMeasurement; | ||||||
|           badgeIcon = Center( |           badgeIcon = Center( | ||||||
|             child: Text( |             child: Text( | ||||||
|               "${entityModel.entity.state}", |               "${entityModel.entity.entity.state}", | ||||||
|               overflow: TextOverflow.fade, |               overflow: TextOverflow.fade, | ||||||
|               softWrap: false, |               softWrap: false, | ||||||
|               textAlign: TextAlign.center, |               textAlign: TextAlign.center, | ||||||
| @@ -41,7 +41,7 @@ class BadgeWidget extends StatelessWidget { | |||||||
|         { |         { | ||||||
|           badgeIcon = MaterialDesignIcons.createIconWidgetFromEntityData( |           badgeIcon = MaterialDesignIcons.createIconWidgetFromEntityData( | ||||||
|               entityModel.entity, iconSize, Colors.black); |               entityModel.entity, iconSize, Colors.black); | ||||||
|           onBadgeTextValue = entityModel.entity.state; |           onBadgeTextValue = entityModel.entity.entity.state; | ||||||
|           break; |           break; | ||||||
|         } |         } | ||||||
|       default: |       default: | ||||||
| @@ -120,6 +120,6 @@ class BadgeWidget extends StatelessWidget { | |||||||
|           ], |           ], | ||||||
|         ), |         ), | ||||||
|         onTap: () => |         onTap: () => | ||||||
|             eventBus.fire(new ShowEntityPageEvent(entityModel.entity))); |             eventBus.fire(new ShowEntityPageEvent(entityModel.entity.entity))); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @@ -165,7 +165,7 @@ class _ClimateControlWidgetState extends State<ClimateControlWidget> { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final ClimateEntity entity = entityModel.entity; |     final ClimateEntity entity = entityModel.entity.entity; | ||||||
|     if (_changedHere) { |     if (_changedHere) { | ||||||
|       _showPending = (_tmpTemperature != entity.temperature); |       _showPending = (_tmpTemperature != entity.temperature); | ||||||
|       _changedHere = false; |       _changedHere = false; | ||||||
|   | |||||||
| @@ -38,7 +38,7 @@ class _CoverControlWidgetState extends State<CoverControlWidget> { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final CoverEntity entity = entityModel.entity; |     final CoverEntity entity = entityModel.entity.entity; | ||||||
|     if (_changedHere) { |     if (_changedHere) { | ||||||
|       _changedHere = false; |       _changedHere = false; | ||||||
|     } else { |     } else { | ||||||
| @@ -152,7 +152,7 @@ class CoverTiltControlsWidget extends StatelessWidget { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final CoverEntity entity = entityModel.entity; |     final CoverEntity entity = entityModel.entity.entity; | ||||||
|     List<Widget> buttons = []; |     List<Widget> buttons = []; | ||||||
|     if (entity.supportOpenTilt) { |     if (entity.supportOpenTilt) { | ||||||
|       buttons.add(IconButton( |       buttons.add(IconButton( | ||||||
|   | |||||||
| @@ -80,7 +80,7 @@ class _LightControlsWidgetState extends State<LightControlsWidget> { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final LightEntity entity = entityModel.entity; |     final LightEntity entity = entityModel.entity.entity; | ||||||
|     if (!_changedHere) { |     if (!_changedHere) { | ||||||
|       _resetState(entity); |       _resetState(entity); | ||||||
|     } else { |     } else { | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ class MediaPlayerWidget extends StatelessWidget { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final EntityModel entityModel = EntityModel.of(context); |     final EntityModel entityModel = EntityModel.of(context); | ||||||
|     final MediaPlayerEntity entity = entityModel.entity; |     final MediaPlayerEntity entity = entityModel.entity.entity; | ||||||
|     return Column( |     return Column( | ||||||
|       children: <Widget>[ |       children: <Widget>[ | ||||||
|         Stack( |         Stack( | ||||||
| @@ -229,7 +229,7 @@ class _MediaPlayerProgressWidgetState extends State<MediaPlayerProgressWidget> { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final EntityModel entityModel = EntityModel.of(context); |     final EntityModel entityModel = EntityModel.of(context); | ||||||
|     final MediaPlayerEntity entity = entityModel.entity; |     final MediaPlayerEntity entity = entityModel.entity.entity; | ||||||
|     double progress; |     double progress; | ||||||
|     try { |     try { | ||||||
|       DateTime lastUpdated = DateTime.parse( |       DateTime lastUpdated = DateTime.parse( | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ class _SliderControlsWidgetState extends State<SliderControlsWidget> { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final SliderEntity entity = entityModel.entity; |     final SliderEntity entity = entityModel.entity.entity; | ||||||
|     if (entity.valueStep < 1) { |     if (entity.valueStep < 1) { | ||||||
|       _multiplier = 10; |       _multiplier = 10; | ||||||
|     } else if (entity.valueStep < 0.1) { |     } else if (entity.valueStep < 0.1) { | ||||||
|   | |||||||
| @@ -7,14 +7,14 @@ class EntityAttributesList extends StatelessWidget { | |||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     List<Widget> attrs = []; |     List<Widget> attrs = []; | ||||||
|     if ((entityModel.entity.attributesToShow == null) || |     if ((entityModel.entity.entity.attributesToShow == null) || | ||||||
|         (entityModel.entity.attributesToShow.contains("all"))) { |         (entityModel.entity.entity.attributesToShow.contains("all"))) { | ||||||
|       entityModel.entity.attributes.forEach((name, value) { |       entityModel.entity.entity.attributes.forEach((name, value) { | ||||||
|         attrs.add(_buildSingleAttribute("$name", "$value")); |         attrs.add(_buildSingleAttribute("$name", "$value")); | ||||||
|       }); |       }); | ||||||
|     } else { |     } else { | ||||||
|       entityModel.entity.attributesToShow.forEach((String attr) { |       entityModel.entity.entity.attributesToShow.forEach((String attr) { | ||||||
|         String attrValue = entityModel.entity.getAttribute("$attr"); |         String attrValue = entityModel.entity.entity.getAttribute("$attr"); | ||||||
|         if (attrValue != null) { |         if (attrValue != null) { | ||||||
|           attrs.add( |           attrs.add( | ||||||
|               _buildSingleAttribute("$attr", "$attrValue")); |               _buildSingleAttribute("$attr", "$attrValue")); | ||||||
|   | |||||||
| @@ -17,11 +17,11 @@ class EntityIcon extends StatelessWidget { | |||||||
|         child: MaterialDesignIcons.createIconWidgetFromEntityData( |         child: MaterialDesignIcons.createIconWidgetFromEntityData( | ||||||
|             entityModel.entity, |             entityModel.entity, | ||||||
|             iconSize, |             iconSize, | ||||||
|             EntityColor.stateColor(entityModel.entity.state) |             EntityColor.stateColor(entityModel.entity.entity.state) | ||||||
|         ), |         ), | ||||||
|       ), |       ), | ||||||
|       onTap: () => entityModel.handleTap |       onTap: () => entityModel.handleTap | ||||||
|           ? eventBus.fire(new ShowEntityPageEvent(entityModel.entity)) |           ? eventBus.fire(new ShowEntityPageEvent(entityModel.entity.entity)) | ||||||
|           : null, |           : null, | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ class EntityName extends StatelessWidget { | |||||||
|       ), |       ), | ||||||
|       onTap: () => |       onTap: () => | ||||||
|       entityModel.handleTap |       entityModel.handleTap | ||||||
|           ? eventBus.fire(new ShowEntityPageEvent(entityModel.entity)) |           ? eventBus.fire(new ShowEntityPageEvent(entityModel.entity.entity)) | ||||||
|           : null, |           : null, | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -1,34 +1,42 @@ | |||||||
| part of '../main.dart'; | part of '../main.dart'; | ||||||
|  |  | ||||||
| class GlanceEntityContainer extends StatelessWidget { | class GlanceEntityContainer extends StatelessWidget { | ||||||
|  |  | ||||||
|  |   final bool showName; | ||||||
|  |   final bool showState; | ||||||
|  |  | ||||||
|   GlanceEntityContainer({ |   GlanceEntityContainer({ | ||||||
|     Key key, |     Key key, @required this.showName, @required this.showState, | ||||||
|   }) : super(key: key); |   }) : super(key: key); | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     return Column( |     List<Widget> result = []; | ||||||
|       mainAxisSize: MainAxisSize.min, |     if (showName) { | ||||||
|       mainAxisAlignment: MainAxisAlignment.start, |       result.add(EntityName( | ||||||
|       crossAxisAlignment: CrossAxisAlignment.center, |  | ||||||
|       children: <Widget>[ |  | ||||||
|         EntityName( |  | ||||||
|         padding: EdgeInsets.only(bottom: Sizes.rowPadding), |         padding: EdgeInsets.only(bottom: Sizes.rowPadding), | ||||||
|         textOverflow: TextOverflow.ellipsis, |         textOverflow: TextOverflow.ellipsis, | ||||||
|         wordsWrap: false, |         wordsWrap: false, | ||||||
|         textAlign: TextAlign.center, |         textAlign: TextAlign.center, | ||||||
|         fontSize: Sizes.smallFontSize, |         fontSize: Sizes.smallFontSize, | ||||||
|         ), |       )); | ||||||
|         EntityIcon( |     } | ||||||
|  |     result.add(EntityIcon( | ||||||
|       padding: EdgeInsets.all(0.0), |       padding: EdgeInsets.all(0.0), | ||||||
|       iconSize: Sizes.largeIconSize, |       iconSize: Sizes.largeIconSize, | ||||||
|         ), |     )); | ||||||
|         SimpleEntityState( |     if (showState) { | ||||||
|  |       result.add(SimpleEntityState( | ||||||
|         textAlign: TextAlign.center, |         textAlign: TextAlign.center, | ||||||
|         expanded: false, |         expanded: false, | ||||||
|         padding: EdgeInsets.only(top: Sizes.rowPadding), |         padding: EdgeInsets.only(top: Sizes.rowPadding), | ||||||
|         ) |       )); | ||||||
|       ], |     } | ||||||
|  |     return Column( | ||||||
|  |       mainAxisSize: MainAxisSize.min, | ||||||
|  |       mainAxisAlignment: MainAxisAlignment.start, | ||||||
|  |       crossAxisAlignment: CrossAxisAlignment.center, | ||||||
|  |       children: result, | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @@ -65,7 +65,7 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> { | |||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final HomeAssistantModel homeAssistantModel = HomeAssistantModel.of(context); |     final HomeAssistantModel homeAssistantModel = HomeAssistantModel.of(context); | ||||||
|     final EntityModel entityModel = EntityModel.of(context); |     final EntityModel entityModel = EntityModel.of(context); | ||||||
|     final Entity entity = entityModel.entity; |     final Entity entity = entityModel.entity.entity; | ||||||
|     if (!_needToUpdateHistory) { |     if (!_needToUpdateHistory) { | ||||||
|       _needToUpdateHistory = true; |       _needToUpdateHistory = true; | ||||||
|     } else { |     } else { | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ class LastUpdatedWidget extends StatelessWidget { | |||||||
|       padding: EdgeInsets.fromLTRB( |       padding: EdgeInsets.fromLTRB( | ||||||
|           Sizes.leftWidgetPadding, 0.0, 0.0, 0.0), |           Sizes.leftWidgetPadding, 0.0, 0.0, 0.0), | ||||||
|       child: Text( |       child: Text( | ||||||
|         '${entityModel.entity.lastUpdated}', |         '${entityModel.entity.entity.lastUpdated}', | ||||||
|         textAlign: TextAlign.left, |         textAlign: TextAlign.left, | ||||||
|         style: TextStyle( |         style: TextStyle( | ||||||
|             fontSize: Sizes.smallFontSize, color: Colors.black26), |             fontSize: Sizes.smallFontSize, color: Colors.black26), | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ class EntityModel extends InheritedWidget { | |||||||
|     @required Widget child, |     @required Widget child, | ||||||
|   }) : super(key: key, child: child); |   }) : super(key: key, child: child); | ||||||
|  |  | ||||||
|   final Entity entity; |   final EntityWrapper entity; | ||||||
|   final bool handleTap; |   final bool handleTap; | ||||||
|  |  | ||||||
|   static EntityModel of(BuildContext context) { |   static EntityModel of(BuildContext context) { | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ class ButtonStateWidget extends StatelessWidget { | |||||||
|       height: 34.0, |       height: 34.0, | ||||||
|       child: FlatButton( |       child: FlatButton( | ||||||
|         onPressed: (() { |         onPressed: (() { | ||||||
|           _setNewState(entityModel.entity); |           _setNewState(entityModel.entity.entity); | ||||||
|         }), |         }), | ||||||
|         child: Text( |         child: Text( | ||||||
|           "EXECUTE", |           "EXECUTE", | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ class ClimateStateWidget extends StatelessWidget { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final ClimateEntity entity = entityModel.entity; |     final ClimateEntity entity = entityModel.entity.entity; | ||||||
|     String targetTemp = "-"; |     String targetTemp = "-"; | ||||||
|     if ((entity.supportTargetTemperature) && (entity.temperature != null)) { |     if ((entity.supportTargetTemperature) && (entity.temperature != null)) { | ||||||
|       targetTemp = "${entity.temperature}"; |       targetTemp = "${entity.temperature}"; | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ class CoverStateWidget extends StatelessWidget { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final CoverEntity entity = entityModel.entity; |     final CoverEntity entity = entityModel.entity.entity; | ||||||
|     List<Widget> buttons = []; |     List<Widget> buttons = []; | ||||||
|     if (entity.supportOpen) { |     if (entity.supportOpen) { | ||||||
|       buttons.add(IconButton( |       buttons.add(IconButton( | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ class DateTimeStateWidget extends StatelessWidget { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final DateTimeEntity entity = entityModel.entity; |     final DateTimeEntity entity = entityModel.entity.entity; | ||||||
|     return Padding( |     return Padding( | ||||||
|         padding: EdgeInsets.fromLTRB(0.0, 0.0, Sizes.rightWidgetPadding, 0.0), |         padding: EdgeInsets.fromLTRB(0.0, 0.0, Sizes.rightWidgetPadding, 0.0), | ||||||
|         child: GestureDetector( |         child: GestureDetector( | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ class _SelectStateWidgetState extends State<SelectStateWidget> { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final SelectEntity entity = entityModel.entity; |     final SelectEntity entity = entityModel.entity.entity; | ||||||
|     Widget ctrl; |     Widget ctrl; | ||||||
|     if (entity.listOptions.isNotEmpty) { |     if (entity.listOptions.isNotEmpty) { | ||||||
|       ctrl = DropdownButton<String>( |       ctrl = DropdownButton<String>( | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ class SimpleEntityState extends StatelessWidget { | |||||||
|         padding: padding, |         padding: padding, | ||||||
|         child: GestureDetector( |         child: GestureDetector( | ||||||
|           child: Text( |           child: Text( | ||||||
|               "${entityModel.entity.state}${entityModel.entity.unitOfMeasurement}", |               "${entityModel.entity.entity.state}${entityModel.entity.entity.unitOfMeasurement}", | ||||||
|               textAlign: textAlign, |               textAlign: textAlign, | ||||||
|               maxLines: 4, |               maxLines: 4, | ||||||
|               overflow: TextOverflow.ellipsis, |               overflow: TextOverflow.ellipsis, | ||||||
| @@ -24,7 +24,7 @@ class SimpleEntityState extends StatelessWidget { | |||||||
|                 fontSize: Sizes.stateFontSize, |                 fontSize: Sizes.stateFontSize, | ||||||
|               )), |               )), | ||||||
|           onTap: () => entityModel.handleTap |           onTap: () => entityModel.handleTap | ||||||
|               ? eventBus.fire(new ShowEntityPageEvent(entityModel.entity)) |               ? eventBus.fire(new ShowEntityPageEvent(entityModel.entity.entity)) | ||||||
|               : null, |               : null, | ||||||
|         ) |         ) | ||||||
|     ); |     ); | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ class _SwitchStateWidgetState extends State<SwitchStateWidget> { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final entity = entityModel.entity; |     final entity = entityModel.entity.entity; | ||||||
|     if (!updatedHere) { |     if (!updatedHere) { | ||||||
|       newState = entity.state; |       newState = entity.state; | ||||||
|     } else { |     } else { | ||||||
|   | |||||||
| @@ -55,7 +55,7 @@ class _TextInputStateWidgetState extends State<TextInputStateWidget> { | |||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     final entityModel = EntityModel.of(context); |     final entityModel = EntityModel.of(context); | ||||||
|     final TextEntity entity = entityModel.entity; |     final TextEntity entity = entityModel.entity.entity; | ||||||
|     _entityState = entity.state; |     _entityState = entity.state; | ||||||
|     _entityDomain = entity.domain; |     _entityDomain = entity.domain; | ||||||
|     _entityId = entity.entityId; |     _entityId = entity.entityId; | ||||||
|   | |||||||
| @@ -413,20 +413,42 @@ class HomeAssistant { | |||||||
|             name: rawCard["title"], |             name: rawCard["title"], | ||||||
|             type: rawCard['type'], |             type: rawCard['type'], | ||||||
|             columnsCount: rawCard['columns'] ?? 4, |             columnsCount: rawCard['columns'] ?? 4, | ||||||
|  |             showName: rawCard['show_name'] ?? true, | ||||||
|  |             showState: rawCard['show_state'] ?? true, | ||||||
|         ); |         ); | ||||||
|         rawCard["entities"]?.forEach((rawEntity) { |         rawCard["entities"]?.forEach((rawEntity) { | ||||||
|           if (rawEntity is String) { |           if (rawEntity is String) { | ||||||
|             if (entities.isExist(rawEntity)) { |             if (entities.isExist(rawEntity)) { | ||||||
|               card.entities.add(entities.get(rawEntity)); |               card.entities.add(EntityWrapper(entity: entities.get(rawEntity))); | ||||||
|             } |             } | ||||||
|           } else { |           } else { | ||||||
|             if (entities.isExist(rawEntity["entity"])) { |             if (entities.isExist(rawEntity["entity"])) { | ||||||
|               card.entities.add(entities.get(rawEntity["entity"])); |               card.entities.add( | ||||||
|  |                   EntityWrapper( | ||||||
|  |                     entity: entities.get(rawEntity["entity"]), | ||||||
|  |                     displayName: rawEntity["name"], | ||||||
|  |                     icon: rawEntity["icon"] | ||||||
|  |                   ) | ||||||
|  |               ); | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|         }); |         }); | ||||||
|         if (rawCard["entity"] != null) { |         if (rawCard["entity"] != null) { | ||||||
|           card.linkedEntity = entities.get(rawCard["entity"]); |           var en = rawCard["entity"]; | ||||||
|  |           if (en is String) { | ||||||
|  |             if (entities.isExist(en)) { | ||||||
|  |               card.linkedEntity = EntityWrapper(entity: entities.get(en)); | ||||||
|  |             } | ||||||
|  |           } else { | ||||||
|  |             if (entities.isExist(en["entity"])) { | ||||||
|  |               card.linkedEntity = EntityWrapper( | ||||||
|  |                 entity: entities.get(en["entity"]), | ||||||
|  |                 icon: en["icon"], | ||||||
|  |                 displayName: en["name"] | ||||||
|  |               ); | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  |  | ||||||
|         } |         } | ||||||
|         result.add(card); |         result.add(card); | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ import 'package:charts_flutter/flutter.dart' as charts; | |||||||
|  |  | ||||||
| part 'entity_class/const.dart'; | part 'entity_class/const.dart'; | ||||||
| part 'entity_class/entity.class.dart'; | part 'entity_class/entity.class.dart'; | ||||||
|  | part 'entity_class/entity_wrapper.class.dart'; | ||||||
| part 'entity_class/switch_entity.class.dart'; | part 'entity_class/switch_entity.class.dart'; | ||||||
| part 'entity_class/button_entity.class.dart'; | part 'entity_class/button_entity.class.dart'; | ||||||
| part 'entity_class/text_entity.class.dart'; | part 'entity_class/text_entity.class.dart'; | ||||||
| @@ -80,7 +81,7 @@ part 'ui_widgets/card_header_widget.dart'; | |||||||
|  |  | ||||||
| EventBus eventBus = new EventBus(); | EventBus eventBus = new EventBus(); | ||||||
| const String appName = "HA Client"; | const String appName = "HA Client"; | ||||||
| const appVersion = "0.3.8 internal build 64"; | const appVersion = "0.3.8-65"; | ||||||
|  |  | ||||||
| String homeAssistantWebHost; | String homeAssistantWebHost; | ||||||
|  |  | ||||||
| @@ -480,7 +481,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | |||||||
|       headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { |       headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { | ||||||
|         return <Widget>[ |         return <Widget>[ | ||||||
|           SliverAppBar( |           SliverAppBar( | ||||||
|             //expandedHeight: 100.0, |  | ||||||
|             floating: true, |             floating: true, | ||||||
|             pinned: true, |             pinned: true, | ||||||
|             primary: true, |             primary: true, | ||||||
| @@ -530,6 +530,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver { | |||||||
|     if (_homeAssistant.ui == null || _homeAssistant.ui.views == null) { |     if (_homeAssistant.ui == null || _homeAssistant.ui.views == null) { | ||||||
|       return Scaffold( |       return Scaffold( | ||||||
|         key: _scaffoldKey, |         key: _scaffoldKey, | ||||||
|  |         primary: true, | ||||||
|         drawer: _buildAppDrawer(), |         drawer: _buildAppDrawer(), | ||||||
|         body: _buildScaffoldBody(true) |         body: _buildScaffoldBody(true) | ||||||
|       ); |       ); | ||||||
|   | |||||||
| @@ -2880,17 +2880,17 @@ class MaterialDesignIcons { | |||||||
|     "mdi:blank": 0xf68c |     "mdi:blank": 0xf68c | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   static Widget createIconWidgetFromEntityData(Entity data, double size, Color color) { |   static Widget createIconWidgetFromEntityData(EntityWrapper data, double size, Color color) { | ||||||
|     if (data == null) { |     if (data == null) { | ||||||
|       return null; |       return null; | ||||||
|     } |     } | ||||||
|     if (data.entityPicture != null) { |     if (data.entity.entityPicture != null) { | ||||||
|       if (homeAssistantWebHost != null) { |       if (homeAssistantWebHost != null) { | ||||||
|         return CircleAvatar( |         return CircleAvatar( | ||||||
|           radius: size/2, |           radius: size/2, | ||||||
|           backgroundColor: Colors.white, |           backgroundColor: Colors.white, | ||||||
|           backgroundImage: CachedNetworkImageProvider( |           backgroundImage: CachedNetworkImageProvider( | ||||||
|             "$homeAssistantWebHost${data.entityPicture}", |             "$homeAssistantWebHost${data.entity.entityPicture}", | ||||||
|           ), |           ), | ||||||
|         ); |         ); | ||||||
|       } else { |       } else { | ||||||
| @@ -2902,8 +2902,8 @@ class MaterialDesignIcons { | |||||||
|       if (iconName.length > 0) { |       if (iconName.length > 0) { | ||||||
|         iconCode = getIconCodeByIconName(iconName); |         iconCode = getIconCodeByIconName(iconName); | ||||||
|       } else { |       } else { | ||||||
|         iconCode = getDefaultIconByEntityId(data.entityId, |         iconCode = getDefaultIconByEntityId(data.entity.entityId, | ||||||
|             data.deviceClass, data.state); // |             data.entity.deviceClass, data.entity.state); // | ||||||
|       } |       } | ||||||
|       return Icon( |       return Icon( | ||||||
|         IconData(iconCode, fontFamily: 'Material Design Icons'), |         IconData(iconCode, fontFamily: 'Material Design Icons'), | ||||||
|   | |||||||
| @@ -1,11 +1,13 @@ | |||||||
| part of '../main.dart'; | part of '../main.dart'; | ||||||
|  |  | ||||||
| class HACard { | class HACard { | ||||||
|   List<Entity> entities = []; |   List<EntityWrapper> entities = []; | ||||||
|   Entity linkedEntity; |   EntityWrapper linkedEntity; | ||||||
|   String name; |   String name; | ||||||
|   String id; |   String id; | ||||||
|   String type; |   String type; | ||||||
|  |   bool showName; | ||||||
|  |   bool showState; | ||||||
|   int columnsCount; |   int columnsCount; | ||||||
|  |  | ||||||
|   HACard({ |   HACard({ | ||||||
| @@ -13,6 +15,8 @@ class HACard { | |||||||
|     this.id, |     this.id, | ||||||
|     this.linkedEntity, |     this.linkedEntity, | ||||||
|     this.columnsCount: 4, |     this.columnsCount: 4, | ||||||
|  |     this.showName: true, | ||||||
|  |     this.showState: true, | ||||||
|     @required this.type |     @required this.type | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ class HAView { | |||||||
|       HACard card = HACard( |       HACard card = HACard( | ||||||
|           name: e.displayName, |           name: e.displayName, | ||||||
|           id: e.entityId, |           id: e.entityId, | ||||||
|           linkedEntity: e, |           linkedEntity: EntityWrapper(entity: e), | ||||||
|           type: "media-control" |           type: "media-control" | ||||||
|       ); |       ); | ||||||
|       cards.add(card); |       cards.add(card); | ||||||
| @@ -42,24 +42,24 @@ class HAView { | |||||||
|               name: entity.domain, |               name: entity.domain, | ||||||
|               type: "entities" |               type: "entities" | ||||||
|           ); |           ); | ||||||
|           card.entities.add(entity); |           card.entities.add(EntityWrapper(entity: entity)); | ||||||
|           autoGeneratedCards.add(card); |           autoGeneratedCards.add(card); | ||||||
|         } else { |         } else { | ||||||
|           autoGeneratedCards.firstWhere((card) => card.id == groupIdToAdd).entities.add(entity); |           autoGeneratedCards.firstWhere((card) => card.id == groupIdToAdd).entities.add(EntityWrapper(entity: entity)); | ||||||
|         } |         } | ||||||
|       } else { |       } else { | ||||||
|         HACard card = HACard( |         HACard card = HACard( | ||||||
|             name: entity.displayName, |             name: entity.displayName, | ||||||
|             id: entity.entityId, |             id: entity.entityId, | ||||||
|             linkedEntity: entity, |             linkedEntity: EntityWrapper(entity: entity), | ||||||
|             type: "entities" |             type: "entities" | ||||||
|         ); |         ); | ||||||
|         card.entities.addAll(entity.childEntities.where((entity) {return entity.domain != "media_player";})); |         card.entities.addAll(entity.childEntities.where((entity) {return entity.domain != "media_player";}).map((e) {return EntityWrapper(entity: entity);})); | ||||||
|         entity.childEntities.where((entity) {return entity.domain == "media_player";}).forEach((entity){ |         entity.childEntities.where((entity) {return entity.domain == "media_player";}).forEach((entity){ | ||||||
|           HACard mediaCard = HACard( |           HACard mediaCard = HACard( | ||||||
|               name: entity.displayName, |               name: entity.displayName, | ||||||
|               id: entity.entityId, |               id: entity.entityId, | ||||||
|               linkedEntity: entity, |               linkedEntity: EntityWrapper(entity: entity), | ||||||
|               type: "media-control" |               type: "media-control" | ||||||
|           ); |           ); | ||||||
|           cards.add(mediaCard); |           cards.add(mediaCard); | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ class EntitiesCardWidget extends StatelessWidget { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     if ((card.linkedEntity!= null) && (card.linkedEntity.isHidden)) { |     if ((card.linkedEntity!= null) && (card.linkedEntity.entity.isHidden)) { | ||||||
|       return Container(width: 0.0, height: 0.0,); |       return Container(width: 0.0, height: 0.0,); | ||||||
|     } |     } | ||||||
|     List<Widget> body = []; |     List<Widget> body = []; | ||||||
| @@ -24,12 +24,16 @@ class EntitiesCardWidget extends StatelessWidget { | |||||||
|  |  | ||||||
|   List<Widget> _buildCardBody(BuildContext context) { |   List<Widget> _buildCardBody(BuildContext context) { | ||||||
|     List<Widget> result = []; |     List<Widget> result = []; | ||||||
|     card.entities.forEach((Entity entity) { |     card.entities.forEach((EntityWrapper entity) { | ||||||
|       if (!entity.isHidden) { |       if (!entity.entity.isHidden) { | ||||||
|         result.add( |         result.add( | ||||||
|             Padding( |             Padding( | ||||||
|               padding: EdgeInsets.fromLTRB(0.0, Sizes.rowPadding, 0.0, Sizes.rowPadding), |               padding: EdgeInsets.fromLTRB(0.0, Sizes.rowPadding, 0.0, Sizes.rowPadding), | ||||||
|               child: entity.buildDefaultWidget(context), |               child: EntityModel( | ||||||
|  |                   entity: entity, | ||||||
|  |                   handleTap: true, | ||||||
|  |                   child: entity.entity.buildDefaultWidget(context) | ||||||
|  |               ), | ||||||
|             )); |             )); | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ class GlanceCardWidget extends StatelessWidget { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     if ((card.linkedEntity!= null) && (card.linkedEntity.isHidden)) { |     if ((card.linkedEntity!= null) && (card.linkedEntity.entity.isHidden)) { | ||||||
|       return Container(width: 0.0, height: 0.0,); |       return Container(width: 0.0, height: 0.0,); | ||||||
|     } |     } | ||||||
|     List<Widget> rows = []; |     List<Widget> rows = []; | ||||||
| @@ -25,14 +25,18 @@ class GlanceCardWidget extends StatelessWidget { | |||||||
|   Widget _buildRows(BuildContext context) { |   Widget _buildRows(BuildContext context) { | ||||||
|     List<Widget> result = []; |     List<Widget> result = []; | ||||||
|     double width = MediaQuery.of(context).size.width - Sizes.leftWidgetPadding - (2*Sizes.rightWidgetPadding); |     double width = MediaQuery.of(context).size.width - Sizes.leftWidgetPadding - (2*Sizes.rightWidgetPadding); | ||||||
|     List<Entity> toShow = card.entities.where((entity) {return !entity.isHidden;}).toList(); |     List<EntityWrapper> toShow = card.entities.where((entity) {return !entity.entity.isHidden;}).toList(); | ||||||
|     int columnsCount = toShow.length >= card.columnsCount ? card.columnsCount : toShow.length; |     int columnsCount = toShow.length >= card.columnsCount ? card.columnsCount : toShow.length; | ||||||
|     card.entities.forEach((Entity entity) { |     card.entities.forEach((EntityWrapper entity) { | ||||||
|       if (!entity.isHidden) { |       if (!entity.entity.isHidden) { | ||||||
|         result.add( |         result.add( | ||||||
|           SizedBox( |           SizedBox( | ||||||
|             width: width / columnsCount, |             width: width / columnsCount, | ||||||
|             child: entity.buildGlanceWidget(context), |             child: EntityModel( | ||||||
|  |               entity: entity, | ||||||
|  |               child: entity.entity.buildGlanceWidget(context, card.showName, card.showState), | ||||||
|  |               handleTap: true | ||||||
|  |             ), | ||||||
|           ) |           ) | ||||||
|         ); |         ); | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ class MediaControlCardWidget extends StatelessWidget { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     if ((card.linkedEntity == null) || (card.linkedEntity.isHidden)) { |     if ((card.linkedEntity == null) || (card.linkedEntity.entity.isHidden)) { | ||||||
|       return Container(width: 0.0, height: 0.0,); |       return Container(width: 0.0, height: 0.0,); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ class UnsupportedCardWidget extends StatelessWidget { | |||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|     if ((card.linkedEntity!= null) && (card.linkedEntity.isHidden)) { |     if ((card.linkedEntity!= null) && (card.linkedEntity.entity.isHidden)) { | ||||||
|       return Container(width: 0.0, height: 0.0,); |       return Container(width: 0.0, height: 0.0,); | ||||||
|     } |     } | ||||||
|     List<Widget> body = []; |     List<Widget> body = []; | ||||||
| @@ -32,7 +32,11 @@ class UnsupportedCardWidget extends StatelessWidget { | |||||||
|       result.addAll(<Widget>[ |       result.addAll(<Widget>[ | ||||||
|           Padding( |           Padding( | ||||||
|             padding: EdgeInsets.fromLTRB(0.0, Sizes.rowPadding, 0.0, Sizes.rowPadding), |             padding: EdgeInsets.fromLTRB(0.0, Sizes.rowPadding, 0.0, Sizes.rowPadding), | ||||||
|             child: card.linkedEntity.buildDefaultWidget(context), |             child: EntityModel( | ||||||
|  |                 entity: card.linkedEntity, | ||||||
|  |                 handleTap: true, | ||||||
|  |                 child: card.linkedEntity.entity.buildDefaultWidget(context) | ||||||
|  |             ), | ||||||
|           ) |           ) | ||||||
|       ]); |       ]); | ||||||
|     } else { |     } else { | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| name: hass_client | name: hass_client | ||||||
| description: Home Assistant Android Client | description: Home Assistant Android Client | ||||||
|  |  | ||||||
| version: 0.3.8+64 | version: 0.3.8+65 | ||||||
|  |  | ||||||
| environment: | environment: | ||||||
|   sdk: ">=2.0.0-dev.68.0 <3.0.0" |   sdk: ">=2.0.0-dev.68.0 <3.0.0" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user