diff --git a/files/icons/awesome4.toml b/files/icons/awesome4.toml index da50b4783c..a102a0fdb7 100644 --- a/files/icons/awesome4.toml +++ b/files/icons/awesome4.toml @@ -76,9 +76,15 @@ volume_muted = "\uf026 \uf00d" microphone = "\uf130" # fa-microphone microphone_muted = "\uf131" # fa-microphone-slash weather_clouds = "\uf0c2" # fa-cloud +weather_clouds_night = "\uf0c2" # fa-cloud weather_default = "\uf0c2" # fa-cloud +weather_fog = "\uf0c2" # fa-cloud +weather_fog_night = "\uf0c2" # fa-cloud +weather_moon = "\uf186" # fa-moon-o weather_rain = "\uf043" # fa-tint +weather_rain_night = "\uf043" # fa-tint weather_snow = "\uf2dc" # fa-snowflake-o weather_sun = "\uf185" # fa-sun-o weather_thunder = "\uf0e7" # fa-bolt +weather_thunder_night = "\uf0e7" # fa-bolt xrandr = "\uf26c" # fa-television diff --git a/files/icons/awesome5.toml b/files/icons/awesome5.toml index a9764f323e..551104c489 100644 --- a/files/icons/awesome5.toml +++ b/files/icons/awesome5.toml @@ -75,10 +75,16 @@ volume = [ volume_muted = "\uf6a9" microphone = "\uf3c9" microphone_muted = "\uf539" -weather_clouds = "\uf0c2" +weather_clouds = "\uf0c2" # fa-cloud weather_default = "\uf0c2" # Cloud symbol as default -weather_rain = "\uf043" -weather_snow = "\uf2dc" -weather_sun = "\uf185" -weather_thunder = "\uf0e7" +weather_clouds_night = "\uf6c3" # fa-cloud-moon +weather_fog = "\uf0c2" # fa-cloud +weather_fog_night = "\uf0c2" # fa-cloud +weather_moon = "\uf186" # fa-moon +weather_rain = "\uf743" # fa-cloud-sun-rain +weather_rain_night = "\uf73c" # fa-cloud-moon-rain +weather_snow = "\uf2dc" # fa-snowflake +weather_sun = "\uf185" # fa-sun +weather_thunder = "\uf0e7" # fa-bolt +weather_thunder_night = "\uf0e7" # fa-bolt xrandr = "\uf26c" diff --git a/files/icons/awesome6.toml b/files/icons/awesome6.toml index b7f6e7b5b9..92940627ee 100644 --- a/files/icons/awesome6.toml +++ b/files/icons/awesome6.toml @@ -79,10 +79,16 @@ volume = [ volume_muted = "\uf6a9" microphone = "\uf3c9" microphone_muted = "\uf539" -weather_clouds = "\uf0c2" +weather_clouds = "\uf0c2" # fa-cloud weather_default = "\uf0c2" # Cloud symbol as default -weather_rain = "\uf043" -weather_snow = "\uf2dc" -weather_sun = "\uf185" -weather_thunder = "\uf0e7" +weather_clouds_night = "\uf6c3" # fa-cloud-moon +weather_fog = "\uf0c2" # fa-cloud +weather_fog_night = "\uf0c2" # fa-cloud +weather_moon = "\uf186" # fa-moon +weather_rain = "\uf743" # fa-cloud-sun-rain +weather_rain_night = "\uf73c" # fa-cloud-moon-rain +weather_snow = "\uf2dc" # fa-snowflake +weather_sun = "\uf185" # fa-sun +weather_thunder = "\uf0e7" # fa-bolt +weather_thunder_night = "\uf0e7" # fa-bolt xrandr = "\uf26c" diff --git a/files/icons/material-nf.toml b/files/icons/material-nf.toml index bfb8bc82a9..2626560fec 100644 --- a/files/icons/material-nf.toml +++ b/files/icons/material-nf.toml @@ -117,9 +117,15 @@ microphone = [ "\U000f036c", # nf-md-microphone ] weather_clouds = "\ue33d" # nf-weather-cloud +weather_clouds_night = "\ue37e" # nf-weather-night_alt_cloudy weather_default = "\ue33d" # Cloud symbol as default +weather_fog = "\ue313" # nf-weather-fog +weather_fog_night = "\ue346" # nf-weather-night_fog +weather_moon = "\uf186" # nf-fa-moon_o weather_rain = "\ue371" # nf-weather-raindrop +weather_rain_night = "\ue325" # nf-weather-night_alt_rain weather_snow = "\ue36f" # nf-weather-snowflake_cold weather_sun = "\ue30d" # nf-weather-day_sunny weather_thunder = "\ue31d" # nf-weather-thunderstorm +weather_thunder_night = "\ue32a" # nf-weather-night_alt_thunderstorm xrandr = "\U000f037a" # nf-md-monitor_multiple diff --git a/files/icons/material.toml b/files/icons/material.toml index b744d5a5f8..4e70556fce 100644 --- a/files/icons/material.toml +++ b/files/icons/material.toml @@ -97,9 +97,15 @@ microphone = [ ] microphone_muted = "\ue02b" # mic_off weather_clouds = "\ue42d" # wb_cloudy +weather_clouds_night = "\uea46" # nights_stay weather_default = "\ue42d" # wb_cloudy -weather_rain = "\ue42d" # wb_cloudy -weather_snow = "\ue42d" # wb_cloudy +weather_fog = "\ue42d" # wb_cloudy +weather_fog_night = "\ue42d" # wb_cloudy +weather_moon = "\uf03d" # nightlight +weather_rain = "\ue798" # water_drop +weather_rain_night = "\ue798" # water_drop +weather_snow = "\ueb3b" # ac_unit weather_sun = "\ue430" # wb_sunny -weather_thunder = "\ue42d" # wb_cloudy +weather_thunder = "\uebdb" # thunderstorm +weather_thunder_night = "\uebdb" # thunderstorm xrandr = "\ue31e" # laptop diff --git a/src/blocks/weather.rs b/src/blocks/weather.rs index f8913f6876..e79a459c9b 100644 --- a/src/blocks/weather.rs +++ b/src/blocks/weather.rs @@ -82,12 +82,17 @@ //! //! # Used Icons //! -//! - `weather_sun` (when weather is reported as "Clear") -//! - `weather_rain` (when weather is reported as "Rain" or "Drizzle") -//! - `weather_clouds` (when weather is reported as "Clouds", "Fog" or "Mist") -//! - `weather_thunder` (when weather is reported as "Thunderstorm") +//! - `weather_sun` (when weather is reported as "Clear" during the day) +//! - `weather_moon` (when weather is reported as "Clear" at night) +//! - `weather_clouds` (when weather is reported as "Clouds" during the day) +//! - `weather_clouds_night` (when weather is reported as "Clouds" at night) +//! - `weather_fog` (when weather is reported as "Fog" or "Mist" during the day) +//! - `weather_fog_night` (when weather is reported as "Fog" or "Mist" at night) +//! - `weather_rain` (when weather is reported as "Rain" or "Drizzle" during the day) +//! - `weather_rain_night` (when weather is reported as "Rain" or "Drizzle" at night) //! - `weather_snow` (when weather is reported as "Snow") -//! - `weather_default` (in all other cases) +//! - `weather_thunder` (when weather is reported as "Thunderstorm" during the day) +//! - `weather_thunder_night` (when weather is reported as "Thunderstorm" at night) use std::fmt; use std::sync::{Arc, Mutex}; @@ -134,22 +139,29 @@ pub enum WeatherService { #[derive(Clone, Copy)] enum WeatherIcon { - Sun, - Rain, - Clouds, - Thunder, + Clear { is_night: bool }, + Clouds { is_night: bool }, + Fog { is_night: bool }, + Rain { is_night: bool }, Snow, + Thunder { is_night: bool }, Default, } impl WeatherIcon { fn to_icon_str(self) -> &'static str { match self { - Self::Sun => "weather_sun", - Self::Rain => "weather_rain", - Self::Clouds => "weather_clouds", - Self::Thunder => "weather_thunder", + Self::Clear { is_night: false } => "weather_sun", + Self::Clear { is_night: true } => "weather_moon", + Self::Clouds { is_night: false } => "weather_clouds", + Self::Clouds { is_night: true } => "weather_clouds_night", + Self::Fog { is_night: false } => "weather_fog", + Self::Fog { is_night: true } => "weather_fog_night", + Self::Rain { is_night: false } => "weather_rain", + Self::Rain { is_night: true } => "weather_rain_night", Self::Snow => "weather_snow", + Self::Thunder { is_night: false } => "weather_thunder", + Self::Thunder { is_night: true } => "weather_thunder_night", Self::Default => "weather_default", } } diff --git a/src/blocks/weather/met_no.rs b/src/blocks/weather/met_no.rs index 7e49d62257..4543dc2e92 100644 --- a/src/blocks/weather/met_no.rs +++ b/src/blocks/weather/met_no.rs @@ -143,15 +143,21 @@ impl WeatherProvider for Service<'_> { let instant = &first.instant.details; - let summary = first + let mut symbol_code_split = first .next_1_hours .as_ref() .unwrap() .summary .symbol_code - .split('_') + .split('_'); + + let summary = symbol_code_split.next().unwrap(); + + // Times of day can be day, night, and polartwilight + let is_night = symbol_code_split .next() - .unwrap(); + .map_or(false, |time_of_day| time_of_day == "night"); + let translated = translate(self.legend, summary, lang); let temp = instant.air_temperature.unwrap_or_default(); @@ -168,17 +174,18 @@ impl WeatherProvider for Service<'_> { wind: wind_speed, wind_kmh: instant.wind_speed.unwrap_or_default() * 3.6, wind_direction: convert_wind_direction(instant.wind_from_direction).into(), - icon: weather_to_icon(summary), + icon: weather_to_icon(summary, is_night), }) } } -fn weather_to_icon(weather: &str) -> WeatherIcon { +fn weather_to_icon(weather: &str, is_night: bool) -> WeatherIcon { match weather { - "cloudy" | "partlycloudy" | "fair" | "fog" => WeatherIcon::Clouds, - "clearsky" => WeatherIcon::Sun, + "cloudy" | "partlycloudy" | "fair" => WeatherIcon::Clouds{is_night}, + "fog" => WeatherIcon::Fog{is_night}, + "clearsky" => WeatherIcon::Clear{is_night}, "heavyrain" | "heavyrainshowers" | "lightrain" | "lightrainshowers" | "rain" - | "rainshowers" => WeatherIcon::Rain, + | "rainshowers" => WeatherIcon::Rain{is_night}, "rainandthunder" | "heavyrainandthunder" | "rainshowersandthunder" @@ -194,9 +201,11 @@ fn weather_to_icon(weather: &str) -> WeatherIcon { | "lightsleetandthunder" | "lightrainandthunder" | "lightsnowandthunder" - | "lightssleetshowersandthunder" - | "lightssnowshowersandthunder" - | "lightrainshowersandthunder" => WeatherIcon::Thunder, + | "lightssleetshowersandthunder" // There's a typo in the api it will be fixed in the next version to the following entry + | "lightsleetshowersandthunder" + | "lightssnowshowersandthunder"// There's a typo in the api it will be fixed in the next version to the following entry + | "lightsnowshowersandthunder" + | "lightrainshowersandthunder" => WeatherIcon::Thunder{is_night}, "heavysleet" | "heavysleetshowers" | "heavysnow" | "heavysnowshowers" | "lightsleet" | "lightsleetshowers" | "lightsnow" | "lightsnowshowers" | "sleet" | "sleetshowers" | "snow" | "snowshowers" => WeatherIcon::Snow, diff --git a/src/blocks/weather/open_weather_map.rs b/src/blocks/weather/open_weather_map.rs index 65a7e06b1b..6293ba1031 100644 --- a/src/blocks/weather/open_weather_map.rs +++ b/src/blocks/weather/open_weather_map.rs @@ -1,4 +1,5 @@ use super::*; +use chrono::Utc; pub(super) const URL: &str = "https://api.openweathermap.org/data/2.5/weather"; pub(super) const API_KEY_ENV: &str = "OPENWEATHERMAP_API_KEY"; @@ -49,6 +50,7 @@ struct ApiResponse { weather: Vec, main: ApiMain, wind: ApiWind, + sys: ApiSys, name: String, } @@ -65,6 +67,12 @@ struct ApiMain { humidity: f64, } +#[derive(Deserialize, Debug)] +struct ApiSys { + sunrise: i64, + sunset: i64, +} + #[derive(Deserialize, Debug)] struct ApiWeather { main: String, @@ -109,6 +117,9 @@ impl WeatherProvider for Service<'_> { .await .error("Forecast request failed")?; + let now = Utc::now().timestamp(); + let is_night = data.sys.sunrise >= now || now >= data.sys.sunset; + Ok(WeatherResult { location: data.name, temp: data.main.temp, @@ -124,10 +135,11 @@ impl WeatherProvider for Service<'_> { }, wind_direction: convert_wind_direction(data.wind.deg).into(), icon: match data.weather[0].main.as_str() { - "Clear" => WeatherIcon::Sun, - "Rain" | "Drizzle" => WeatherIcon::Rain, - "Clouds" | "Fog" | "Mist" => WeatherIcon::Clouds, - "Thunderstorm" => WeatherIcon::Thunder, + "Clear" => WeatherIcon::Clear { is_night }, + "Rain" | "Drizzle" => WeatherIcon::Rain { is_night }, + "Clouds" => WeatherIcon::Clouds { is_night }, + "Fog" | "Mist" => WeatherIcon::Fog { is_night }, + "Thunderstorm" => WeatherIcon::Thunder { is_night }, "Snow" => WeatherIcon::Snow, _ => WeatherIcon::Default, }, diff --git a/src/icons.rs b/src/icons.rs index 5ab27ad6fe..767a4da3c8 100644 --- a/src/icons.rs +++ b/src/icons.rs @@ -97,11 +97,17 @@ impl Default for Icons { "volume_muted" => "VOL MUTED", "microphone" => "MIC", "microphone_muted" => "MIC MUTED", + "weather_clouds_night" => "CLOUDY", "weather_clouds" => "CLOUDY", "weather_default" => "WEATHER", + "weather_fog_night" => "FOG", + "weather_fog" => "FOG", + "weather_moon" => "MOONY", + "weather_rain_night" => "RAIN", "weather_rain" => "RAIN", "weather_snow" => "SNOW", "weather_sun" => "SUNNY", + "weather_thunder_night" => "STORM", "weather_thunder" => "STORM", "xrandr" => "SCREEN" })