[#51,#35] Proper handling new entities appeared after refresh
This commit is contained in:
parent
739e659a81
commit
4dc211f2f7
@ -191,13 +191,14 @@ class HassioDataModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleEntityStateChange(Map eventData) {
|
void _handleEntityStateChange(Map eventData) {
|
||||||
String entityId = eventData["entity_id"];
|
var parsedEntityData = _parseEntity(eventData["new_state"]);
|
||||||
if (_entitiesData[entityId] != null) {
|
String entityId = parsedEntityData["entity_id"];
|
||||||
_entitiesData[entityId].addAll(eventData["new_state"]);
|
if (_entitiesData[entityId] == null) {
|
||||||
eventBus.fire(new StateChangedEvent(eventData["entity_id"]));
|
_entitiesData[entityId] = parsedEntityData;
|
||||||
} else {
|
} else {
|
||||||
debugPrint("Unknown enity $entityId");
|
_entitiesData[entityId].addAll(parsedEntityData);
|
||||||
}
|
}
|
||||||
|
eventBus.fire(new StateChangedEvent(eventData["entity_id"]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _parseConfig(Map data) {
|
void _parseConfig(Map data) {
|
||||||
@ -230,6 +231,8 @@ class HassioDataModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _parseEntities(response) async {
|
void _parseEntities(response) async {
|
||||||
|
_entitiesData.clear();
|
||||||
|
_uiStructure.clear();
|
||||||
if (response["success"] == false) {
|
if (response["success"] == false) {
|
||||||
_statesCompleter.completeError({"errorCode": 3, "errorMessage": response["error"]["message"]});
|
_statesCompleter.completeError({"errorCode": 3, "errorMessage": response["error"]["message"]});
|
||||||
return;
|
return;
|
||||||
@ -238,28 +241,15 @@ class HassioDataModel {
|
|||||||
debugPrint("Parsing ${data.length} Home Assistant entities");
|
debugPrint("Parsing ${data.length} Home Assistant entities");
|
||||||
List<String> uiGroups = [];
|
List<String> uiGroups = [];
|
||||||
data.forEach((entity) {
|
data.forEach((entity) {
|
||||||
var composedEntity = Map.from(entity);
|
var composedEntity = _parseEntity(entity);
|
||||||
String entityDomain = entity["entity_id"].split(".")[0];
|
|
||||||
String entityId = entity["entity_id"];
|
|
||||||
|
|
||||||
composedEntity["display_name"] = "${entity["attributes"]!=null ? entity["attributes"]["friendly_name"] ?? entity["attributes"]["name"] : "_"}";
|
|
||||||
composedEntity["domain"] = entityDomain;
|
|
||||||
|
|
||||||
if (composedEntity["attributes"] != null) {
|
if (composedEntity["attributes"] != null) {
|
||||||
if ((entityDomain == "group")&&(composedEntity["attributes"]["view"] == true)) {
|
if ((composedEntity["domain"] == "group")&&(composedEntity["attributes"]["view"] == true)) {
|
||||||
uiGroups.add(entityId);
|
uiGroups.add(composedEntity["entity_id"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_entitiesData[composedEntity["entity_id"]] = composedEntity;
|
||||||
if (entityDomain == "group") {
|
|
||||||
if ((composedEntity["attributes"] != null) &&
|
|
||||||
(composedEntity["attributes"]["view"] == true)) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_entitiesData[entityId] = Map.from(composedEntity);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//Gethering information for UI
|
//Gethering information for UI
|
||||||
@ -317,6 +307,14 @@ class HassioDataModel {
|
|||||||
_statesCompleter.complete();
|
_statesCompleter.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map _parseEntity(rawData) {
|
||||||
|
var composedEntity = Map.from(rawData);
|
||||||
|
String entityDomain = rawData["entity_id"].split(".")[0];
|
||||||
|
composedEntity["display_name"] = "${rawData["attributes"]!=null ? rawData["attributes"]["friendly_name"] ?? rawData["attributes"]["name"] : "_"}";
|
||||||
|
composedEntity["domain"] = entityDomain;
|
||||||
|
return composedEntity;
|
||||||
|
}
|
||||||
|
|
||||||
Future callService(String domain, String service, String entity_id) {
|
Future callService(String domain, String service, String entity_id) {
|
||||||
var sendCompleter = Completer();
|
var sendCompleter = Completer();
|
||||||
//TODO: Send service call timeout timer. Should be removed after #21 fix
|
//TODO: Send service call timeout timer. Should be removed after #21 fix
|
||||||
|
Reference in New Issue
Block a user