Massive refactoring: HomeAssistant, EntityCollection, Entity

This commit is contained in:
estevez
2018-09-27 14:51:57 +03:00
parent 0b42019ef3
commit 375ae36884
5 changed files with 207 additions and 197 deletions

View File

@ -1,9 +1,34 @@
part of 'main.dart';
class Entity {
Map _attributes;
String _domain;
String _entityId;
String _state;
String _entityPicture;
Entity() {
//
String get displayName => _attributes["friendly_name"] ?? (_attributes["name"] ?? "_");
String get domain => _domain;
String get entityId => _entityId;
String get state => _state;
String get deviceClass => _attributes["device_class"] ?? null;
bool get isView => (_domain == "group") && (_attributes != null ? _attributes["view"] ?? false : false);
bool get isGroup => _domain == "group";
String get icon => _attributes["icon"] ?? "";
bool get isOn => state == "on";
String get entityPicture => _attributes["entity_picture"];
String get unitOfMeasurement => _attributes["unit_of_measurement"] ?? "";
List get childEntities => _attributes["entity_id"] ?? [];
Entity(Map rawData) {
update(rawData);
}
void update(Map rawData) {
_attributes = rawData["attributes"] ?? {};
_domain = rawData["entity_id"].split(".")[0];
_entityId = rawData["entity_id"];
_state = rawData["state"];
}
}