From dbeda6ea68127681c8197aa4dc8e969ee0a98769 Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Tue, 19 May 2020 22:01:07 +0000 Subject: [PATCH] Default states-like UI if no Lovelace config --- .../mobile_app_integration_manager.class.dart | 9 ++-- lib/ui.dart | 47 +++++++++++++++---- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/lib/managers/mobile_app_integration_manager.class.dart b/lib/managers/mobile_app_integration_manager.class.dart index 3f7d93c..e8aaed9 100644 --- a/lib/managers/mobile_app_integration_manager.class.dart +++ b/lib/managers/mobile_app_integration_manager.class.dart @@ -128,14 +128,11 @@ class MobileAppIntegrationManager { popup: Popup( title: "App integration is not working properly", body: "Something wrong with HA Client integration on your Home Assistant server. Please report this issue. You can try to remove Mobile App integration from Home Assistant and restart server to fix this issue.", - positiveText: "Report to GitHub", - negativeText: "Report to Discord", + positiveText: "Report issue", + negativeText: "Close", onPositive: () { Launcher.launchURLInBrowser("https://github.com/estevez-dev/ha_client/issues/new"); - }, - onNegative: () { - Launcher.launchURLInBrowser("https://discord.gg/u9vq7QE"); - }, + } ) )); } diff --git a/lib/ui.dart b/lib/ui.dart index f6057fb..d4ea533 100644 --- a/lib/ui.dart +++ b/lib/ui.dart @@ -30,8 +30,42 @@ class HomeAssistantUI { } Map _generateLovelaceConfig() { - Map result = {}; - result['title'] = 'Home'; + Map result = { + 'title': 'Home' + }; + List left = HomeAssistant().entities.getByDomains( + excludeDomains: ['sensor','binary_sensor', 'device_tracker', 'person', 'sun'] + ); + List cards = []; + Map cardsByDomains = {}; + left.forEach((Entity entity) { + if (entity is GroupEntity) { + cards.add({ + 'type': CardType.ENTITIES, + 'title': entity.displayName, + 'entities': entity.childEntities.map((e) => e.entityId) + }); + } else if (entity is MediaPlayerEntity) { + cards.add({ + 'type': CardType.MEDIA_CONTROL, + 'entity': entity.entityId + }); + } else if (entity is AlarmControlPanelEntity) { + cards.add({ + 'type': CardType.ALARM_PANEL, + 'entity': entity.entityId + }); + } else if (cardsByDomains.containsKey(entity.domain)) { + cardsByDomains[entity.domain]['entities'].add(entity.entityId); + } else { + cardsByDomains[entity.domain] = { + 'type': 'entities', + 'entities': [entity.entityId], + 'title': entity.domain + }; + } + }); + cards.addAll(cardsByDomains.values); result['views'] = [ { 'icon': 'mdi:home', @@ -40,14 +74,7 @@ class HomeAssistantUI { ).map( (en) => en.entityId ).toList(), - 'cards': [{ - 'type': 'entities', - 'entities': HomeAssistant().entities.getByDomains( - excludeDomains: ['sensor','binary_sensor', 'device_tracker', 'person', 'sun'] - ).map( - (en) => en.entityId - ).toList() - }] + 'cards': cards } ]; return result;