Skip to content

Commit

Permalink
use night icons when showing hourly forecast
Browse files Browse the repository at this point in the history
and time ist between sun setting and rising.
  • Loading branch information
Mike Goutrie committed Dec 25, 2022
1 parent 8773e03 commit 18759ae
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions dist/weather-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ class WeatherCard extends LitElement {
<i
class="icon"
style="background: none, url('${this.getWeatherIcon(
daily.condition.toLowerCase()
daily.condition.toLowerCase(),
this.hass.states["sun.sun"],
this._config.hourly_forecast,
daily.datetime
)}') no-repeat; background-size: contain"
></i>
<div class="highTemp">
Expand Down Expand Up @@ -318,18 +321,26 @@ class WeatherCard extends LitElement {
`;
}

getWeatherIcon(condition, sun) {
getWeatherIcon(condition, sun, hourly, dt) {
return `${
this._config.icons
? this._config.icons
: "https://cdn.jsdelivr.net/gh/bramkragten/weather-card/dist/icons/"
}${
sun && sun.state == "below_horizon"
sun && ((!dt && sun.state == "below_horizon") || (dt && hourly && this.getIsNight(sun, dt)))
? weatherIconsNight[condition]
: weatherIconsDay[condition]
}.svg`;
}

getIsNight(sun, dt)
{
const time = new Date(dt).getHours();
const afterSetting = time > new Date(sun.attributes.next_setting).getHours();
const beforeRising = time < new Date(sun.attributes.next_rising).getHours();
return beforeRising || afterSetting;
}

getUnit(measure) {
const lengthUnit = this.hass.config.unit_system.length;
switch (measure) {
Expand Down

0 comments on commit 18759ae

Please sign in to comment.