ea9c746852
The hand-written table understood "какая погода в X" for six values of X. Ask about Kazan or Tbilisi and the city was dropped silently and answered for the default location — a correct-sounding answer about the wrong place. The table is gone. internal/weather already calls Open-Meteo's geocoding endpoint on every lookup, so the place he named goes straight there and any place it knows is a place he can ask about. He speaks the prepositional case, so locationCandidates reverses the two endings that cover most of it: a final "е" is a nominative "а" or nothing, a final "и" is a soft sign. A wrong candidate finds no city; it never invents one. A place the geocoder does not have now reads as "не знаю такого города" rather than as a provider outage or, worse, as the default city's weather. ErrLocationUnknown is what carries that apart. "в" followed by a room or a day word is still the default location. Those questions are answered by the house sensors and the calendar, not by Open-Meteo, and they must not be read as a city.
34 lines
973 B
Go
34 lines
973 B
Go
package weather
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
)
|
|
|
|
var ErrNotConfigured = errors.New("weather: not configured")
|
|
|
|
// ErrLocationUnknown — the geocoder has no such place. A named city that does
|
|
// not resolve must read differently from a provider outage: one is "I do not
|
|
// know that place", the other is "I could not reach the service", and
|
|
// answering for the default location instead is the defect this replaces
|
|
// (Vikunja #421).
|
|
var ErrLocationUnknown = errors.New("weather: location not found")
|
|
|
|
type Weather struct {
|
|
Location string `json:"location"`
|
|
Temperature float64 `json:"temperature"`
|
|
Condition string `json:"condition"`
|
|
}
|
|
|
|
type Provider interface {
|
|
CurrentWeather(ctx context.Context, location string) (Weather, error)
|
|
}
|
|
|
|
type StubProvider struct{}
|
|
|
|
func NewStubProvider() *StubProvider { return &StubProvider{} }
|
|
|
|
func (s *StubProvider) CurrentWeather(_ context.Context, location string) (Weather, error) {
|
|
return Weather{}, ErrNotConfigured
|
|
}
|