Fix: entity pictures are circular again

This commit is contained in:
Paulus Schoutsen 2016-02-07 11:31:41 -08:00
parent 4d3c0e6a4c
commit de22de9a08
5 changed files with 43 additions and 40 deletions

View File

@ -30,9 +30,7 @@ export default new Polymer({
this.async(() => moreInfoActions.selectEntity(this.state.entityId), 1); this.async(() => moreInfoActions.selectEntity(this.state.entityId), 1);
return; return;
} }
if (this.state.domain === 'scene') { if (this.state.domain === 'scene' || this.state.state === 'off') {
serviceActions.callTurnOn(this.state.entityId);
} else if (this.state.state === 'off') {
serviceActions.callTurnOn(this.state.entityId); serviceActions.callTurnOn(this.state.entityId);
} else { } else {
serviceActions.callTurnOff(this.state.entityId); serviceActions.callTurnOff(this.state.entityId);
@ -62,7 +60,7 @@ export default new Polymer({
case 'scene': case 'scene':
case 'script': case 'script':
case 'alarm_control_panel': case 'alarm_control_panel':
return undefined; return null;
case 'sensor': case 'sensor':
default: default:
return state.state === 'unknown' ? '-' : state.state; return state.state === 'unknown' ? '-' : state.state;
@ -91,12 +89,12 @@ export default new Polymer({
return state.state === 'above_horizon' ? return state.state === 'above_horizon' ?
domainIcon(state.domain) : 'mdi:brightness-3'; domainIcon(state.domain) : 'mdi:brightness-3';
default: default:
return undefined; return null;
} }
}, },
computeImage(state) { computeImage(state) {
return state.attributes.entity_picture; return state.attributes.entity_picture || null;
}, },
computeLabel(state) { computeLabel(state) {
@ -115,7 +113,7 @@ export default new Polymer({
// state == 'disarmed' // state == 'disarmed'
return 'disarm'; return 'disarm';
default: default:
return state.attributes.unit_of_measurement; return state.attributes.unit_of_measurement || null;
} }
}, },

View File

@ -1,5 +1,4 @@
<link rel='import' href='../../../bower_components/polymer/polymer.html'> <link rel='import' href='../../../bower_components/polymer/polymer.html'>
<link rel='import' href='../../../bower_components/iron-image/iron-image.html'>
<link rel='import' href='./ha-state-icon.html'> <link rel='import' href='./ha-state-icon.html'>
@ -9,23 +8,15 @@
position: relative; position: relative;
display: inline-block; display: inline-block;
width: 40px; width: 40px;
/*background-color: #4fc3f7;*/
color: #44739E; color: #44739E;
border-radius: 50%; border-radius: 50%;
}
.badge {
height: 40px; height: 40px;
text-align: center; text-align: center;
} background-size: cover;
line-height: 40px;
iron-image {
border-radius: 50%;
background-color: #FFFFFF;
} }
ha-state-icon { ha-state-icon {
margin: 0 auto;
transition: color .3s ease-in-out; transition: color .3s ease-in-out;
} }
@ -39,15 +30,8 @@
</style> </style>
<template> <template>
<div class='layout horizontal center badge'> <ha-state-icon id='icon' state-obj='[[stateObj]]'
<ha-state-icon id='icon' state-obj='[[stateObj]]' data-domain$='[[stateObj.domain]]' data-state$='[[stateObj.state]]'>
data-domain$='[[stateObj.domain]]' data-state$='[[stateObj.state]]'> </ha-state-icon>
</ha-state-icon>
<template is='dom-if' if='[[stateObj.attributes.entity_picture]]'>
<iron-image
sizing='cover' class='fit'
src$="[[stateObj.attributes.entity_picture]]"></iron-image>
</template>
</div>
</template> </template>
</dom-module> </dom-module>

View File

@ -16,6 +16,16 @@ export default new Polymer({
* Called when an attribute changes that influences the color of the icon. * Called when an attribute changes that influences the color of the icon.
*/ */
updateIconColor(newVal) { updateIconColor(newVal) {
// hide icon if we have entity picture
if (newVal.attributes.entity_picture) {
this.style.backgroundImage = `url(${newVal.attributes.entity_picture})`;
this.$.icon.style.display = 'none';
return;
}
this.style.backgroundImage = '';
this.$.icon.style.display = 'inline';
// for domain light, set color of icon to light color if available and it is // for domain light, set color of icon to light color if available and it is
// not very white (sum rgb colors < 730) // not very white (sum rgb colors < 730)
if (newVal.domain === 'light' && newVal.state === 'on' && if (newVal.domain === 'light' && newVal.state === 'on' &&

View File

@ -1,5 +1,4 @@
<link rel='import' href='../../bower_components/polymer/polymer.html'> <link rel='import' href='../../bower_components/polymer/polymer.html'>
<link rel='import' href='../../bower_components/iron-image/iron-image.html'>
<link rel='import' href='../../bower_components/iron-icon/iron-icon.html'> <link rel='import' href='../../bower_components/iron-icon/iron-icon.html'>
<dom-module id='ha-label-badge'> <dom-module id='ha-label-badge'>
@ -25,6 +24,7 @@
white-space: nowrap; white-space: nowrap;
background-color: white; background-color: white;
background-size: cover;
transition: border .3s ease-in-out; transition: border .3s ease-in-out;
} }
.label-badge .value { .label-badge .value {
@ -74,17 +74,10 @@
<div class='badge-container'> <div class='badge-container'>
<div class='label-badge' id='badge'> <div class='label-badge' id='badge'>
<div class$='[[computeClasses(value)]]'> <div class$='[[computeClasses(value)]]'>
<template is='dom-if' if='[[icon]]'> <iron-icon icon='[[icon]]' hidden$='[[computeHideIcon(icon, value, image)]]'></iron-icon>
<iron-icon icon='[[icon]]'></iron-icon> <span hidden$='[[computeHideValue(value, image)]]'>[[value]]</span>
</template>
<template is='dom-if' if='[[value]]'>[[value]]</template>
<template is='dom-if' if='[[image]]'>
<iron-image sizing='cover' class='fit'src='[[image]]'></iron-image>
</template>
</div> </div>
<template is='dom-if' if='[[label]]'> <div class='label' hidden$='[[!label]]'><span>[[label]]</span></div>
<div class='label'><span>[[label]]</span></div>
</template>
</div> </div>
<div class='title'>[[description]]</div> <div class='title'>[[description]]</div>
</div> </div>

View File

@ -1,19 +1,24 @@
import Polymer from '../polymer'; import Polymer from '../polymer';
// Beware: Polymer will not call computeHideIcon and computeHideValue if any of
// the parameters are undefined. Set to null if not using.
export default new Polymer({ export default new Polymer({
is: 'ha-label-badge', is: 'ha-label-badge',
properties: { properties: {
value: { value: {
type: String, type: String,
value: null,
}, },
icon: { icon: {
type: String, type: String,
value: null,
}, },
label: { label: {
type: String, type: String,
value: null,
}, },
description: { description: {
@ -22,11 +27,24 @@ export default new Polymer({
image: { image: {
type: String, type: String,
observe: 'imageChanged', value: null,
observer: 'imageChanged',
}, },
}, },
computeClasses(value) { computeClasses(value) {
return value && value.length > 4 ? 'value big' : 'value'; return value && value.length > 4 ? 'value big' : 'value';
}, },
computeHideIcon(icon, value, image) {
return !icon || value || image;
},
computeHideValue(value, image) {
return !value || image;
},
imageChanged(newVal) {
this.$.badge.style.backgroundImage = newVal ? `url(${newVal})` : '';
},
}); });