From dad7d63d2fa36bec8f0bfa46febdb0d6faa035e6 Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Sat, 13 Aug 2022 12:54:23 -0400 Subject: weather: update `humidity` - Change return type to just (int). - Add check to skip a value if it's < 1. --- version/version.go | 2 +- weather/weather.go | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/version/version.go b/version/version.go index c331727..502afb4 100644 --- a/version/version.go +++ b/version/version.go @@ -4,4 +4,4 @@ // Peach version. package version -const Version = "0.10.0" +const Version = "0.10.1.dev" diff --git a/weather/weather.go b/weather/weather.go index e72b601..0e981a1 100644 --- a/weather/weather.go +++ b/weather/weather.go @@ -60,11 +60,7 @@ func NewWeather(lat, lng float32) (*Weather, error, int) { } // Get humidity from the grid data. - h, err := humidity(fBundle.ForecastGrid) - if err != nil { - return nil, err, 500 - } - + h := humidity(fBundle.ForecastGrid) w := new(Weather) w.Location = fmt.Sprintf("%s, %s", strings.ToLower(fBundle.Point.Properties.RelativeLocation.Properties.City), @@ -148,18 +144,21 @@ func NewWeather(lat, lng float32) (*Weather, error, int) { return w, nil, 200 } -func humidity(g *nws.ForecastGrid) (int, error) { +func humidity(g *nws.ForecastGrid) int { if g == nil { - return 0, fmt.Errorf("humdity: forecast grid data empty") + return 0 } for _, v := range g.Properties.RelativeHumidity.Values { + if v.Value < 1 { + continue + } yes, err := t.IsCurrent(v.ValidTime) if err != nil { - return 0, fmt.Errorf("humidity: %v", err) + return 0 } if yes { - return v.Value, nil + return v.Value } } - return 0, fmt.Errorf("humidity: not found") + return 0 } -- cgit v1.2.3