Resolves #107 Show entity attributes
This commit is contained in:
parent
ce69f044fb
commit
a4ac40b366
@ -1,14 +1,14 @@
|
|||||||
part of '../main.dart';
|
part of '../main.dart';
|
||||||
|
|
||||||
class _DateTimeEntityWidgetState extends _EntityWidgetState {
|
class _DateTimeEntityWidgetState extends _EntityWidgetState {
|
||||||
bool get hasDate => widget.entity._attributes["has_date"] ?? false;
|
bool get hasDate => widget.entity.attributes["has_date"] ?? false;
|
||||||
bool get hasTime => widget.entity._attributes["has_time"] ?? false;
|
bool get hasTime => widget.entity.attributes["has_time"] ?? false;
|
||||||
int get year => widget.entity._attributes["year"] ?? 1970;
|
int get year => widget.entity.attributes["year"] ?? 1970;
|
||||||
int get month => widget.entity._attributes["month"] ?? 1;
|
int get month => widget.entity.attributes["month"] ?? 1;
|
||||||
int get day => widget.entity._attributes["day"] ?? 1;
|
int get day => widget.entity.attributes["day"] ?? 1;
|
||||||
int get hour => widget.entity._attributes["hour"] ?? 0;
|
int get hour => widget.entity.attributes["hour"] ?? 0;
|
||||||
int get minute => widget.entity._attributes["minute"] ?? 0;
|
int get minute => widget.entity.attributes["minute"] ?? 0;
|
||||||
int get second => widget.entity._attributes["second"] ?? 0;
|
int get second => widget.entity.attributes["second"] ?? 0;
|
||||||
String get formattedState => _getFormattedState();
|
String get formattedState => _getFormattedState();
|
||||||
DateTime get dateTimeState => _getDateTimeState();
|
DateTime get dateTimeState => _getDateTimeState();
|
||||||
|
|
||||||
|
@ -22,8 +22,9 @@ class Entity {
|
|||||||
static const NAME_FONT_SIZE = 16.0;
|
static const NAME_FONT_SIZE = 16.0;
|
||||||
static const SMALL_FONT_SIZE = 14.0;
|
static const SMALL_FONT_SIZE = 14.0;
|
||||||
static const INPUT_WIDTH = 160.0;
|
static const INPUT_WIDTH = 160.0;
|
||||||
|
static const ROW_PADDING = 10.0;
|
||||||
|
|
||||||
Map _attributes;
|
Map attributes;
|
||||||
String _domain;
|
String _domain;
|
||||||
String _entityId;
|
String _entityId;
|
||||||
String _state;
|
String _state;
|
||||||
@ -33,23 +34,23 @@ class Entity {
|
|||||||
List<Entity> childEntities = [];
|
List<Entity> childEntities = [];
|
||||||
|
|
||||||
String get displayName =>
|
String get displayName =>
|
||||||
_attributes["friendly_name"] ?? (_attributes["name"] ?? "_");
|
attributes["friendly_name"] ?? (attributes["name"] ?? "_");
|
||||||
String get domain => _domain;
|
String get domain => _domain;
|
||||||
String get entityId => _entityId;
|
String get entityId => _entityId;
|
||||||
String get state => _state;
|
String get state => _state;
|
||||||
set state(value) => _state = value;
|
set state(value) => _state = value;
|
||||||
|
|
||||||
String get deviceClass => _attributes["device_class"] ?? null;
|
String get deviceClass => attributes["device_class"] ?? null;
|
||||||
bool get isView =>
|
bool get isView =>
|
||||||
(_domain == "group") &&
|
(_domain == "group") &&
|
||||||
(_attributes != null ? _attributes["view"] ?? false : false);
|
(attributes != null ? attributes["view"] ?? false : false);
|
||||||
bool get isGroup => _domain == "group";
|
bool get isGroup => _domain == "group";
|
||||||
bool get isBadge => Entity.badgeDomains.contains(_domain);
|
bool get isBadge => Entity.badgeDomains.contains(_domain);
|
||||||
String get icon => _attributes["icon"] ?? "";
|
String get icon => attributes["icon"] ?? "";
|
||||||
bool get isOn => state == "on";
|
bool get isOn => state == "on";
|
||||||
String get entityPicture => _attributes["entity_picture"];
|
String get entityPicture => attributes["entity_picture"];
|
||||||
String get unitOfMeasurement => _attributes["unit_of_measurement"] ?? "";
|
String get unitOfMeasurement => attributes["unit_of_measurement"] ?? "";
|
||||||
List get childEntityIds => _attributes["entity_id"] ?? [];
|
List get childEntityIds => attributes["entity_id"] ?? [];
|
||||||
String get lastUpdated => _getLastUpdatedFormatted();
|
String get lastUpdated => _getLastUpdatedFormatted();
|
||||||
|
|
||||||
Entity(Map rawData) {
|
Entity(Map rawData) {
|
||||||
@ -57,7 +58,7 @@ class Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update(Map rawData) {
|
void update(Map rawData) {
|
||||||
_attributes = rawData["attributes"] ?? {};
|
attributes = rawData["attributes"] ?? {};
|
||||||
_domain = rawData["entity_id"].split(".")[0];
|
_domain = rawData["entity_id"].split(".")[0];
|
||||||
_entityId = rawData["entity_id"];
|
_entityId = rawData["entity_id"];
|
||||||
_state = rawData["state"];
|
_state = rawData["state"];
|
||||||
@ -72,6 +73,13 @@ class Entity {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getAttribute(String attributeName) {
|
||||||
|
if (attributes != null) {
|
||||||
|
return attributes["$attributeName"];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String _getLastUpdatedFormatted() {
|
String _getLastUpdatedFormatted() {
|
||||||
if (_lastUpdated == null) {
|
if (_lastUpdated == null) {
|
||||||
return "-";
|
return "-";
|
||||||
@ -119,6 +127,9 @@ class EntityWidget extends StatefulWidget {
|
|||||||
@override
|
@override
|
||||||
_EntityWidgetState createState() {
|
_EntityWidgetState createState() {
|
||||||
switch (entity.domain) {
|
switch (entity.domain) {
|
||||||
|
case 'sun': {
|
||||||
|
return _SunEntityWidgetState();
|
||||||
|
}
|
||||||
case "automation":
|
case "automation":
|
||||||
case "input_boolean":
|
case "input_boolean":
|
||||||
case "switch":
|
case "switch":
|
||||||
@ -156,6 +167,8 @@ class EntityWidget extends StatefulWidget {
|
|||||||
|
|
||||||
class _EntityWidgetState extends State<EntityWidget> {
|
class _EntityWidgetState extends State<EntityWidget> {
|
||||||
|
|
||||||
|
List<String> attributesToShow = ["all"];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (widget.widgetType == EntityWidgetType.regular) {
|
if (widget.widgetType == EntityWidgetType.regular) {
|
||||||
@ -174,7 +187,8 @@ class _EntityWidgetState extends State<EntityWidget> {
|
|||||||
return ListView(
|
return ListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
_buildMainWidget(context),
|
_buildMainWidget(context),
|
||||||
_buildSecondRowWidget()
|
_buildSecondRowWidget(),
|
||||||
|
_buildAttributesWidget()
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -200,6 +214,56 @@ class _EntityWidgetState extends State<EntityWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildAttributesWidget() {
|
||||||
|
List<Widget> attrs = [];
|
||||||
|
if (attributesToShow.contains("all")) {
|
||||||
|
widget.entity.attributes.forEach((name, value){
|
||||||
|
attrs.add(
|
||||||
|
_buildAttributeWidget("$name", "$value")
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
attributesToShow.forEach((String attr) {
|
||||||
|
String attrValue = widget.entity.getAttribute("$attr");
|
||||||
|
if (attrValue != null) {
|
||||||
|
attrs.add(
|
||||||
|
_buildAttributeWidget("$attr", "$attrValue")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
children: attrs,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildAttributeWidget(String name, String value) {
|
||||||
|
return Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(Entity.LEFT_WIDGET_PADDING, Entity.ROW_PADDING, 0.0, 0.0),
|
||||||
|
child: Text(
|
||||||
|
"$name",
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(0.0, Entity.ROW_PADDING, Entity.RIGHT_WIDGET_PADDING, 0.0),
|
||||||
|
child: Text(
|
||||||
|
"$value",
|
||||||
|
textAlign: TextAlign.right,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void openEntityPage() {
|
void openEntityPage() {
|
||||||
eventBus.fire(new ShowEntityPageEvent(widget.entity));
|
eventBus.fire(new ShowEntityPageEvent(widget.entity));
|
||||||
}
|
}
|
||||||
@ -208,9 +272,9 @@ class _EntityWidgetState extends State<EntityWidget> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildAdditionalWidget() {
|
/*Widget buildAdditionalWidget() {
|
||||||
return _buildSecondRowWidget();
|
return _buildSecondRowWidget();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
Widget _buildIconWidget() {
|
Widget _buildIconWidget() {
|
||||||
return Padding(
|
return Padding(
|
||||||
@ -320,56 +384,59 @@ class _EntityWidgetState extends State<EntityWidget> {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Column(
|
return GestureDetector(
|
||||||
children: <Widget>[
|
child: Column(
|
||||||
Container(
|
children: <Widget>[
|
||||||
margin: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
|
Container(
|
||||||
width: 50.0,
|
margin: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
|
||||||
height: 50.0,
|
width: 50.0,
|
||||||
decoration: new BoxDecoration(
|
height: 50.0,
|
||||||
// Circle shape
|
decoration: new BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
// Circle shape
|
||||||
color: Colors.white,
|
shape: BoxShape.circle,
|
||||||
// The border you want
|
color: Colors.white,
|
||||||
border: new Border.all(
|
// The border you want
|
||||||
width: 2.0,
|
border: new Border.all(
|
||||||
color: iconColor,
|
width: 2.0,
|
||||||
|
color: iconColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Stack(
|
||||||
|
overflow: Overflow.visible,
|
||||||
|
children: <Widget>[
|
||||||
|
Positioned(
|
||||||
|
width: 46.0,
|
||||||
|
height: 46.0,
|
||||||
|
top: 0.0,
|
||||||
|
left: 0.0,
|
||||||
|
child: badgeIcon,
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
//width: 50.0,
|
||||||
|
bottom: -9.0,
|
||||||
|
left: -10.0,
|
||||||
|
right: -10.0,
|
||||||
|
child: Center(
|
||||||
|
child: onBadgeText,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Stack(
|
Container(
|
||||||
overflow: Overflow.visible,
|
width: 60.0,
|
||||||
children: <Widget>[
|
child: Text(
|
||||||
Positioned(
|
"${widget.entity.displayName}",
|
||||||
width: 46.0,
|
textAlign: TextAlign.center,
|
||||||
height: 46.0,
|
style: TextStyle(fontSize: 12.0),
|
||||||
top: 0.0,
|
softWrap: true,
|
||||||
left: 0.0,
|
maxLines: 3,
|
||||||
child: badgeIcon,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
Positioned(
|
|
||||||
//width: 50.0,
|
|
||||||
bottom: -9.0,
|
|
||||||
left: -10.0,
|
|
||||||
right: -10.0,
|
|
||||||
child: Center(
|
|
||||||
child: onBadgeText,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
Container(
|
),
|
||||||
width: 60.0,
|
onTap: openEntityPage,
|
||||||
child: Text(
|
|
||||||
"${widget.entity.displayName}",
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(fontSize: 12.0),
|
|
||||||
softWrap: true,
|
|
||||||
maxLines: 3,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ class _SelectEntityWidgetState extends _EntityWidgetState {
|
|||||||
@override
|
@override
|
||||||
Widget _buildActionWidget(BuildContext context) {
|
Widget _buildActionWidget(BuildContext context) {
|
||||||
_listOptions.clear();
|
_listOptions.clear();
|
||||||
if (widget.entity._attributes["options"] != null) {
|
if (widget.entity.attributes["options"] != null) {
|
||||||
widget.entity._attributes["options"].forEach((value){
|
widget.entity.attributes["options"].forEach((value){
|
||||||
_listOptions.add(value.toString());
|
_listOptions.add(value.toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ part of '../main.dart';
|
|||||||
class _SliderEntityWidgetState extends _EntityWidgetState {
|
class _SliderEntityWidgetState extends _EntityWidgetState {
|
||||||
int _multiplier = 1;
|
int _multiplier = 1;
|
||||||
|
|
||||||
double get minValue => widget.entity._attributes["min"] ?? 0.0;
|
double get minValue => widget.entity.attributes["min"] ?? 0.0;
|
||||||
double get maxValue => widget.entity._attributes["max"] ?? 100.0;
|
double get maxValue => widget.entity.attributes["max"] ?? 100.0;
|
||||||
double get valueStep => widget.entity._attributes["step"] ?? 1.0;
|
double get valueStep => widget.entity.attributes["step"] ?? 1.0;
|
||||||
double get doubleState => double.tryParse(widget.entity.state) ?? 0.0;
|
double get doubleState => double.tryParse(widget.entity.state) ?? 0.0;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
8
lib/entity_class/sun_entity.class.dart
Normal file
8
lib/entity_class/sun_entity.class.dart
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
part of '../main.dart';
|
||||||
|
|
||||||
|
class _SunEntityWidgetState extends _EntityWidgetState {
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<String> attributesToShow = ["all"];
|
||||||
|
|
||||||
|
}
|
@ -5,11 +5,11 @@ class _TextEntityWidgetState extends _EntityWidgetState {
|
|||||||
FocusNode _focusNode = FocusNode();
|
FocusNode _focusNode = FocusNode();
|
||||||
bool validValue = false;
|
bool validValue = false;
|
||||||
|
|
||||||
int get valueMinLength => widget.entity._attributes["min"] ?? -1;
|
int get valueMinLength => widget.entity.attributes["min"] ?? -1;
|
||||||
int get valueMaxLength => widget.entity._attributes["max"] ?? -1;
|
int get valueMaxLength => widget.entity.attributes["max"] ?? -1;
|
||||||
String get valuePattern => widget.entity._attributes["pattern"] ?? null;
|
String get valuePattern => widget.entity.attributes["pattern"] ?? null;
|
||||||
bool get isTextField => widget.entity._attributes["mode"] == "text";
|
bool get isTextField => widget.entity.attributes["mode"] == "text";
|
||||||
bool get isPasswordField => widget.entity._attributes["mode"] == "password";
|
bool get isPasswordField => widget.entity.attributes["mode"] == "password";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -19,6 +19,7 @@ part 'entity_class/select_entity.class.dart';
|
|||||||
part 'entity_class/slider_entity.class.dart';
|
part 'entity_class/slider_entity.class.dart';
|
||||||
part 'entity_class/switch_entity.class.dart';
|
part 'entity_class/switch_entity.class.dart';
|
||||||
part 'entity_class/text_entity.class.dart';
|
part 'entity_class/text_entity.class.dart';
|
||||||
|
part 'entity_class/sun_entity.class.dart';
|
||||||
|
|
||||||
part 'settings.page.dart';
|
part 'settings.page.dart';
|
||||||
part 'home_assistant.class.dart';
|
part 'home_assistant.class.dart';
|
||||||
|
Reference in New Issue
Block a user