Add precipitation to weather card (#1098) (#1221)

This commit is contained in:
c727 2018-05-29 03:29:52 +02:00 committed by GitHub
parent 21e4bc4ee4
commit 74e0779d38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -84,7 +84,8 @@ class HaWeatherCard extends
} }
.attributes, .attributes,
.templow { .templow,
.precipitation { {
color: var(--secondary-text-color); color: var(--secondary-text-color);
} }
</style> </style>
@ -100,19 +101,19 @@ class HaWeatherCard extends
</div> </div>
</div> </div>
<div class="attributes"> <div class="attributes">
<template is="dom-if" if="[[stateObj.attributes.pressure]]"> <template is="dom-if" if="[[_showValue(stateObj.attributes.pressure)]]">
<div> <div>
[[localize('ui.card.weather.attributes.air_pressure')]]: [[localize('ui.card.weather.attributes.air_pressure')]]:
[[stateObj.attributes.pressure]] hPa [[stateObj.attributes.pressure]] hPa
</div> </div>
</template> </template>
<template is="dom-if" if="[[stateObj.attributes.humidity]]"> <template is="dom-if" if="[[_showValue(stateObj.attributes.humidity)]]">
<div> <div>
[[localize('ui.card.weather.attributes.humidity')]]: [[localize('ui.card.weather.attributes.humidity')]]:
[[stateObj.attributes.humidity]] % [[stateObj.attributes.humidity]] %
</div> </div>
</template> </template>
<template is="dom-if" if="[[stateObj.attributes.humidity]]"> <template is="dom-if" if="[[_showValue(stateObj.attributes.humidity)]]">
<div> <div>
[[localize('ui.card.weather.attributes.wind_speed')]]: [[localize('ui.card.weather.attributes.wind_speed')]]:
[[getWind(stateObj.attributes.wind_speed, stateObj.attributes.wind_bearing, localize)]] [[getWind(stateObj.attributes.wind_speed, stateObj.attributes.wind_bearing, localize)]]
@ -134,9 +135,12 @@ class HaWeatherCard extends
</div> </div>
</template> </template>
<div class="temp">[[item.temperature]] [[getUnit('temperature')]]</div> <div class="temp">[[item.temperature]] [[getUnit('temperature')]]</div>
<template is="dom-if" if="[[item.templow]]"> <template is="dom-if" if="[[_showValue(item.templow)]]">
<div class="templow">[[item.templow]] [[getUnit('temperature')]]</div> <div class="templow">[[item.templow]] [[getUnit('temperature')]]</div>
</template> </template>
<template is="dom-if" if="[[_showValue(item.precipitation)]]">
<div class="precipitation">[[item.precipitation]] [[getUnit('precipitation')]]</div>
</template>
</div> </div>
</template> </template>
</div> </div>
@ -194,8 +198,11 @@ class HaWeatherCard extends
return forecast && forecast.slice(0, 5); return forecast && forecast.slice(0, 5);
} }
getUnit(unit) { getUnit(measure) {
return this.hass.config.core.unit_system[unit] || ''; if (measure === 'precipitation') {
return this.getUnit('length') === 'km' ? 'mm' : 'in';
}
return this.hass.config.core.unit_system[measure] || '';
} }
computeState(state, localize) { computeState(state, localize) {
@ -226,6 +233,10 @@ class HaWeatherCard extends
return `${speed} ${this.getUnit('length')}/h`; return `${speed} ${this.getUnit('length')}/h`;
} }
_showValue(item) {
return typeof item !== 'undefined' && item !== null;
}
computeDateTime(data) { computeDateTime(data) {
const date = new Date(data); const date = new Date(data);
const provider = this.stateObj.attributes.attribution; const provider = this.stateObj.attributes.attribution;