Fix #77 Skip non existing entities in view
This commit is contained in:
parent
94f43ded6f
commit
94bcc30421
@ -272,57 +272,64 @@ class HassioDataModel {
|
|||||||
int viewCounter = 0;
|
int viewCounter = 0;
|
||||||
uiGroups.forEach((viewId) { //Each view
|
uiGroups.forEach((viewId) { //Each view
|
||||||
try {
|
try {
|
||||||
Map viewGroupStructure = {};
|
Map viewStructure = {};
|
||||||
viewCounter += 1;
|
viewCounter += 1;
|
||||||
var viewGroup = _entitiesData[viewId];
|
var viewGroupData = _entitiesData[viewId];
|
||||||
if (viewGroup != null) {
|
if ((viewGroupData != null) && (viewGroupData["attributes"] != null)) {
|
||||||
viewGroupStructure["groups"] = {};
|
viewStructure["groups"] = {};
|
||||||
viewGroupStructure["state"] = "on";
|
viewStructure["state"] = "on";
|
||||||
viewGroupStructure["entity_id"] = viewGroup["entity_id"];
|
viewStructure["entity_id"] = viewGroupData["entity_id"];
|
||||||
viewGroupStructure["badges"] = {"children": []};
|
viewStructure["badges"] = {"children": []};
|
||||||
viewGroupStructure["attributes"] = viewGroup["attributes"] != null ? {
|
viewStructure["attributes"] = {
|
||||||
"icon": viewGroup["attributes"]["icon"]
|
"icon": viewGroupData["attributes"]["icon"]
|
||||||
} : {"icon": "none"};
|
};
|
||||||
|
|
||||||
|
viewGroupData["attributes"]["entity_id"].forEach((
|
||||||
viewGroup["attributes"]["entity_id"].forEach((
|
|
||||||
entityId) { //Each entity or group in view
|
entityId) { //Each entity or group in view
|
||||||
Map newGroup = {};
|
Map newGroup = {};
|
||||||
String domain = _entitiesData[entityId]["domain"];
|
if (_entitiesData[entityId] != null) {
|
||||||
|
Map cardOrEntityData = _entitiesData[entityId];
|
||||||
|
String domain = cardOrEntityData["domain"];
|
||||||
if (domain != "group") {
|
if (domain != "group") {
|
||||||
if (_topBadgeDomains.contains(domain)) {
|
if (_topBadgeDomains.contains(domain)) {
|
||||||
viewGroupStructure["badges"]["children"].add(entityId);
|
viewStructure["badges"]["children"].add(entityId);
|
||||||
} else {
|
} else {
|
||||||
String autoGroupID = "$domain.$domain$viewCounter";
|
String autoGroupID = "$domain.$domain$viewCounter";
|
||||||
if (viewGroupStructure["groups"]["$autoGroupID"] == null) {
|
if (viewStructure["groups"]["$autoGroupID"] == null) {
|
||||||
newGroup["entity_id"] = "$domain.$domain$viewCounter";
|
newGroup["entity_id"] = "$domain.$domain$viewCounter";
|
||||||
newGroup["friendly_name"] = "$domain";
|
newGroup["friendly_name"] = "$domain";
|
||||||
newGroup["children"] = [];
|
newGroup["children"] = [];
|
||||||
newGroup["children"].add(entityId);
|
newGroup["children"].add(entityId);
|
||||||
viewGroupStructure["groups"]["$autoGroupID"] =
|
viewStructure["groups"]["$autoGroupID"] =
|
||||||
Map.from(newGroup);
|
Map.from(newGroup);
|
||||||
} else {
|
} else {
|
||||||
viewGroupStructure["groups"]["$autoGroupID"]["children"].add(
|
viewStructure["groups"]["$autoGroupID"]["children"].add(
|
||||||
entityId);
|
entityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newGroup["entity_id"] = entityId;
|
newGroup["entity_id"] = entityId;
|
||||||
newGroup["friendly_name"] =
|
newGroup["friendly_name"] =
|
||||||
(_entitiesData[entityId]['attributes'] != null)
|
(cardOrEntityData['attributes'] != null)
|
||||||
? (_entitiesData[entityId]['attributes']['friendly_name'] ??
|
? (cardOrEntityData['attributes']['friendly_name'] ??
|
||||||
"")
|
"")
|
||||||
: "";
|
: "";
|
||||||
newGroup["children"] = List<String>();
|
newGroup["children"] = List<String>();
|
||||||
_entitiesData[entityId]["attributes"]["entity_id"].forEach((
|
cardOrEntityData["attributes"]["entity_id"].forEach((
|
||||||
groupedEntityId) {
|
groupedEntityId) {
|
||||||
newGroup["children"].add(groupedEntityId);
|
newGroup["children"].add(groupedEntityId);
|
||||||
});
|
});
|
||||||
viewGroupStructure["groups"]["$entityId"] = Map.from(newGroup);
|
viewStructure["groups"]["$entityId"] = Map.from(newGroup);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TheLogger.log("Warning", "Unknown entity inside view: $entityId");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
_uiStructure[viewId.split(".")[1]] = viewStructure;
|
||||||
|
} else {
|
||||||
|
TheLogger.log("Warning", "No state or attributes found for view: $viewId");
|
||||||
}
|
}
|
||||||
_uiStructure[viewId.split(".")[1]] = viewGroupStructure;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
TheLogger.log("Error","Error parsing view: $viewId");
|
TheLogger.log("Error","Error parsing view: $viewId");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user