Proxy support for AWN/Wunderground
This commit is contained in:
@ -1,6 +1,10 @@
|
||||
package weather
|
||||
|
||||
import "math"
|
||||
import (
|
||||
"math"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Attempts to complete missing fields that may not
|
||||
// be set by a specific provider, such as DewPoint and WindChill
|
||||
@ -53,3 +57,31 @@ func CalculateWindChill(tempF float64, windSpeedMPH float64) float64 {
|
||||
35.75*math.Pow(windSpeedMPH, 0.16) +
|
||||
0.4275*tempF*math.Pow(windSpeedMPH, 0.16)
|
||||
}
|
||||
|
||||
// Helper function to set values from fields
|
||||
// typically from a WeatherUpdate
|
||||
func SetURLVal(vals *url.Values, key string, value any) {
|
||||
if value == nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch v := value.(type) {
|
||||
case *float64:
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
str := strconv.FormatFloat(*v, 'f', 4, 64)
|
||||
vals.Set(key, str)
|
||||
case *int:
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
str := strconv.FormatInt(int64(*v), 10)
|
||||
vals.Set(key, str)
|
||||
case *string:
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
vals.Set(key, *v)
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,9 @@ type WeatherUpdate struct {
|
||||
// if not otherwise set
|
||||
DewPointF *float64
|
||||
WindChillF *float64
|
||||
// First URL parameters given to AWN/Wunderground
|
||||
// if proxying is enabled
|
||||
WeatherServiceCredentials map[string]string
|
||||
}
|
||||
|
||||
type StationInfo struct {
|
||||
@ -82,3 +85,17 @@ const (
|
||||
FieldDewPointF WeatherUpdateField = "DewPointF"
|
||||
FieldWindChillF WeatherUpdateField = "WindChillF"
|
||||
)
|
||||
|
||||
func (u *WeatherUpdate) GetStationName() string {
|
||||
if u.StationInfo != nil {
|
||||
return u.StationInfo.GetName()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (si *StationInfo) GetName() string {
|
||||
if si.Name != nil {
|
||||
return *si.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user