diff --git a/lib/entity.class.dart b/lib/entity.class.dart new file mode 100644 index 0000000..ea13157 --- /dev/null +++ b/lib/entity.class.dart @@ -0,0 +1,9 @@ +part of 'main.dart'; + +class Entity { + + Entity() { + // + } + +} \ No newline at end of file diff --git a/lib/entity_collection.class.dart b/lib/entity_collection.class.dart new file mode 100644 index 0000000..ee904c3 --- /dev/null +++ b/lib/entity_collection.class.dart @@ -0,0 +1,37 @@ +part of 'main.dart'; + +class EntityCollection { + + Map _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 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']}"); + } + }); + } + +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index ca0792d..f158c5f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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";