This commit is contained in:
estevez-dev
2019-03-06 16:50:30 +00:00
parent 146efef72d
commit 2cfa92a42b
3 changed files with 10 additions and 54 deletions

View File

@ -67,7 +67,6 @@ class Entity {
String state; String state;
String displayState; String displayState;
DateTime _lastUpdated; DateTime _lastUpdated;
String thumbnailBase64;
List<Entity> childEntities = []; List<Entity> childEntities = [];
List<String> attributesToShow = ["all"]; List<String> attributesToShow = ["all"];

View File

@ -1,19 +1,13 @@
part of '../main.dart'; part of '../main.dart';
class EntityIcon extends StatefulWidget { class EntityIcon extends StatelessWidget {
final EdgeInsetsGeometry padding; final EdgeInsetsGeometry padding;
final double size; final double size;
final Color color; final Color color;
EntityIcon({Key key, this.padding: const EdgeInsets.fromLTRB( const EntityIcon({Key key, this.color, this.size: Sizes.iconSize, this.padding: const EdgeInsets.fromLTRB(
Sizes.leftWidgetPadding, 0.0, 12.0, 0.0), this.size: Sizes.iconSize, this.color}) : super(key: key); Sizes.leftWidgetPadding, 0.0, 12.0, 0.0)}) : super(key: key);
@override
_EntityIconState createState() => _EntityIconState();
}
class _EntityIconState extends State<EntityIcon> {
int getDefaultIconByEntityId(String entityId, String deviceClass, String state) { int getDefaultIconByEntityId(String entityId, String deviceClass, String state) {
String domain = entityId.split(".")[0]; String domain = entityId.split(".")[0];
@ -30,24 +24,13 @@ class _EntityIconState extends State<EntityIcon> {
} }
} }
Widget buildIcon(HomeAssistantModel homeAssistantModel, EntityWrapper data, Color color) { Widget buildIcon(EntityWrapper data, Color color) {
if (data == null) { if (data == null) {
return Container(width: widget.size, height: widget.size,); return null;
} }
if ((data.entity.domain == "camera" || data.entity.domain == "media_player") && data.entity.thumbnailBase64 == null) { if (data.entity.entityPicture != null) {
homeAssistantModel.homeAssistant.updateEntityThumbnail(data.entity);
}
if (data.entity.thumbnailBase64 != null) {
return CircleAvatar( return CircleAvatar(
radius: widget.size/2, radius: size/2,
backgroundColor: Colors.white,
backgroundImage: MemoryImage(
Base64Codec().decode(data.entity.thumbnailBase64),
)
);
} else if (data.entity.entityPicture != null && data.entity.domain != "camera" && data.entity.domain != "media_player") {
return CircleAvatar(
radius: widget.size/2,
backgroundColor: Colors.white, backgroundColor: Colors.white,
backgroundImage: CachedNetworkImageProvider( backgroundImage: CachedNetworkImageProvider(
"$homeAssistantWebHost${data.entity.entityPicture}", "$homeAssistantWebHost${data.entity.entityPicture}",
@ -64,7 +47,7 @@ class _EntityIconState extends State<EntityIcon> {
} }
return Icon( return Icon(
IconData(iconCode, fontFamily: 'Material Design Icons'), IconData(iconCode, fontFamily: 'Material Design Icons'),
size: widget.size, size: size,
color: color, color: color,
); );
} }
@ -73,13 +56,11 @@ class _EntityIconState extends State<EntityIcon> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper; final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
final HomeAssistantModel homeAssistantModel = HomeAssistantModel.of(context);
return Padding( return Padding(
padding: widget.padding, padding: padding,
child: buildIcon( child: buildIcon(
homeAssistantModel,
entityWrapper, entityWrapper,
widget.color ?? EntityColor.stateColor(entityWrapper.entity.state) color ?? EntityColor.stateColor(entityWrapper.entity.state)
), ),
); );
} }

View File

@ -253,30 +253,6 @@ class HomeAssistant {
await _sendInitialMessage("get_services").then((data) => Logger.d("We actually don`t need the list of servcies for now")); await _sendInitialMessage("get_services").then((data) => Logger.d("We actually don`t need the list of servcies for now"));
} }
Future updateEntityThumbnail(Entity entity) async {
if (entity.thumbnailBase64 == null) {
_incrementMessageId();
_messageResolver[_currentMessageId] = Completer();
String type;
if (entity.domain == "camera") {
type = "camera_thumbnail";
} else if (entity.domain == "media_player") {
type = "media_player_thumbnail";
}
_send('{"id": $_currentMessageId, "type": "$type", "entity_id": "${entity.entityId}"}', false);
await _messageResolver[_currentMessageId].future.then((data){
if (data['success']) {
Logger.d("Got entity thumbnail for ${entity
.entityId}. Content-type: ${data['result']['content_type']}");
if (!data['result']['content_type'].contains('xml')) {
entity.thumbnailBase64 = data['result']['content'];
}
}
});
}
}
_incrementMessageId() { _incrementMessageId() {
_currentMessageId += 1; _currentMessageId += 1;
} }