Use custom config type
This commit is contained in:
@ -24,6 +24,7 @@ type AmbientWeather struct {
|
||||
// when either "AmbientWeather" or "Wunderground" are selected
|
||||
// in the "Custom" section of the AWNet app, or the web UI
|
||||
// of an Ambient WeatherHub
|
||||
config *AmbientLocalExporterConfig
|
||||
awnProvider provider.AmbientProvider
|
||||
wuProvider provider.AmbientProvider
|
||||
appCtx context.Context
|
||||
@ -31,7 +32,7 @@ type AmbientWeather struct {
|
||||
l *zerolog.Logger
|
||||
}
|
||||
|
||||
func New(appCtx context.Context) *AmbientWeather {
|
||||
func New(appCtx context.Context, awConfig *AmbientLocalExporterConfig) *AmbientWeather {
|
||||
return &AmbientWeather{
|
||||
appCtx: appCtx,
|
||||
}
|
||||
|
33
pkg/ambient/config.go
Normal file
33
pkg/ambient/config.go
Normal file
@ -0,0 +1,33 @@
|
||||
package ambient
|
||||
|
||||
import (
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/weather"
|
||||
)
|
||||
|
||||
// This configuration includes all config from go-app/config.AppConfig
|
||||
type AmbientLocalExporterConfig struct {
|
||||
MetricPrefix string `yaml:"metricPrefix" default:"weather" env:"AMBIENT_METRIC_PREFIX"`
|
||||
WeatherStations []WeatherStation `yaml:"weatherStations"` // No env, too complex, not worth the time
|
||||
*config.AppConfig // Extends app config
|
||||
}
|
||||
|
||||
type WeatherStation struct {
|
||||
Name string `yaml:"name"` // Human Friendly Name (e.g. Back Yard Weather)
|
||||
Equipment string `yaml:"equipment"` // Equipment Type (e.g. WS-5000)
|
||||
|
||||
// One of these is required, based on the type
|
||||
// set in the "Custom" weather service on your
|
||||
// console, weather station, or weather hub
|
||||
WundergroundID string `yaml:"wundergroundID"`
|
||||
AWNPassKey string `yaml:"awnPassKey"`
|
||||
|
||||
// Proxy updates to AWN or Wunderground
|
||||
ProxyToAWN bool `yaml:"proxyToAWN"`
|
||||
ProxyToWunderground bool `yaml:"proxyToWunderground"`
|
||||
|
||||
// Unreliable / unwanted metrics by name of WeatherUpdate Field
|
||||
// These fields are mapped from the provider fields
|
||||
DiscardMetrics []weather.WeatherUpdateField `yaml:"discardMetrics"`
|
||||
}
|
@ -7,31 +7,27 @@ import (
|
||||
// Stable intermediate struct containing superset of fields
|
||||
// between AWN and Wunderground style updates from Ambient devices
|
||||
type WeatherUpdate struct {
|
||||
DateUTC *time.Time
|
||||
StationType string
|
||||
TempOutdoorF float64
|
||||
TempIndoorF float64
|
||||
HumidityOudoor int
|
||||
HumidityIndoor int
|
||||
WindSpeedMPH float64
|
||||
WindGustMPH float64
|
||||
MaxDailyGust float64
|
||||
WindDir int
|
||||
WindDirAvg10m int
|
||||
UV int
|
||||
SolarRadiation float64
|
||||
HourlyRainIn float64
|
||||
EventRainIn float64
|
||||
DailyRainIn float64
|
||||
WeeklyRainIn float64
|
||||
MonthlyRainIn float64
|
||||
YearlyRainIn float64
|
||||
TotalRainIn float64
|
||||
Batteries []BatteryStatus
|
||||
// BattOutdoorSensor int
|
||||
// BattIndoorSensor int
|
||||
// BattRainSensor int
|
||||
// BattCO2Sensor int
|
||||
DateUTC *time.Time
|
||||
StationType string
|
||||
TempOutdoorF float64
|
||||
TempIndoorF float64
|
||||
HumidityOudoor int
|
||||
HumidityIndoor int
|
||||
WindSpeedMPH float64
|
||||
WindGustMPH float64
|
||||
MaxDailyGust float64
|
||||
WindDir int
|
||||
WindDirAvg10m int
|
||||
UV int
|
||||
SolarRadiation float64
|
||||
HourlyRainIn float64
|
||||
EventRainIn float64
|
||||
DailyRainIn float64
|
||||
WeeklyRainIn float64
|
||||
MonthlyRainIn float64
|
||||
YearlyRainIn float64
|
||||
TotalRainIn float64
|
||||
Batteries []BatteryStatus
|
||||
BaromRelativeIn float64
|
||||
BaromAbsoluteIn float64
|
||||
// These fields may be calculated
|
||||
@ -44,3 +40,35 @@ type BatteryStatus struct {
|
||||
Component string
|
||||
Status int
|
||||
}
|
||||
|
||||
type WeatherUpdateField string
|
||||
|
||||
// NOTE: Annoyance to avoid string constant comparisons
|
||||
// CHORE: Maintain this
|
||||
const (
|
||||
FieldDateUTC WeatherUpdateField = "DateUTC"
|
||||
FieldStationType WeatherUpdateField = "StationType"
|
||||
FieldTempOutdoorF WeatherUpdateField = "TempOutdoorF"
|
||||
FieldTempIndoorF WeatherUpdateField = "TempIndoorF"
|
||||
FieldHumidityOudoor WeatherUpdateField = "HumidityOudoor"
|
||||
FieldHumidityIndoor WeatherUpdateField = "HumidityIndoor"
|
||||
FieldWindSpeedMPH WeatherUpdateField = "WindSpeedMPH"
|
||||
FieldWindGustMPH WeatherUpdateField = "WindGustMPH"
|
||||
FieldMaxDailyGust WeatherUpdateField = "MaxDailyGust"
|
||||
FieldWindDir WeatherUpdateField = "WindDir"
|
||||
FieldWindDirAvg10m WeatherUpdateField = "WindDirAvg10m"
|
||||
FieldUV WeatherUpdateField = "UV"
|
||||
FieldSolarRadiation WeatherUpdateField = "SolarRadiation"
|
||||
FieldHourlyRainIn WeatherUpdateField = "HourlyRainIn"
|
||||
FieldEventRainIn WeatherUpdateField = "EventRainIn"
|
||||
FieldDailyRainIn WeatherUpdateField = "DailyRainIn"
|
||||
FieldWeeklyRainIn WeatherUpdateField = "WeeklyRainIn"
|
||||
FieldMonthlyRainIn WeatherUpdateField = "MonthlyRainIn"
|
||||
FieldYearlyRainIn WeatherUpdateField = "YearlyRainIn"
|
||||
FieldTotalRainIn WeatherUpdateField = "TotalRainIn"
|
||||
FieldBatteries WeatherUpdateField = "Batteries"
|
||||
FieldBaromRelativeIn WeatherUpdateField = "BaromRelativeIn"
|
||||
FieldBaromAbsoluteIn WeatherUpdateField = "BaromAbsoluteIn"
|
||||
FieldDewPointF WeatherUpdateField = "DewPointF"
|
||||
FieldWindChillF WeatherUpdateField = "WindChillF"
|
||||
)
|
||||
|
Reference in New Issue
Block a user