Giving option to round temp to nearest integer

This commit is contained in:
Florian Hoss 2022-10-28 08:20:13 +02:00
parent 3a564fc52a
commit 03dc2ae2e7
4 changed files with 20 additions and 9 deletions

View file

@ -67,6 +67,7 @@ LOCATION_LONGITUDE = 9.177968320179422
OPEN_WEATHER_KEY = ""
OPEN_WEATHER_UNITS = "metric"
OPEN_WEATHER_LANG = "en"
OPEN_WEATHER_DIGITS = true
LIVE_SYSTEM = true
```
@ -99,6 +100,8 @@ services:
- OPEN_WEATHER_UNITS=metric
# https://openweathermap.org/current#multi
- OPEN_WEATHER_LANG=en
# Temp is normally xx.xx, can be rounded to xx if desired
- OPEN_WEATHER_DIGITS=true
# location is needed for weather
- LOCATION_LATITUDE=48.644929601442485
- LOCATION_LONGITUDE=9.349618464869025

View file

@ -6,6 +6,7 @@
"open_weather": {
"key": "",
"units": "metric",
"lang": "en"
"lang": "en",
"digits": true
}
}

View file

@ -12,16 +12,17 @@ type Location struct {
}
type OpenWeather struct {
Key string
Units string
Lang string
Key string
Units string
Lang string
Digits bool
}
type Weather struct {
Icon string `json:"icon"`
Temp float32 `json:"temp"`
Temp float64 `json:"temp"`
Description string `json:"description"`
Humidity float32 `json:"humidity"`
Humidity uint8 `json:"humidity"`
Sunrise string `json:"sunrise"`
Sunset string `json:"sunset"`
Units string `json:"units"`
@ -39,8 +40,8 @@ type OpenWeatherApiWeather struct {
}
type OpenWeatherApiMain struct {
Temp float32 `json:"temp"`
Humidity float32 `json:"humidity"`
Temp float64 `json:"temp"`
Humidity uint8 `json:"humidity"`
}
type OpenWeatherApiSys struct {

View file

@ -7,6 +7,7 @@ import (
"godash/config"
"godash/hub"
"io"
"math"
"net/http"
"time"
)
@ -36,7 +37,12 @@ func copyWeatherValues(weatherResp *OpenWeatherApiResponse) {
myTime = time.Unix(weatherResp.Sys.Sunset, 0)
CurrentWeather.Sunset = myTime.Format("15:04")
CurrentWeather.Icon = weatherResp.Weather[0].Icon
CurrentWeather.Temp = weatherResp.Main.Temp
fmt.Println(weatherResp.Main.Temp)
if Conf.OpenWeather.Digits {
CurrentWeather.Temp = weatherResp.Main.Temp
} else {
CurrentWeather.Temp = math.Round(weatherResp.Main.Temp)
}
CurrentWeather.Description = weatherResp.Weather[0].Description
CurrentWeather.Humidity = weatherResp.Main.Humidity
}