[#32] Use entity picture instead of icon if exist

This commit is contained in:
estevez
2018-09-23 02:04:44 +03:00
parent 1133a996b9
commit cc0278ee55
5 changed files with 86 additions and 23 deletions

View File

@ -3211,15 +3211,37 @@ class MaterialDesignIcons {
"mdi:blank": 0xf68c
};
static IconData createIconDataFromEntityData(Map data) {
String iconName = data["attributes"] != null ? data["attributes"]["icon"] : null;
int iconCode = 0;
if (iconName != null) {
iconCode = getIconCodeByIconName(iconName);
static Widget createIconFromEntityData(Map data, double size, Color color) {
if ((data["attributes"] != null) && (data["attributes"]["entity_picture"] != null)) {
if (homeAssistantWebHost != null) {
return CircleAvatar(
backgroundColor: Colors.white,
backgroundImage: CachedNetworkImageProvider(
"$homeAssistantWebHost${data["attributes"]["entity_picture"]}",
),
);
} else {
return Container(width: 0.0, height: 0.0);
}
} else {
iconCode = getDefaultIconByEntityId(data["entity_id"], data["attributes"] != null ? data["attributes"]["device_class"] : null, data["state"]); //
String iconName = data["attributes"] != null
? data["attributes"]["icon"]
: null;
int iconCode = 0;
if (iconName != null) {
iconCode = getIconCodeByIconName(iconName);
} else {
iconCode = getDefaultIconByEntityId(data["entity_id"],
data["attributes"] != null
? data["attributes"]["device_class"]
: null, data["state"]); //
}
return Icon(
IconData(iconCode, fontFamily: 'Material Design Icons'),
size: size,
color: color,
);
}
return IconData(iconCode, fontFamily: 'Material Design Icons');
}
static IconData createIconDataFromIconCode(int code) {