Replace deprecated smhi pmp3g api with new SNOW api#220
Replace deprecated smhi pmp3g api with new SNOW api#220kordianbruck merged 7 commits intoschachmat:masterfrom
Conversation
This reverts commit 85c6120.
|
Can you update your branch please to the latest master? I've fixed the lint warnings in master today. |
There was a problem hiding this comment.
Pull request overview
Updates the SMHI backend to use the new snow1g API endpoint after the old pmp3g endpoint was deactivated.
Changes:
- Replaced the SMHI response model/types to match the new SNOW API response shape.
- Updated parsing logic to read values from the new
dataobject and use the newtimefield. - Switched the SMHI request URL to the
snow1g/version/1endpoint.
Comments suppressed due to low confidence (2)
backends/smhi.go:186
- The loop over
forecast.TimeSeriesnever updatescurrentPrediction, soparseCurrentalways returns the first timeseries entry regardless of the current time. UpdatecurrentPredictionas you iterate (e.g., keep the latest prediction withts <= now), and then break oncets.After(now)is true.
for _, prediction := range forecast.TimeSeries {
ts, err := time.Parse(time.RFC3339, prediction.Time)
if err != nil {
log.Fatalf("Failed to parse timestamp: %v\n", err)
}
if ts.After(currentTime) {
break
backends/smhi.go:160
tsis parsed from the API timestamp (likely with an explicit timezone), but the day-bucketing logic comparests.Day()against a separately initializedcurrentTime(time.Now()earlier). If local time != the API timezone, day boundaries can be off. Consider initializing the “current day” from the first parsedts(or converting both to the same location withIn(...)) so grouping is consistent.
ts, err := time.Parse(time.RFC3339, prediction.Time)
if err != nil {
log.Fatalf("Failed to parse timestamp: %v\n", err)
}
if ts.Day() != currentTime.Day() {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
sorry for the mess. this is the first time I'm doing a PR /o\ https://opendata.smhi.se/metfcst/snow1gv1/parameters |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Should be, thanks for the updates. Looks good from what I can tell. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var currentPrediction *smhiTimeSeries = forecast.TimeSeries[0] | ||
| var currentTime time.Time = time.Now().UTC() | ||
|
|
||
| for _, prediction := range forecast.TimeSeries { | ||
| ts, err := time.Parse(time.RFC3339, prediction.ValidTime) | ||
| ts, err := time.Parse(time.RFC3339, prediction.Time) |
There was a problem hiding this comment.
parseCurrent iterates over forecast.TimeSeries but never updates currentPrediction, so it always returns the first entry regardless of the timestamps. Update currentPrediction inside the loop (e.g., set it to the latest prediction not after currentTime) before breaking so the "current" condition reflects the correct time slot.
| break | ||
| } | ||
|
|
||
| ts, err := time.Parse(time.RFC3339, prediction.ValidTime) | ||
| ts, err := time.Parse(time.RFC3339, prediction.Time) | ||
| if err != nil { |
There was a problem hiding this comment.
Day grouping in parseForecast depends on comparing ts.Day() to currentTime.Day(), but currentTime/day.Date are initialized from time.Now() earlier in the function rather than the first forecast timestamp. If the first prediction.Time is in a different day/timezone than the local clock, this can mis-group days. Consider initializing currentTime/day.Date from the first parsed prediction.Time (and in a consistent timezone) before applying the grouping logic.
| const ( | ||
| // see http://opendata.smhi.se/apidocs/metfcst/index.html | ||
| smhiWuri = "https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/%s/lat/%s/data.json" | ||
| // API Spec: https://opendata.smhi.se/metfcst/snow1gv1/parameters | ||
| smhiWuri = "https://opendata-download-metfcst.smhi.se/api/category/snow1g/version/1/geotype/point/lon/%s/lat/%s/data.json" | ||
| ) |
There was a problem hiding this comment.
The old smhiWuri assignment is left in place as a commented-out line. This is effectively dead code and can be confusing to maintainers; consider removing it (or turning it into a proper comment explaining the deprecation) to keep the constant definition unambiguous.
SMHI deactivated the pmp3g api this month, breaking the wego backend.
This attempts to rejig it for the new api: https://opendata.smhi.se/metfcst/snow1gv1/introduction
Used Gemini to generate most of this.