weather

package
v0.4.131 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const ConfigFile = "/var/lib/casaos/weather.json"

ConfigFile holds the switch, the place and the units.

Variables

View Source
var Default = New("/")

Default is the box's own.

View Source
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 New

func New(root string) *Service

New keeps weather.json under root.

func (*Service) Search

func (s *Service) Search(name, language string) ([]Place, error)

Search finds up to five places by name, their names in language (an ISO code, "en" when not one).

func (*Service) Status

func (s *Service) Status() Status

Status answers the settings and the forecast. On with a place and nothing cached for it, it waits for Open-Meteo; with a forecast older than refreshEvery, it refreshes in the background. Off, it asks nothing.

func (*Service) Update

func (s *Service) Update(c Config) (Status, error)

Update replaces the settings. On needs a place; units other than "imperial" are "metric".

type Status

type Status struct {
	Config
	Forecast *Forecast `json:"forecast"`
	// why the last read failed; the forecast shown, if any, is the one before
	Error string `json:"error,omitempty"`
}

Status is what GET and PUT /v1/sys/weather answer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL