[WIP] Entity collection

This commit is contained in:
estevez 2018-09-26 22:16:50 +03:00
parent 516d38a8a9
commit 0b42019ef3
3 changed files with 48 additions and 0 deletions

9
lib/entity.class.dart Normal file
View File

@ -0,0 +1,9 @@
part of 'main.dart';
class Entity {
Entity() {
//
}
}

View File

@ -0,0 +1,37 @@
part of 'main.dart';
class EntityCollection {
Map<String, Entity> _entities;
EntityCollection() {
_entities = {};
}
void fillFromRawData(Map rawData) {
_entities.clear();
if (response["success"] == false) {
_statesCompleter.completeError({"errorCode": 3, "errorMessage": response["error"]["message"]});
return;
}
List data = response["result"];
TheLogger.log("Debug","Parsing ${data.length} Home Assistant entities");
List<String> viewsList = [];
data.forEach((entity) {
try {
var composedEntity = _parseEntity(entity);
if (composedEntity["attributes"] != null) {
if ((composedEntity["domain"] == "group") &&
(composedEntity["attributes"]["view"] == true)) {
viewsList.add(composedEntity["entity_id"]);
}
}
_entitiesData[entity["entity_id"]] = composedEntity;
} catch (error) {
TheLogger.log("Error","Error parsing entity: ${entity['entity_id']}");
}
});
}
}

View File

@ -16,6 +16,8 @@ part 'data_provider.class.dart';
part 'log.page.dart';
part 'utils.class.dart';
part 'mdi.class.dart';
part 'entity.class.dart';
part 'entity_collection.class.dart';
EventBus eventBus = new EventBus();
const String appName = "HA Client";