Massive refactoring: HomeAssistant, EntityCollection, Entity
This commit is contained in:
@ -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"];
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user