Added PressureQFE to current weather

This commit is contained in:
Winni Neessen 2023-06-23 12:35:52 +02:00
parent 4d60f35c6a
commit fcc7626a76
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D
3 changed files with 81 additions and 7 deletions

View file

@ -46,6 +46,8 @@ type APICurrentWeatherData struct {
Precipitation24h *APIFloat `json:"prec24h,omitempty"`
// PressureMSL represents the pressure at mean sea level (MSL) in hPa
PressureMSL *APIFloat `json:"pressureMsl,omitempty"`
// PressureQFE represents the pressure at station level (QFE) in hPa
PressureQFE *APIFloat `json:"pressure,omitempty"`
// Temperature represents the temperature in °C
Temperature *APIFloat `json:"temp,omitempty,omitempty"`
// WindDirection represents the direction from which the wind
@ -228,6 +230,25 @@ func (cw CurrentWeather) PressureMSL() Pressure {
return v
}
// PressureQFE returns the pressure at mean sea level data point as Pressure.
// If the data point is not available in the CurrentWeather it will return
// Pressure in which the "not available" field will be true.
func (cw CurrentWeather) PressureQFE() Pressure {
if cw.Data.PressureQFE == nil {
return Pressure{na: true}
}
v := Pressure{
dt: cw.Data.PressureQFE.DateTime,
n: FieldPressureQFE,
s: SourceUnknown,
fv: cw.Data.PressureQFE.Value,
}
if cw.Data.PressureQFE.Source != nil {
v.s = StringToSource(*cw.Data.PressureQFE.Source)
}
return v
}
// Temperature returns the temperature data point as Temperature.
// If the data point is not available in the CurrentWeather it will return
// Temperature in which the "not available" field will be true.

View file

@ -512,6 +512,59 @@ func TestClient_CurrentWeatherByLocation_PressureMSL(t *testing.T) {
}
}
func TestClient_CurrentWeatherByLocation_PressureQFE(t *testing.T) {
tt := []struct {
// Location name
loc string
// CurWeather pressure
p *Pressure
}{
{"Ehrenfeld, Germany", &Pressure{
dt: time.Date(2023, 5, 23, 7, 0, 0, 0, time.Local),
s: SourceAnalysis,
fv: 1011.7,
}},
{"Berlin, Germany", nil},
{"Neermoor, Germany", nil},
}
c := New(withMockAPI())
if c == nil {
t.Errorf("failed to create new Client, got nil")
return
}
for _, tc := range tt {
t.Run(tc.loc, func(t *testing.T) {
cw, err := c.CurrentWeatherByLocation(tc.loc)
if err != nil {
t.Errorf("CurrentWeatherByLocation failed: %s", err)
return
}
if tc.p != nil && tc.p.String() != cw.PressureQFE().String() {
t.Errorf("CurrentWeatherByLocation failed, expected pressure "+
"string: %s, got: %s", tc.p.String(), cw.PressureQFE())
}
if tc.p != nil && tc.p.Value() != cw.PressureQFE().Value() {
t.Errorf("CurrentWeatherByLocation failed, expected pressure "+
"float: %f, got: %f", tc.p.Value(), cw.PressureQFE().Value())
}
if tc.p != nil && cw.PressureQFE().Source() != tc.p.s {
t.Errorf("CurrentWeatherByLocation failed, expected source: %s, but got: %s",
tc.p.s, cw.PressureQFE().Source())
}
if tc.p == nil {
if cw.PressureQFE().IsAvailable() {
t.Errorf("CurrentWeatherByLocation failed, expected pressure "+
"to have no data, but got: %s", cw.PressureQFE())
}
if !math.IsNaN(cw.PressureQFE().Value()) {
t.Errorf("CurrentWeatherByLocation failed, expected pressure "+
"to return NaN, but got: %s", cw.PressureQFE().String())
}
}
})
}
}
func TestClient_CurrentWeatherByLocation_Temperature(t *testing.T) {
tt := []struct {
// Location name

View file

@ -52,17 +52,17 @@ type APIObservationData struct {
// HumidityRelative represents the relative humidity in percent
HumidityRelative *APIFloat `json:"humidityRelative,omitempty"`
// Precipitation represents the current amount of precipitation
Precipitation *APIFloat `json:"prec"`
Precipitation *APIFloat `json:"prec,omitempty"`
// Precipitation10m represents the amount of precipitation over the last 10 minutes
Precipitation10m *APIFloat `json:"prec10m"`
Precipitation10m *APIFloat `json:"prec10m,omitempty"`
// Precipitation1h represents the amount of precipitation over the last hour
Precipitation1h *APIFloat `json:"prec1h"`
Precipitation1h *APIFloat `json:"prec1h,omitempty"`
// Precipitation24h represents the amount of precipitation over the last 24 hours
Precipitation24h *APIFloat `json:"prec24h"`
Precipitation24h *APIFloat `json:"prec24h,omitempty"`
// PressureMSL represents the air pressure at MSL / temperature adjusted (QFF) in hPa
PressureMSL *APIFloat `json:"pressureMsl"`
PressureMSL *APIFloat `json:"pressureMsl,omitempty"`
// PressureQFE represents the pressure at station level (QFE) in hPa
PressureQFE *APIFloat `json:"pressure"`
PressureQFE *APIFloat `json:"pressure,omitempty"`
// Temperature represents the temperature in °C
Temperature *APIFloat `json:"temp,omitempty"`
// TemperatureMax represents the maximum temperature in °C
@ -79,7 +79,7 @@ type APIObservationData struct {
// WindDirection represents the direction from which the wind
// originates in degree (0=N, 90=E, 180=S, 270=W)
WindDirection *APIFloat `json:"windDirection,omitempty"`
// WindSpeed represents the wind speed in knots
// WindSpeed represents the wind speed in knots (soon switched to m/s)
WindSpeed *APIFloat `json:"windSpeed,omitempty"`
}