diff --git a/lib/cards/card.class.dart b/lib/cards/card.class.dart index d694a54..fadacca 100644 --- a/lib/cards/card.class.dart +++ b/lib/cards/card.class.dart @@ -22,6 +22,7 @@ class HACard { int max; int depth; Map severity; + EntityUIAction action; HACard({ this.name, @@ -117,5 +118,4 @@ class HACard { return showByFilter; }).toList(); } - } \ No newline at end of file diff --git a/lib/cards/card_widget.dart b/lib/cards/card_widget.dart index f090119..4690756 100644 --- a/lib/cards/card_widget.dart +++ b/lib/cards/card_widget.dart @@ -15,7 +15,7 @@ class LovelaceCard extends StatelessWidget { if (card.linkedEntityWrapper.entity.isHidden) { return Container(width: 0.0, height: 0.0,); } - if (card.linkedEntityWrapper.entity.statelessType == StatelessEntityType.MISSED) { + if (card.linkedEntityWrapper.entity.statelessType == StatelessEntityType.missed) { return EntityModel( entityWrapper: card.linkedEntityWrapper, child: MissedEntityWidget(), diff --git a/lib/cards/entity_button_card.dart b/lib/cards/entity_button_card.dart index 3f4e71d..c30857f 100644 --- a/lib/cards/entity_button_card.dart +++ b/lib/cards/entity_button_card.dart @@ -10,39 +10,45 @@ class EntityButtonCard extends StatelessWidget { @override Widget build(BuildContext context) { - card.linkedEntityWrapper.overrideName = card.name?.toUpperCase() ?? - card.linkedEntityWrapper.displayName.toUpperCase(); + //card.linkedEntityWrapper.overrideName = card.name?.toUpperCase() ?? + // card.linkedEntityWrapper.displayName.toUpperCase(); EntityWrapper entityWrapper = card.linkedEntityWrapper; - if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { + if (entityWrapper.entity.statelessType == StatelessEntityType.missed) { return MissedEntityWidget(); - } - if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) { + } else if (entityWrapper.entity.statelessType != StatelessEntityType.ghost && entityWrapper.entity.statelessType != StatelessEntityType.none) { return Container(width: 0.0, height: 0.0,); } 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( - child: Center( - child: EntityModel( - entityWrapper: card.linkedEntityWrapper, - child: InkWell( - onTap: () => entityWrapper.handleTap(), - onLongPress: () => entityWrapper.handleHold(), - onDoubleTap: () => entityWrapper.handleDoubleTap(), + child: EntityModel( + entityWrapper: card.linkedEntityWrapper, + child: InkWell( + onTap: () => entityWrapper.handleTap(), + onLongPress: () => entityWrapper.handleHold(), + onDoubleTap: () => entityWrapper.handleDoubleTap(), + child: Container( child: Column( mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - EntityIcon( - padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0), - size: widthBase / (card.depth * 0.5), - ), + buttonIcon, _buildName() ], - ), + ) ), - handleTap: true ), + handleTap: true ) ); } diff --git a/lib/cards/glance_card.dart b/lib/cards/glance_card.dart index 845e856..7404b56 100644 --- a/lib/cards/glance_card.dart +++ b/lib/cards/glance_card.dart @@ -59,10 +59,9 @@ class GlanceCard extends StatelessWidget { } Widget _buildEntityContainer(BuildContext context, EntityWrapper entityWrapper) { - if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { + if (entityWrapper.entity.statelessType == StatelessEntityType.missed) { return MissedEntityWidget(); - } - if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) { + } else if (entityWrapper.entity.statelessType != StatelessEntityType.none) { return Container(width: 0.0, height: 0.0,); } List result = []; diff --git a/lib/entities/default_entity_container.widget.dart b/lib/entities/default_entity_container.widget.dart index 51d6bd6..dd5de7b 100644 --- a/lib/entities/default_entity_container.widget.dart +++ b/lib/entities/default_entity_container.widget.dart @@ -11,13 +11,13 @@ class DefaultEntityContainer extends StatelessWidget { @override Widget build(BuildContext context) { final EntityModel entityModel = EntityModel.of(context); - if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.MISSED) { + if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.missed) { return MissedEntityWidget(); } - if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.DIVIDER) { + if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.divider) { return Divider(); } - if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.SECTION) { + if (entityModel.entityWrapper.entity.statelessType == StatelessEntityType.section) { return Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, diff --git a/lib/entities/entity.class.dart b/lib/entities/entity.class.dart index dd6b193..641439e 100644 --- a/lib/entities/entity.class.dart +++ b/lib/entities/entity.class.dart @@ -1,13 +1,6 @@ part of '../main.dart'; -class StatelessEntityType { - 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; -} +enum StatelessEntityType {none, missed, ghost, divider, section, callService, webLink} class Entity { @@ -77,7 +70,7 @@ class Entity { String state; String displayState; DateTime lastUpdatedTimestamp; - int statelessType = 0; + StatelessEntityType statelessType = StatelessEntityType.none; List childEntities = []; String deviceClass; @@ -120,30 +113,35 @@ class Entity { } Entity.missed(String entityId) { - statelessType = StatelessEntityType.MISSED; + statelessType = StatelessEntityType.missed; attributes = {"hidden": false}; this.entityId = entityId; } Entity.divider() { - statelessType = StatelessEntityType.DIVIDER; + statelessType = StatelessEntityType.divider; attributes = {"hidden": false}; } Entity.section(String label) { - statelessType = StatelessEntityType.SECTION; + statelessType = StatelessEntityType.section; 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}) { - statelessType = StatelessEntityType.CALL_SERVICE; + statelessType = StatelessEntityType.callService; entityId = service; displayState = actionName?.toUpperCase() ?? "RUN"; attributes = {"hidden": false, "friendly_name": "$name", "icon": "$icon"}; } Entity.weblink({String url, String name, String icon}) { - statelessType = StatelessEntityType.WEBLINK; + statelessType = StatelessEntityType.webLink; entityId = "custom.custom"; attributes = {"hidden": false, "friendly_name": "${name ?? url}", "icon": "${icon ?? 'mdi:link'}"}; } diff --git a/lib/entities/entity_name.widget.dart b/lib/entities/entity_name.widget.dart index c7457c3..feb401a 100644 --- a/lib/entities/entity_name.widget.dart +++ b/lib/entities/entity_name.widget.dart @@ -16,7 +16,7 @@ class EntityName extends StatelessWidget { final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; TextStyle tStyle; if (textStyle == null) { - if (entityWrapper.entity.statelessType == StatelessEntityType.WEBLINK) { + if (entityWrapper.entity.statelessType == StatelessEntityType.webLink) { tStyle = HAClientTheme().getLinkTextStyle(context); } else { tStyle = Theme.of(context).textTheme.body1; diff --git a/lib/entities/entity_wrapper.class.dart b/lib/entities/entity_wrapper.class.dart index d116965..ff5a20b 100644 --- a/lib/entities/entity_wrapper.class.dart +++ b/lib/entities/entity_wrapper.class.dart @@ -21,7 +21,7 @@ class EntityWrapper { this.uiAction, 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) { uiAction = EntityUIAction(); } diff --git a/lib/entities/simple_state.widget.dart b/lib/entities/simple_state.widget.dart index 236b1e2..d480b37 100644 --- a/lib/entities/simple_state.widget.dart +++ b/lib/entities/simple_state.widget.dart @@ -25,7 +25,7 @@ class SimpleEntityState extends StatelessWidget { TextStyle tStyle; if (textStyle != null) { 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( color: Colors.blue ); diff --git a/lib/pages/widgets/bottom_info_bar.dart b/lib/pages/widgets/bottom_info_bar.dart index af09da4..17504c8 100644 --- a/lib/pages/widgets/bottom_info_bar.dart +++ b/lib/pages/widgets/bottom_info_bar.dart @@ -14,7 +14,6 @@ class BottomInfoBarController { List actions = []; void hideBottomBar() { - //_scaffoldKey?.currentState?.hideCurrentSnackBar(); _bottomBarTimer?.cancel(); if (hide == null) { initialState = false; @@ -32,7 +31,6 @@ class BottomInfoBarController { if (show == null) { initialState = true; } else { - Logger.d("Calling show() - ${bottomBarProgress}"); show(); } if (duration != null) { @@ -78,7 +76,6 @@ class _BottomInfoBarState extends State { void initState() { _show = widget.controller.initialState; widget.controller.show = () { - Logger.d('Set state in show() - ${widget.controller.bottomBarProgress}'); setState(() { _show = true; }); diff --git a/lib/view.class.dart b/lib/view.class.dart index 1a24c1f..9fbbbab 100644 --- a/lib/view.class.dart +++ b/lib/view.class.dart @@ -66,72 +66,73 @@ class HAView { card.childCards = _createLovelaceCards(rawCardInfo["cards"], depth + 1); } var rawEntities = rawCard["entities"] ?? rawCardInfo["entities"]; - rawEntities?.forEach((rawEntity) { - if (rawEntity is String) { - if (HomeAssistant().entities.isExist(rawEntity)) { - card.entities.add(EntityWrapper(entity: HomeAssistant().entities.get(rawEntity))); + var rawSingleEntity = rawCard["entity"] ?? rawCardInfo["entity"]; + if (rawEntities != null) { + rawEntities.forEach((rawEntity) { + if (rawEntity is String) { + if (HomeAssistant().entities.isExist(rawEntity)) { + card.entities.add(EntityWrapper(entity: HomeAssistant().entities.get(rawEntity))); + } else { + card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity))); + } } else { - card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity))); - } - } else { - if (rawEntity["type"] == "divider") { - card.entities.add(EntityWrapper(entity: Entity.divider())); - } else if (rawEntity["type"] == "section") { - card.entities.add(EntityWrapper(entity: Entity.section(rawEntity["label"] ?? ""))); - } else if (rawEntity["type"] == "call-service") { - Map uiActionData = { - "tap_action": { - "action": EntityUIAction.callService, - "service": rawEntity["service"], - "service_data": rawEntity["service_data"] - }, - "hold_action": EntityUIAction.none - }; - card.entities.add(EntityWrapper( + if (rawEntity["type"] == "divider") { + card.entities.add(EntityWrapper(entity: Entity.divider())); + } else if (rawEntity["type"] == "section") { + card.entities.add(EntityWrapper(entity: Entity.section(rawEntity["label"] ?? ""))); + } else if (rawEntity["type"] == "call-service") { + Map uiActionData = { + "tap_action": { + "action": EntityUIAction.callService, + "service": rawEntity["service"], + "service_data": rawEntity["service_data"] + }, + "hold_action": EntityUIAction.none + }; + card.entities.add(EntityWrapper( entity: Entity.callService( icon: rawEntity["icon"], name: rawEntity["name"], service: rawEntity["service"], actionName: rawEntity["action_name"] ), - uiAction: EntityUIAction(rawEntityData: uiActionData) - ) - ); - } else if (rawEntity["type"] == "weblink") { - Map uiActionData = { - "tap_action": { - "action": EntityUIAction.navigate, - "service": rawEntity["url"] - }, - "hold_action": EntityUIAction.none - }; - card.entities.add(EntityWrapper( - entity: Entity.weblink( - icon: rawEntity["icon"], - name: rawEntity["name"], - url: rawEntity["url"] - ), uiAction: EntityUIAction(rawEntityData: uiActionData) - ) - ); - } else if (HomeAssistant().entities.isExist(rawEntity["entity"])) { - Entity e = HomeAssistant().entities.get(rawEntity["entity"]); - card.entities.add( - EntityWrapper( - entity: e, - overrideName: rawEntity["name"], - overrideIcon: rawEntity["icon"], - stateFilter: rawEntity['state_filter'] ?? [], - uiAction: EntityUIAction(rawEntityData: rawEntity) - ) - ); - } else { - card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity["entity"]))); + ) + ); + } else if (rawEntity["type"] == "weblink") { + Map uiActionData = { + "tap_action": { + "action": EntityUIAction.navigate, + "service": rawEntity["url"] + }, + "hold_action": EntityUIAction.none + }; + card.entities.add(EntityWrapper( + entity: Entity.weblink( + icon: rawEntity["icon"], + name: rawEntity["name"], + url: rawEntity["url"] + ), + uiAction: EntityUIAction(rawEntityData: uiActionData) + ) + ); + } else if (HomeAssistant().entities.isExist(rawEntity["entity"])) { + Entity e = HomeAssistant().entities.get(rawEntity["entity"]); + card.entities.add( + EntityWrapper( + entity: e, + overrideName: rawEntity["name"], + overrideIcon: rawEntity["icon"], + stateFilter: rawEntity['state_filter'] ?? [], + uiAction: EntityUIAction(rawEntityData: rawEntity) + ) + ); + } else { + card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity["entity"]))); + } } - } - }); - var rawSingleEntity = rawCard["entity"] ?? rawCardInfo["entity"]; - if (rawSingleEntity != null) { + }); + } else if (rawSingleEntity != null) { var en = rawSingleEntity; if (en is String) { if (HomeAssistant().entities.isExist(en)) { @@ -159,6 +160,16 @@ class HAView { 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); } catch (e) {