Resolves #299, Resolves #234 Fix entity picture url issue

This commit is contained in:
estevez-dev 2019-03-13 17:48:49 +02:00
parent e1d2981782
commit 491ae55a2a
3 changed files with 16 additions and 11 deletions

View File

@ -95,7 +95,7 @@ class Entity {
bool get isBadge => Entity.badgeDomains.contains(domain);
String get icon => attributes["icon"] ?? "";
bool get isOn => state == EntityState.on;
String get entityPicture => attributes["entity_picture"];
String get entityPicture => _getEntityPictureUrl();
String get unitOfMeasurement => attributes["unit_of_measurement"] ?? "";
List get childEntityIds => attributes["entity_id"] ?? [];
String get lastUpdated => _getLastUpdatedFormatted();
@ -103,6 +103,19 @@ class Entity {
double get doubleState => double.tryParse(state) ?? 0.0;
int get supportedFeatures => attributes["supported_features"] ?? 0;
String _getEntityPictureUrl() {
String result = attributes["entity_picture"];
if (result == null) return result;
if (!result.startsWith("http")) {
if (result.startsWith("/")) {
result = "$homeAssistantWebHost$result";
} else {
result = "$homeAssistantWebHost/$result";
}
}
return result;
}
Entity(Map rawData) {
update(rawData);
}

View File

@ -81,7 +81,7 @@ class MediaPlayerWidget extends StatelessWidget {
children: <Widget>[
Flexible(
child: Image(
image: CachedNetworkImageProvider("$homeAssistantWebHost${entity.entityPicture}"),
image: CachedNetworkImageProvider("${entity.entityPicture}"),
height: 240.0,
//width: 320.0,
fit: BoxFit.contain,

View File

@ -36,19 +36,11 @@ class EntityIcon extends StatelessWidget {
image: DecorationImage(
fit:BoxFit.cover,
image: CachedNetworkImageProvider(
"$homeAssistantWebHost${data.entity.entityPicture}",
"${data.entity.entityPicture}",
),
)
),
);
return CircleAvatar(
radius: size/2+0,
backgroundColor: Colors.white,
backgroundImage: CachedNetworkImageProvider(
"$homeAssistantWebHost${data.entity.entityPicture}",
),
);
} else {
String iconName = data.icon;
int iconCode = 0;