Initial UI generation if no lovelace config
This commit is contained in:
parent
d8df32f140
commit
d0b7cc1929
@ -152,39 +152,12 @@ class EntityCollection {
|
||||
return _allEntities[entityId] != null;
|
||||
}
|
||||
|
||||
List<Entity> getByDomains({List<String> domains, List<String> stateFiler}) {
|
||||
List<Entity> getByDomains({List<String> includeDomains: const [], List<String> excludeDomains: const [], List<String> stateFiler}) {
|
||||
return _allEntities.values.where((entity) {
|
||||
return domains.contains(entity.domain) &&
|
||||
((stateFiler != null && stateFiler.contains(entity.state)) || stateFiler == null);
|
||||
return
|
||||
(excludeDomains.isEmpty || !excludeDomains.contains(entity.domain)) &&
|
||||
(includeDomains.isEmpty || includeDomains.contains(entity.domain)) &&
|
||||
((stateFiler != null && stateFiler.contains(entity.state)) || stateFiler == null);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Entity> filterEntitiesForDefaultView() {
|
||||
List<Entity> result = [];
|
||||
List<Entity> groups = [];
|
||||
List<Entity> nonGroupEntities = [];
|
||||
_allEntities.forEach((id, entity){
|
||||
if (entity.isGroup && (entity.attributes['auto'] == null || (entity.attributes['auto'] && !entity.isHidden)) && (!entity.isView)) {
|
||||
groups.add(entity);
|
||||
}
|
||||
if (!entity.isGroup) {
|
||||
nonGroupEntities.add(entity);
|
||||
}
|
||||
});
|
||||
|
||||
nonGroupEntities.forEach((entity) {
|
||||
bool foundInGroup = false;
|
||||
groups.forEach((groupEntity) {
|
||||
if (groupEntity.childEntityIds.contains(entity.entityId)) {
|
||||
foundInGroup = true;
|
||||
}
|
||||
});
|
||||
if (!foundInGroup) {
|
||||
result.add(entity);
|
||||
}
|
||||
});
|
||||
result.insertAll(0, groups);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -37,9 +37,9 @@ class HomeAssistant {
|
||||
|
||||
String get locationName {
|
||||
if (!autoUi) {
|
||||
return ui?.title ?? "";
|
||||
return ui?.title ?? "Home";
|
||||
} else {
|
||||
return _instanceConfig["location_name"] ?? "";
|
||||
return _instanceConfig["location_name"] ?? "Home";
|
||||
}
|
||||
}
|
||||
String get userName => _userName ?? locationName;
|
||||
@ -202,6 +202,7 @@ class HomeAssistant {
|
||||
}).catchError((e) {
|
||||
if ("$e" == "config_not_found") {
|
||||
autoUi = true;
|
||||
_rawLovelaceData = null;
|
||||
completer.complete();
|
||||
} else {
|
||||
completer.completeError(HAError("Error getting lovelace config: $e"));
|
||||
@ -324,22 +325,18 @@ class HomeAssistant {
|
||||
}
|
||||
|
||||
void _createUI() {
|
||||
if (!autoUi && (_rawLovelaceData != null)) {
|
||||
Logger.d("Creating Lovelace UI");
|
||||
ui = HomeAssistantUI(_rawLovelaceData);
|
||||
if (isServiceExist('zha_map')) {
|
||||
panels.add(
|
||||
Panel(
|
||||
id: 'haclient_zha',
|
||||
componentName: 'haclient_zha',
|
||||
title: 'ZHA',
|
||||
urlPath: '/haclient_zha',
|
||||
icon: 'mdi:zigbee'
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Logger.e("No lovelace config!!!!");
|
||||
Logger.d("Creating Lovelace UI");
|
||||
ui = HomeAssistantUI(rawLovelaceConfig: _rawLovelaceData);
|
||||
if (isServiceExist('zha_map')) {
|
||||
panels.add(
|
||||
Panel(
|
||||
id: 'haclient_zha',
|
||||
componentName: 'haclient_zha',
|
||||
title: 'ZHA',
|
||||
urlPath: '/haclient_zha',
|
||||
icon: 'mdi:zigbee'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -636,7 +636,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
Widget mediaMenuIcon;
|
||||
int playersCount = 0;
|
||||
if (!empty && !HomeAssistant().entities.isEmpty) {
|
||||
List<Entity> activePlayers = HomeAssistant().entities.getByDomains(domains: ["media_player"], stateFiler: [EntityState.paused, EntityState.playing, EntityState.idle]);
|
||||
List<Entity> activePlayers = HomeAssistant().entities.getByDomains(includeDomains: ["media_player"], stateFiler: [EntityState.paused, EntityState.playing, EntityState.idle]);
|
||||
playersCount = activePlayers.length;
|
||||
mediaMenuItems.addAll(
|
||||
activePlayers.map((entity) => PopupMenuItem<String>(
|
||||
|
@ -59,7 +59,7 @@ class _PlayMediaPageState extends State<PlayMediaPage> {
|
||||
} else {
|
||||
_isMediaExtractorExist = HomeAssistant().isServiceExist("media_extractor");
|
||||
//_useMediaExtractor = _isMediaExtractorExist;
|
||||
_players = HomeAssistant().entities.getByDomains(domains: ["media_player"]);
|
||||
_players = HomeAssistant().entities.getByDomains(includeDomains: ["media_player"]);
|
||||
setState(() {
|
||||
if (_players.isNotEmpty) {
|
||||
_loaded = true;
|
||||
|
17
lib/ui.dart
17
lib/ui.dart
@ -33,7 +33,22 @@ class HomeAssistantUI {
|
||||
Map result = {};
|
||||
result['title'] = 'Home';
|
||||
result['views'] = [
|
||||
|
||||
{
|
||||
'icon': 'mdi:home',
|
||||
'badges': HomeAssistant().entities.getByDomains(
|
||||
includeDomains: ['sensor', 'binary_sensor', 'device_tracker', 'person', 'sun']
|
||||
).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()
|
||||
}]
|
||||
}
|
||||
];
|
||||
return result;
|
||||
}
|
||||
|
@ -17,15 +17,21 @@ class ViewWidget extends StatelessWidget {
|
||||
child: _buildPanelChild(context),
|
||||
);
|
||||
} else {
|
||||
Widget cardsContainer;
|
||||
if (this.view.cards.isNotEmpty) {
|
||||
cardsContainer = DynamicMultiColumnLayout(
|
||||
minColumnWidth: Sizes.minViewColumnWidth,
|
||||
children: this.view.cards.map((card) => card.build(context)).toList(),
|
||||
);
|
||||
} else {
|
||||
cardsContainer = Container();
|
||||
}
|
||||
return ListView(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.all(0),
|
||||
children: <Widget>[
|
||||
_buildBadges(context),
|
||||
DynamicMultiColumnLayout(
|
||||
minColumnWidth: Sizes.minViewColumnWidth,
|
||||
children: this.view.cards.map((card) => card.build(context)).toList(),
|
||||
)
|
||||
cardsContainer
|
||||
]
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user