Skip to content

Commit 1a8a267

Browse files
committed
Add wind speed to daily and hourly forecasts.
Signed-off-by: Katharine Berry <[email protected]>
1 parent 8a92b68 commit 1a8a267

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

service/assistant/functions/weather.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ func processDailyForecast(ctx context.Context, lat, lon float64, units string) a
144144
if uvIndex == nil {
145145
uvIndex = dayParts.UvIndex[i*2+1]
146146
}
147+
windSpeed := dayParts.WindSpeed[i*2]
148+
if windSpeed == nil {
149+
windSpeed = dayParts.WindSpeed[i*2+1]
150+
}
147151
response[day] = map[string]any{
148152
"high": forecast.CalendarDayTemperatureMax[i],
149153
"low": forecast.CalendarDayTemperatureMin[i],
@@ -153,12 +157,14 @@ func processDailyForecast(ctx context.Context, lat, lon float64, units string) a
153157
//"moonrise": forecast.MoonriseTimeLocal[i],
154158
//"moonset": forecast.MoonsetTimeLocal[i],
155159
//"moon_phase": forecast.MoonPhase[i],
156-
"qpf": forecast.Qpf[i],
157-
"qpf_snow": forecast.QpfSnow[i],
158-
"uv_index": uvIndex,
160+
"qpf": forecast.Qpf[i],
161+
"qpf_snow": forecast.QpfSnow[i],
162+
"uv_index": uvIndex,
163+
"wind_speed": windSpeed,
159164
}
160165
}
161166
response["temperatureUnit"] = forecast.TemperatureUnit
167+
response["windSpeedUnit"] = forecast.WindSpeedUnit
162168
response["attribution"] = "The Weather Channel"
163169
return response
164170
}
@@ -180,6 +186,7 @@ func processHourlyForecast(ctx context.Context, lat, lon float64, units string)
180186
"temperature": hourly.Temperature[i],
181187
"uv_index": hourly.UVIndex[i],
182188
"description": hourly.WxPhraseLong[i],
189+
"wind_speed": hourly.WindSpeed[i],
183190
}
184191
if hourly.PrecipChance[i] > 20 {
185192
entry["precip_chance"] = fmt.Sprintf("%d%%", hourly.PrecipChance[i])

service/assistant/util/weather/weather.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func GetHourlyForecast(ctx context.Context, lat, lon float64, units string) (*Ho
120120
return nil, fmt.Errorf("error decoding response: %w", err)
121121
}
122122
hourly.TemperatureUnit = mapTemperatureUnit(units)
123+
hourly.WindSpeedUnit = mapWindSpeedUnit(units)
123124
return &hourly, nil
124125
}
125126

@@ -207,5 +208,7 @@ type HourlyForecast struct {
207208
PrecipType []string `json:"precipType"`
208209
ValidTimeLocal []string `json:"validTimeLocal"`
209210
UVIndex []int `json:"uvIndex"`
211+
WindSpeed []int `json:"windSpeed"`
210212
TemperatureUnit string `json:"temperatureUnit"`
213+
WindSpeedUnit string `json:"windSpeedUnit"`
211214
}

0 commit comments

Comments
 (0)