Skiping entity and views that cause parsing errors
This commit is contained in:
parent
4dc211f2f7
commit
86738a0515
@ -49,7 +49,7 @@ class HassioDataModel {
|
||||
debugPrint("Previous fetch is not complited");
|
||||
} else {
|
||||
//TODO: Fetch timeout timer. Should be removed after #21 fix
|
||||
_fetchingTimer = Timer(Duration(seconds: 10), () {
|
||||
_fetchingTimer = Timer(Duration(seconds: 15), () {
|
||||
closeConnection();
|
||||
_fetchCompleter.completeError({"errorCode" : 1,"errorMessage": "Connection timeout"});
|
||||
});
|
||||
@ -215,12 +215,13 @@ class HassioDataModel {
|
||||
_servicesCompleter.completeError({"errorCode": 4, "errorMessage": response["error"]["message"]});
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Map data = response["result"];
|
||||
Map result = {};
|
||||
debugPrint("Parsing ${data.length} Home Assistant service domains");
|
||||
data.forEach((domain, services){
|
||||
data.forEach((domain, services) {
|
||||
result[domain] = Map.from(services);
|
||||
services.forEach((serviceName, serviceData){
|
||||
services.forEach((serviceName, serviceData) {
|
||||
if (_entitiesData["$domain.$serviceName"] != null) {
|
||||
result[domain].remove(serviceName);
|
||||
}
|
||||
@ -228,6 +229,11 @@ class HassioDataModel {
|
||||
});
|
||||
_servicesData = result;
|
||||
_servicesCompleter.complete();
|
||||
} catch (e) {
|
||||
//TODO hadle it properly
|
||||
debugPrint("Error parsing services");
|
||||
_servicesCompleter.complete();
|
||||
}
|
||||
}
|
||||
|
||||
void _parseEntities(response) async {
|
||||
@ -241,33 +247,42 @@ class HassioDataModel {
|
||||
debugPrint("Parsing ${data.length} Home Assistant entities");
|
||||
List<String> uiGroups = [];
|
||||
data.forEach((entity) {
|
||||
try {
|
||||
var composedEntity = _parseEntity(entity);
|
||||
|
||||
if (composedEntity["attributes"] != null) {
|
||||
if ((composedEntity["domain"] == "group")&&(composedEntity["attributes"]["view"] == true)) {
|
||||
if ((composedEntity["domain"] == "group") &&
|
||||
(composedEntity["attributes"]["view"] == true)) {
|
||||
uiGroups.add(composedEntity["entity_id"]);
|
||||
}
|
||||
}
|
||||
|
||||
_entitiesData[composedEntity["entity_id"]] = composedEntity;
|
||||
_entitiesData[entity["entity_id"]] = composedEntity;
|
||||
} catch (error) {
|
||||
debugPrint("Error parsing entity: ${entity['entity_id']}");
|
||||
debugPrint("$error");
|
||||
}
|
||||
});
|
||||
|
||||
//Gethering information for UI
|
||||
debugPrint("Gethering views");
|
||||
int viewCounter = 0;
|
||||
uiGroups.forEach((viewId) { //Each view
|
||||
viewCounter +=1;
|
||||
var viewGroup = _entitiesData[viewId];
|
||||
try {
|
||||
Map viewGroupStructure = {};
|
||||
viewCounter += 1;
|
||||
var viewGroup = _entitiesData[viewId];
|
||||
if (viewGroup != null) {
|
||||
viewGroupStructure["groups"] = {};
|
||||
viewGroupStructure["state"] = "on";
|
||||
viewGroupStructure["entity_id"] = viewGroup["entity_id"];
|
||||
viewGroupStructure["badges"] = {"children": []};
|
||||
viewGroupStructure["attributes"] = viewGroup["attributes"] != null ? {"icon": viewGroup["attributes"]["icon"]} : {"icon": "none"};
|
||||
viewGroupStructure["attributes"] = viewGroup["attributes"] != null ? {
|
||||
"icon": viewGroup["attributes"]["icon"]
|
||||
} : {"icon": "none"};
|
||||
|
||||
|
||||
viewGroup["attributes"]["entity_id"].forEach((entityId) { //Each entity or group in view
|
||||
viewGroup["attributes"]["entity_id"].forEach((
|
||||
entityId) { //Each entity or group in view
|
||||
Map newGroup = {};
|
||||
String domain = _entitiesData[entityId]["domain"];
|
||||
if (domain != "group") {
|
||||
@ -291,7 +306,8 @@ class HassioDataModel {
|
||||
newGroup["entity_id"] = entityId;
|
||||
newGroup["friendly_name"] =
|
||||
(_entitiesData[entityId]['attributes'] != null)
|
||||
? (_entitiesData[entityId]['attributes']['friendly_name'] ?? "")
|
||||
? (_entitiesData[entityId]['attributes']['friendly_name'] ??
|
||||
"")
|
||||
: "";
|
||||
newGroup["children"] = List<String>();
|
||||
_entitiesData[entityId]["attributes"]["entity_id"].forEach((
|
||||
@ -301,7 +317,10 @@ class HassioDataModel {
|
||||
viewGroupStructure["groups"]["$entityId"] = Map.from(newGroup);
|
||||
}
|
||||
});
|
||||
}
|
||||
_uiStructure[viewId.split(".")[1]] = viewGroupStructure;
|
||||
} catch (error) {
|
||||
debugPrint("Error parsing view: $viewId");
|
||||
}
|
||||
});
|
||||
_statesCompleter.complete();
|
||||
|
Reference in New Issue
Block a user