[WIP] Entity collection
This commit is contained in:
parent
516d38a8a9
commit
0b42019ef3
9
lib/entity.class.dart
Normal file
9
lib/entity.class.dart
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
part of 'main.dart';
|
||||||
|
|
||||||
|
class Entity {
|
||||||
|
|
||||||
|
Entity() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
lib/entity_collection.class.dart
Normal file
37
lib/entity_collection.class.dart
Normal 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']}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -16,6 +16,8 @@ part 'data_provider.class.dart';
|
|||||||
part 'log.page.dart';
|
part 'log.page.dart';
|
||||||
part 'utils.class.dart';
|
part 'utils.class.dart';
|
||||||
part 'mdi.class.dart';
|
part 'mdi.class.dart';
|
||||||
|
part 'entity.class.dart';
|
||||||
|
part 'entity_collection.class.dart';
|
||||||
|
|
||||||
EventBus eventBus = new EventBus();
|
EventBus eventBus = new EventBus();
|
||||||
const String appName = "HA Client";
|
const String appName = "HA Client";
|
||||||
|
Reference in New Issue
Block a user