Skip to content

Commit

Permalink
✨ Ensure the station is active
Browse files Browse the repository at this point in the history
If the station is inactive we should error out. When a station is
inactive it's not delivering data.
  • Loading branch information
daenney committed Jun 27, 2022
1 parent 1b4c1b2 commit a7fcc6f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,20 @@ func retrieve(ctx context.Context, client *http.Client, body []byte) (data, erro
return data{}, fmt.Errorf("station with ID: %s does not exist", *stationID)
}

station := wr.Response.Result[0].WeatherStation[0]
if station.Active != nil && !*station.Active {
return data{}, fmt.Errorf("station with ID: %s is not active", *stationID)
}

precip := 0.0
if data := wr.Response.Result[0].WeatherStation[0].Measurement.Precipitation.Amount; data != nil {
if data := station.Measurement.Precipitation.Amount; data != nil {
precip = *data
}

return data{
name: *wr.Response.Result[0].WeatherStation[0].Name,
tempC: *wr.Response.Result[0].WeatherStation[0].Measurement.Air.Temperature,
rhPct: *wr.Response.Result[0].WeatherStation[0].Measurement.Air.RelativeHumidity,
name: *station.Name,
tempC: *station.Measurement.Air.Temperature,
rhPct: *station.Measurement.Air.RelativeHumidity,
precip: precip,
}, nil
}

0 comments on commit a7fcc6f

Please sign in to comment.