Allow changing between C and F for weather temp

This commit is contained in:
Svilen Markov
2024-04-29 16:29:11 +01:00
parent 78572a534b
commit ccdafcdfab
4 changed files with 23 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ type Weather struct {
widgetBase `yaml:",inline"`
Location string `yaml:"location"`
HideLocation bool `yaml:"hide-location"`
Units string `yaml:"units"`
Place *feed.PlaceJson `yaml:"-"`
Weather *feed.Weather `yaml:"-"`
TimeLabels [12]string `yaml:"-"`
@@ -24,6 +25,12 @@ func (widget *Weather) Initialize() error {
widget.withTitle("Weather").withCacheOnTheHour()
widget.TimeLabels = timeLabels
if widget.Units == "" {
widget.Units = "metric"
} else if widget.Units != "metric" && widget.Units != "imperial" {
return fmt.Errorf("invalid units '%s' for weather, must be either metric or imperial", widget.Units)
}
place, err := feed.FetchPlaceFromName(widget.Location)
if err != nil {
@@ -36,7 +43,7 @@ func (widget *Weather) Initialize() error {
}
func (widget *Weather) Update(ctx context.Context) {
weather, err := feed.FetchWeatherForPlace(widget.Place)
weather, err := feed.FetchWeatherForPlace(widget.Place, widget.Units)
if !widget.canContinueUpdateAfterHandlingErr(err) {
return