Resolves #254 Missed entities
This commit is contained in:
parent
0ef2ebfe31
commit
a08a056cff
@ -67,6 +67,7 @@ class Entity {
|
|||||||
String state;
|
String state;
|
||||||
String displayState;
|
String displayState;
|
||||||
DateTime _lastUpdated;
|
DateTime _lastUpdated;
|
||||||
|
bool missed = false;
|
||||||
|
|
||||||
List<Entity> childEntities = [];
|
List<Entity> childEntities = [];
|
||||||
List<String> attributesToShow = ["all"];
|
List<String> attributesToShow = ["all"];
|
||||||
@ -97,6 +98,12 @@ class Entity {
|
|||||||
update(rawData);
|
update(rawData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Entity.missed(String entityId) {
|
||||||
|
missed = true;
|
||||||
|
attributes = {"hidden": false};
|
||||||
|
this.entityId = entityId;
|
||||||
|
}
|
||||||
|
|
||||||
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];
|
||||||
|
@ -14,10 +14,12 @@ class EntityWrapper {
|
|||||||
String displayName,
|
String displayName,
|
||||||
this.uiAction
|
this.uiAction
|
||||||
}) {
|
}) {
|
||||||
this.icon = icon ?? entity.icon;
|
if (!entity.missed) {
|
||||||
this.displayName = displayName ?? entity.displayName;
|
this.icon = icon ?? entity.icon;
|
||||||
if (this.uiAction == null) {
|
this.displayName = displayName ?? entity.displayName;
|
||||||
this.uiAction = EntityUIAction();
|
if (uiAction == null) {
|
||||||
|
uiAction = EntityUIAction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,27 +9,30 @@ class ButtonEntityContainer extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
|
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
|
||||||
|
if (entityWrapper.entity.missed) {
|
||||||
return InkWell(
|
return MissedEntityWidget();
|
||||||
onTap: () => entityWrapper.handleTap(),
|
} else {
|
||||||
onLongPress: () => entityWrapper.handleHold(),
|
return InkWell(
|
||||||
child: Column(
|
onTap: () => entityWrapper.handleTap(),
|
||||||
mainAxisSize: MainAxisSize.min,
|
onLongPress: () => entityWrapper.handleHold(),
|
||||||
children: <Widget>[
|
child: Column(
|
||||||
FractionallySizedBox(
|
mainAxisSize: MainAxisSize.min,
|
||||||
widthFactor: 0.4,
|
children: <Widget>[
|
||||||
child: FittedBox(
|
FractionallySizedBox(
|
||||||
fit: BoxFit.fitHeight,
|
widthFactor: 0.4,
|
||||||
child: EntityIcon(
|
child: FittedBox(
|
||||||
padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0),
|
fit: BoxFit.fitHeight,
|
||||||
size: Sizes.iconSize,
|
child: EntityIcon(
|
||||||
)
|
padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0),
|
||||||
|
size: Sizes.iconSize,
|
||||||
|
)
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
_buildName()
|
||||||
_buildName()
|
],
|
||||||
],
|
),
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildName() {
|
Widget _buildName() {
|
||||||
|
@ -11,32 +11,36 @@ class DefaultEntityContainer extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final EntityModel entityModel = EntityModel.of(context);
|
final EntityModel entityModel = EntityModel.of(context);
|
||||||
return InkWell(
|
if (entityModel.entityWrapper.entity.missed) {
|
||||||
onLongPress: () {
|
return MissedEntityWidget();
|
||||||
if (entityModel.handleTap) {
|
} else {
|
||||||
entityModel.entityWrapper.handleHold();
|
return InkWell(
|
||||||
}
|
onLongPress: () {
|
||||||
},
|
if (entityModel.handleTap) {
|
||||||
onTap: () {
|
entityModel.entityWrapper.handleHold();
|
||||||
if (entityModel.handleTap) {
|
}
|
||||||
entityModel.entityWrapper.handleTap();
|
},
|
||||||
}
|
onTap: () {
|
||||||
},
|
if (entityModel.handleTap) {
|
||||||
child: Row(
|
entityModel.entityWrapper.handleTap();
|
||||||
mainAxisSize: MainAxisSize.max,
|
}
|
||||||
children: <Widget>[
|
},
|
||||||
EntityIcon(),
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
children: <Widget>[
|
||||||
|
EntityIcon(),
|
||||||
|
|
||||||
Flexible(
|
Flexible(
|
||||||
fit: FlexFit.tight,
|
fit: FlexFit.tight,
|
||||||
flex: 3,
|
flex: 3,
|
||||||
child: EntityName(
|
child: EntityName(
|
||||||
padding: EdgeInsets.fromLTRB(10.0, 2.0, 10.0, 2.0),
|
padding: EdgeInsets.fromLTRB(10.0, 2.0, 10.0, 2.0),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
state
|
||||||
state
|
],
|
||||||
],
|
),
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,6 +22,9 @@ class GlanceEntityContainer extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
|
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
|
||||||
|
if (entityWrapper.entity.missed) {
|
||||||
|
return MissedEntityWidget();
|
||||||
|
}
|
||||||
List<Widget> result = [];
|
List<Widget> result = [];
|
||||||
if (!nameInTheBottom) {
|
if (!nameInTheBottom) {
|
||||||
if (showName) {
|
if (showName) {
|
||||||
|
19
lib/entity_widgets/missed_entity.dart
Normal file
19
lib/entity_widgets/missed_entity.dart
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
part of '../main.dart';
|
||||||
|
|
||||||
|
class MissedEntityWidget extends StatelessWidget {
|
||||||
|
MissedEntityWidget({
|
||||||
|
Key key
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final EntityModel entityModel = EntityModel.of(context);
|
||||||
|
return Container(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(5.0),
|
||||||
|
child: Text("Entity not available: ${entityModel.entityWrapper.entity.entityId}"),
|
||||||
|
),
|
||||||
|
color: Colors.amber[100],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -401,6 +401,8 @@ class HomeAssistant {
|
|||||||
if (rawEntity is String) {
|
if (rawEntity is String) {
|
||||||
if (entities.isExist(rawEntity)) {
|
if (entities.isExist(rawEntity)) {
|
||||||
card.entities.add(EntityWrapper(entity: entities.get(rawEntity)));
|
card.entities.add(EntityWrapper(entity: entities.get(rawEntity)));
|
||||||
|
} else {
|
||||||
|
card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (entities.isExist(rawEntity["entity"])) {
|
if (entities.isExist(rawEntity["entity"])) {
|
||||||
@ -413,6 +415,8 @@ class HomeAssistant {
|
|||||||
uiAction: EntityUIAction(rawEntityData: rawEntity)
|
uiAction: EntityUIAction(rawEntityData: rawEntity)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
card.entities.add(EntityWrapper(entity: Entity.missed(rawEntity["entity"])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -427,6 +431,8 @@ class HomeAssistant {
|
|||||||
displayName: rawCard["name"],
|
displayName: rawCard["name"],
|
||||||
uiAction: EntityUIAction(rawEntityData: rawCard)
|
uiAction: EntityUIAction(rawEntityData: rawCard)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
card.linkedEntityWrapper = EntityWrapper(entity: Entity.missed(en));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (entities.isExist(en["entity"])) {
|
if (entities.isExist(en["entity"])) {
|
||||||
@ -437,6 +443,8 @@ class HomeAssistant {
|
|||||||
displayName: en["name"],
|
displayName: en["name"],
|
||||||
uiAction: EntityUIAction(rawEntityData: rawCard)
|
uiAction: EntityUIAction(rawEntityData: rawCard)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
card.linkedEntityWrapper = EntityWrapper(entity: Entity.missed(en["entity"]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ part 'entity_class/alarm_control_panel.class.dart';
|
|||||||
part 'entity_widgets/common/badge.dart';
|
part 'entity_widgets/common/badge.dart';
|
||||||
part 'entity_widgets/model_widgets.dart';
|
part 'entity_widgets/model_widgets.dart';
|
||||||
part 'entity_widgets/default_entity_container.dart';
|
part 'entity_widgets/default_entity_container.dart';
|
||||||
|
part 'entity_widgets/missed_entity.dart';
|
||||||
part 'entity_widgets/glance_entity_container.dart';
|
part 'entity_widgets/glance_entity_container.dart';
|
||||||
part 'entity_widgets/button_entity_container.dart';
|
part 'entity_widgets/button_entity_container.dart';
|
||||||
part 'entity_widgets/common/entity_attributes_list.dart';
|
part 'entity_widgets/common/entity_attributes_list.dart';
|
||||||
|
@ -11,8 +11,17 @@ class CardWidget extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if ((card.linkedEntityWrapper!= null) && (card.linkedEntityWrapper.entity.isHidden)) {
|
if (card.linkedEntityWrapper!= null) {
|
||||||
return Container(width: 0.0, height: 0.0,);
|
if (card.linkedEntityWrapper.entity.isHidden) {
|
||||||
|
return Container(width: 0.0, height: 0.0,);
|
||||||
|
}
|
||||||
|
if (card.linkedEntityWrapper.entity.missed) {
|
||||||
|
return EntityModel(
|
||||||
|
entityWrapper: card.linkedEntityWrapper,
|
||||||
|
child: MissedEntityWidget(),
|
||||||
|
handleTap: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (card.type) {
|
switch (card.type) {
|
||||||
@ -133,18 +142,15 @@ class CardWidget extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildAlarmPanelCard(BuildContext context) {
|
Widget _buildAlarmPanelCard(BuildContext context) {
|
||||||
if (card.linkedEntityWrapper == null || card.linkedEntityWrapper.entity == null) {
|
List<Widget> body = [];
|
||||||
return Container(width: 0, height: 0,);
|
body.add(CardHeaderWidget(
|
||||||
} else {
|
name: card.name ?? "",
|
||||||
List<Widget> body = [];
|
subtitle: Text("${card.linkedEntityWrapper.entity.displayState}",
|
||||||
body.add(CardHeaderWidget(
|
style: TextStyle(
|
||||||
name: card.name ?? "",
|
|
||||||
subtitle: Text("${card.linkedEntityWrapper.entity.displayState}",
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.grey
|
color: Colors.grey
|
||||||
),
|
|
||||||
),
|
),
|
||||||
trailing: Row(
|
),
|
||||||
|
trailing: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
children: [
|
children: [
|
||||||
@ -152,36 +158,35 @@ class CardWidget extends StatelessWidget {
|
|||||||
size: 50.0,
|
size: 50.0,
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
width: 26.0,
|
width: 26.0,
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
padding: EdgeInsets.all(0.0),
|
padding: EdgeInsets.all(0.0),
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
icon: Icon(MaterialDesignIcons.getIconDataFromIconName(
|
icon: Icon(MaterialDesignIcons.getIconDataFromIconName(
|
||||||
"mdi:dots-vertical")),
|
"mdi:dots-vertical")),
|
||||||
onPressed: () => eventBus.fire(new ShowEntityPageEvent(card.linkedEntityWrapper.entity))
|
onPressed: () => eventBus.fire(new ShowEntityPageEvent(card.linkedEntityWrapper.entity))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
body.add(
|
body.add(
|
||||||
AlarmControlPanelControlsWidget(
|
AlarmControlPanelControlsWidget(
|
||||||
extended: true,
|
extended: true,
|
||||||
states: card.states,
|
states: card.states,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return Card(
|
return Card(
|
||||||
child: EntityModel(
|
child: EntityModel(
|
||||||
entityWrapper: card.linkedEntityWrapper,
|
entityWrapper: card.linkedEntityWrapper,
|
||||||
handleTap: null,
|
handleTap: null,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: body
|
children: body
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildGlanceCard(BuildContext context) {
|
Widget _buildGlanceCard(BuildContext context) {
|
||||||
@ -227,33 +232,25 @@ class CardWidget extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildMediaControlsCard(BuildContext context) {
|
Widget _buildMediaControlsCard(BuildContext context) {
|
||||||
if (card.linkedEntityWrapper == null || card.linkedEntityWrapper.entity == null) {
|
return Card(
|
||||||
return Container(width: 0, height: 0,);
|
child: EntityModel(
|
||||||
} else {
|
entityWrapper: card.linkedEntityWrapper,
|
||||||
return Card(
|
handleTap: null,
|
||||||
child: EntityModel(
|
child: MediaPlayerWidget()
|
||||||
entityWrapper: card.linkedEntityWrapper,
|
)
|
||||||
handleTap: null,
|
);
|
||||||
child: MediaPlayerWidget()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEntityButtonCard(BuildContext context) {
|
Widget _buildEntityButtonCard(BuildContext context) {
|
||||||
if (card.linkedEntityWrapper == null || card.linkedEntityWrapper.entity == null) {
|
card.linkedEntityWrapper.displayName = card.name?.toUpperCase() ??
|
||||||
return Container(width: 0, height: 0,);
|
card.linkedEntityWrapper.displayName.toUpperCase();
|
||||||
} else {
|
return Card(
|
||||||
card.linkedEntityWrapper.displayName = card.name?.toUpperCase() ??
|
child: EntityModel(
|
||||||
card.linkedEntityWrapper.displayName.toUpperCase();
|
entityWrapper: card.linkedEntityWrapper,
|
||||||
return Card(
|
child: ButtonEntityContainer(),
|
||||||
child: EntityModel(
|
handleTap: true
|
||||||
entityWrapper: card.linkedEntityWrapper,
|
)
|
||||||
child: ButtonEntityContainer(),
|
);
|
||||||
handleTap: true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildUnsupportedCard(BuildContext context) {
|
Widget _buildUnsupportedCard(BuildContext context) {
|
||||||
|
Reference in New Issue
Block a user