Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

New option to report precipitation type in rainfall or probability format #131

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ entity: weather.home
| title | string | none | Card title. |
| show_main | boolean | true | Show or hide a section with current weather condition and temperature. |
| show_attributes | boolean | true | Show or hide a section with attributes such as pressure, humidity, wind direction and speed, etc. |
| precipitation_type | string | rainfall | Show precipitation in either rainfall or probability. |
| icons | string | none | Path to the location of custom icons in svg format, for example `/local/weather-icons/`. |
| icons_size | number | 25 | The size of custom icons in pixels. |
| forecast | object | none | See [forecast options](#forecast-options) for available options. |
| forecast | object | none | See [forecast options](#forecast-options) for available options. |
| units | object | none | See [units of measurement](#units-of-measurement) for available options. |

##### Forecast options
Expand Down
23 changes: 18 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class WeatherChartCard extends LitElement {
static getStubConfig() {
return {
"show_main": true,
"show_attributes": true
"show_attributes": true,
"precipitation_type": 'rainfall'
};
}

Expand Down Expand Up @@ -142,7 +143,11 @@ class WeatherChartCard extends LitElement {
}
var tempUnit = this._hass.config.unit_system.temperature;
var lengthUnit = this._hass.config.unit_system.length;
var precipUnit = lengthUnit === 'km' ? this.ll('units')['mm'] : this.ll('units')['in'];
if (config.precipitation_type === 'probability') {
var precipUnit = '%';
} else {
var precipUnit = lengthUnit === 'km' ? this.ll('units')['mm'] : this.ll('units')['in'];
}
var forecast = weather.attributes.forecast.slice(0, forecastItems);
if ((new Date(forecast[1].datetime) - new Date(forecast[0].datetime)) < 864e5)
var mode = 'hourly';
Expand All @@ -160,7 +165,11 @@ class WeatherChartCard extends LitElement {
if (typeof d.templow !== 'undefined') {
tempLow.push(d.templow);
}
precip.push(d.precipitation);
if (config.precipitation_type === 'probability') {
precip.push(d.precipitation_probability);
} else {
precip.push(d.precipitation);
}
}
var style = getComputedStyle(document.body);
var backgroundColor = style.getPropertyValue('--card-background-color');
Expand Down Expand Up @@ -326,7 +335,7 @@ class WeatherChartCard extends LitElement {
});
}

updateChart({weather, forecastItems, forecastChart} = this) {
updateChart({config, weather, forecastItems, forecastChart} = this) {
if (!weather || !weather.attributes || !weather.attributes.forecast) {
return [];
}
Expand All @@ -343,7 +352,11 @@ class WeatherChartCard extends LitElement {
if (typeof d.templow !== 'undefined') {
tempLow.push(d.templow);
}
precip.push(d.precipitation);
if (config.precipitation_type === 'percentage') {
precip.push(d.precipitation_probability);
} else {
precip.push(d.precipitation);
}
}
if (forecastChart) {
forecastChart.data.labels = dateTime;
Expand Down