diff --git a/lib/card_class.dart b/lib/card_class.dart index d4debe4..68b64a6 100644 --- a/lib/card_class.dart +++ b/lib/card_class.dart @@ -4,13 +4,11 @@ class HACard extends StatelessWidget { final List entities; final String friendlyName; - final bool hidden; const HACard({ Key key, this.entities, - this.friendlyName, - this.hidden + this.friendlyName }) : super(key: key); @override @@ -18,13 +16,9 @@ class HACard extends StatelessWidget { List body = []; body.add(_buildCardHeader()); body.addAll(_buildCardBody(context)); - if (hidden) { - return Container(height: 0.0,); - } else { - return Card( - child: new Column(mainAxisSize: MainAxisSize.min, children: body) - ); - } + return Card( + child: new Column(mainAxisSize: MainAxisSize.min, children: body) + ); } Widget _buildCardHeader() { diff --git a/lib/entity_class/entity.class.dart b/lib/entity_class/entity.class.dart index 391f17d..0d1c84c 100644 --- a/lib/entity_class/entity.class.dart +++ b/lib/entity_class/entity.class.dart @@ -62,7 +62,6 @@ class Entity { String get unitOfMeasurement => attributes["unit_of_measurement"] ?? ""; List get childEntityIds => attributes["entity_id"] ?? []; String get lastUpdated => _getLastUpdatedFormatted(); - bool get isHidden => attributes["hidden"] ?? false; Entity(Map rawData) { update(rawData); diff --git a/lib/entity_class/stateful_widgets.dart b/lib/entity_class/stateful_widgets.dart index 9238fbd..ef26077 100644 --- a/lib/entity_class/stateful_widgets.dart +++ b/lib/entity_class/stateful_widgets.dart @@ -781,12 +781,14 @@ class _LightControlsWidgetState extends State { Color _tmpColor; bool _changedHere = false; String _tmpEffect; + String _tmpFlash; void _resetState(LightEntity entity) { _tmpBrightness = entity.brightness; _tmpColorTemp = entity.colorTemp; _tmpColor = entity.color; _tmpEffect = null; + _tmpFlash = null; } void _setBrightness(LightEntity entity, double value) { @@ -844,6 +846,18 @@ class _LightControlsWidgetState extends State { }); } + void _setFlash(LightEntity entity, String value) { + setState(() { + _tmpFlash = value; + _changedHere = true; + if (_tmpFlash != null) { + eventBus.fire(new ServiceCallEvent( + entity.domain, "turn_on", entity.entityId, + {"flash": "$value"})); + } + }); + } + @override Widget build(BuildContext context) { final entityModel = EntityModel.of(context); diff --git a/lib/view_builder.class.dart b/lib/view_builder.class.dart index 78abe3a..1f6ed36 100644 --- a/lib/view_builder.class.dart +++ b/lib/view_builder.class.dart @@ -13,8 +13,8 @@ class ViewBuilder{ } Widget buildWidget(BuildContext context) { - return TabBarView( - children: _views + return ViewBuilderWidget( + entities: _views ); } @@ -41,7 +41,7 @@ class ViewBuilder{ entitiesForView.add(entityCollection.get(entityId)); }); return View( - childEntities: entitiesForView, + entities: entitiesForView, count: 0 ); } @@ -68,7 +68,7 @@ class ViewBuilder{ }); result.add(View( count: counter, - childEntities: entitiesForView + entities: entitiesForView )); /*} catch (error) { TheLogger.log("Error","Error parsing view: $viewId"); @@ -76,4 +76,30 @@ class ViewBuilder{ }); return result; } +} + +class ViewBuilderWidget extends StatelessWidget { + + final List entities; + + const ViewBuilderWidget({ + Key key, + this.entities + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return TabBarView( + children: _buildChildren(context) + ); + } + + List _buildChildren(BuildContext context) { + List result = []; + entities.forEach((View view){ + result.add(view.buildWidget(context)); + }); + return result; + } + } \ No newline at end of file diff --git a/lib/view_class.dart b/lib/view_class.dart index b7ab19c..29cf665 100644 --- a/lib/view_class.dart +++ b/lib/view_class.dart @@ -1,30 +1,77 @@ part of 'main.dart'; -class View extends StatefulWidget { - final String displayName; - final List childEntities; - final int count; +class View { + List childEntitiesAsBadges; + Map childEntitiesAsCards; + + int count; + List entities; View({ Key key, - @required this.childEntities, - @required this.count, + this.count, + this.entities + }) { + childEntitiesAsBadges = []; + childEntitiesAsCards = {}; + _composeEntities(); + } + + Widget buildWidget(BuildContext context) { + return ViewWidget( + badges: childEntitiesAsBadges, + cards: childEntitiesAsCards, + ); + } + + void _composeEntities() { + entities.forEach((Entity entity){ + if (!entity.isGroup) { + if (entity.isBadge) { + childEntitiesAsBadges.add(entity); + } else { + String groupIdToAdd = "${entity.domain}.${entity.domain}$count"; + if (childEntitiesAsCards[groupIdToAdd] == null) { + childEntitiesAsCards[groupIdToAdd] = CardSkeleton( + displayName: entity.domain, + ); + } + childEntitiesAsCards[groupIdToAdd].childEntities.add(entity); + } + } else { + childEntitiesAsCards[entity.entityId] = CardSkeleton( + displayName: entity.displayName, + ); + childEntitiesAsCards[entity.entityId].childEntities = entity.childEntities; + } + }); + } + +} + +class ViewWidget extends StatefulWidget { + final List badges; + final Map cards; + final String displayName; + + const ViewWidget({ + Key key, + this.badges, + this.cards, this.displayName }) : super(key: key); @override State createState() { - return ViewState(); + return ViewWidgetState(); } } -class ViewState extends State { +class ViewWidgetState extends State { StreamSubscription _refreshDataSubscription; Completer _refreshCompleter; - List _childEntitiesAsBadges; - Map _childEntitiesAsCards; @override void initState() { @@ -34,28 +81,6 @@ class ViewState extends State { _refreshCompleter.complete(); } }); - _childEntitiesAsCards = {}; - _childEntitiesAsBadges = []; - _composeEntities(); - } - - void _composeEntities() { - widget.childEntities.forEach((Entity entity){ - if (!entity.isGroup) { - if (entity.isBadge) { - _childEntitiesAsBadges.add(entity); - } else { - String groupIdToAdd = "${entity.domain}.${entity.domain}${widget.count}"; - if (_childEntitiesAsCards[groupIdToAdd] == null) { - _childEntitiesAsCards[groupIdToAdd] = entity; - } - _childEntitiesAsCards[groupIdToAdd].childEntities.add(entity); - } - } else { - _childEntitiesAsCards[entity.entityId] = entity; - _childEntitiesAsCards[entity.entityId].childEntities = entity.childEntities; - } - }); } @override @@ -73,23 +98,22 @@ class ViewState extends State { List _buildChildren(BuildContext context) { List result = []; - if (_childEntitiesAsBadges.isNotEmpty) { + if (widget.badges.isNotEmpty) { result.insert(0, Wrap( alignment: WrapAlignment.center, spacing: 10.0, runSpacing: 1.0, - children: _buildBadges(context), + children: _buildBadges(context, widget.badges), ) ); } - _childEntitiesAsCards.forEach((String id, Entity groupEntity){ + widget.cards.forEach((String id, CardSkeleton skeleton){ result.add( HACard( - entities: groupEntity.childEntities, - friendlyName: groupEntity.displayName, - hidden: groupEntity.isHidden + entities: skeleton.childEntities, + friendlyName: skeleton.displayName, ) ); }); @@ -97,9 +121,9 @@ class ViewState extends State { return result; } - List _buildBadges(BuildContext context) { + List _buildBadges(BuildContext context, List badges) { List result = []; - _childEntitiesAsBadges.forEach((Entity entity) { + badges.forEach((Entity entity) { result.add(entity.buildBadgeWidget(context)); }); return result; @@ -120,4 +144,15 @@ class ViewState extends State { _refreshDataSubscription.cancel(); super.dispose(); } + + +} + +class CardSkeleton { + String displayName; + List childEntities; + + CardSkeleton({Key key, this.displayName, this.childEntities}) { + childEntities = []; + } } \ No newline at end of file