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