Skip to content

Commit

Permalink
Handle cardinal directions for wind bearing
Browse files Browse the repository at this point in the history
  • Loading branch information
avee87 committed Jul 6, 2022
1 parent f7d1255 commit 8e39870
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions dist/weather-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const windDirections = [
"NNW",
"N",
];
const windDirectionsSet = new Set(windDirections);

window.customCards = window.customCards || [];
window.customCards.push({
Expand Down Expand Up @@ -197,12 +198,12 @@ class WeatherCard extends LitElement {
}

if (stateObj.attributes.wind_speed != null) {
const windBearing = stateObj.attributes.wind_bearing;

items.push(html`
<ha-icon icon="mdi:weather-windy"></ha-icon>
${stateObj.attributes.wind_bearing != null
? windDirections[
parseInt((stateObj.attributes.wind_bearing + 11.25) / 22.5)
]
${windBearing != null
? this.getWindDirection(windBearing)
: ""}
${stateObj.attributes.wind_speed}<span class="unit">
${this.getUnit("wind_speed")}
Expand Down Expand Up @@ -328,6 +329,15 @@ class WeatherCard extends LitElement {
`;
}

getWindDirection(windBearing) {
if (windDirectionsSet.has(windBearing)) {
return windBearing;
}
return windDirections[
parseInt((windBearing + 11.25) / 22.5)
];
}

getWeatherIcon(condition, sun) {
return `${
this._config.icons
Expand Down

0 comments on commit 8e39870

Please sign in to comment.