Documentation
¶
Overview ¶
Package weather keeps the place the owner chose for the dashboard's weather (CasaOS#188) and its forecast, read from Open-Meteo (no key). It is off until the owner turns it on. The box, not the browser, asks Open-Meteo: the place's coordinates leave the box only toward api.open-meteo.com, and a place name typed in the search only toward geocoding-api.open-meteo.com. Reading the forecast waits on the network only when nothing is cached yet; otherwise it answers what is cached and, when that is older than refreshEvery, refreshes in the background.
Index ¶
Constants ¶
const ConfigFile = "/var/lib/casaos/weather.json"
ConfigFile holds the switch, the place and the units.
Variables ¶
var Default = New("/")
Default is the box's own.
var ErrInvalid = errors.New("invalid weather settings")
ErrInvalid is a PUT body or a search that is not one. Nothing is written.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Enabled bool `json:"enabled"`
Place *Place `json:"place"`
Units string `json:"units"`
}
Config is weather.json. Units is "metric" (°C, km/h) or "imperial" (°F, mph).
type Current ¶
type Current struct {
Temperature float64 `json:"temperature"`
Humidity float64 `json:"humidity"`
Wind float64 `json:"wind"`
Code int `json:"code"`
Day bool `json:"day"`
}
Current is the weather now. Code is the WMO weather code Open-Meteo answers.
type Day ¶
type Day struct {
Date string `json:"date"`
Code int `json:"code"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Rain float64 `json:"rain"` // the day's highest chance of rain, in %
}
Day is one day of the forecast, its date as the place's own (YYYY-MM-DD).
type Forecast ¶
type Forecast struct {
Current Current `json:"current"`
Days []Day `json:"days"`
Updated time.Time `json:"updated"`
}
Forecast is what Open-Meteo answered, and when.
type Place ¶
type Place struct {
Name string `json:"name"`
Region string `json:"region,omitempty"`
Country string `json:"country,omitempty"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}
Place is where the forecast is for.
type Service ¶
type Service struct {
Root string
Now func() time.Time
Client *http.Client
ForecastURL string
GeocodeURL string
// contains filtered or unexported fields
}
Service is the weather of one box.
func (*Service) Search ¶
Search finds up to five places by name, their names in language (an ISO code, "en" when not one).