Hide empty 'Currently' on climate statecard (#1047)

* hide currently if no value

* zero is falsy. align items

* don't hide falsy values

* computed property instead of observer

* guard null/undefined
This commit is contained in:
NovapaX 2018-04-01 02:29:49 +02:00 committed by Paulus Schoutsen
parent 77330d03b3
commit d8fb01ab44

View File

@ -3,6 +3,12 @@
<dom-module id="ha-climate-state"> <dom-module id="ha-climate-state">
<template> <template>
<style> <style>
:host {
display: flex;
flex-direction: column;
justify-content: center;
}
.target { .target {
color: var(--primary-text-color); color: var(--primary-text-color);
} }
@ -24,10 +30,12 @@
[[computeTarget(stateObj)]] [[computeTarget(stateObj)]]
</div> </div>
<template is='dom-if' if='[[currentStatus]]'>
<div class='current'> <div class='current'>
Currently: [[computeCurrentStatus(stateObj)]] Currently: [[currentStatus]]
</div> </div>
</template> </template>
</template>
</dom-module> </dom-module>
<script> <script>
@ -37,17 +45,21 @@ class HaClimateState extends Polymer.Element {
static get properties() { static get properties() {
return { return {
stateObj: Object, stateObj: Object,
currentStatus: {
type: String,
computed: 'computeCurrentStatus(stateObj)',
},
}; };
} }
computeCurrentStatus(stateObj) { computeCurrentStatus(stateObj) {
if ('current_temperature' in stateObj.attributes) { if (stateObj.attributes.current_temperature != null) {
return `${stateObj.attributes.current_temperature} ${stateObj.attributes.unit_of_measurement}`; return `${stateObj.attributes.current_temperature} ${stateObj.attributes.unit_of_measurement}`;
} else if ('current_humidity' in stateObj.attributes) { }
if (stateObj.attributes.current_humidity != null) {
return `${stateObj.attributes.current_humidity} ${stateObj.attributes.unit_of_measurement}`; return `${stateObj.attributes.current_humidity} ${stateObj.attributes.unit_of_measurement}`;
} }
return null;
return '';
} }
computeTarget(stateObj) { computeTarget(stateObj) {