continue working on weather mapping
This commit is contained in:
@ -27,7 +27,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 *config.AmbientLocalExporterConfig
|
||||
Config *config.AmbientLocalExporterConfig
|
||||
awnProvider provider.AmbientProvider
|
||||
wuProvider provider.AmbientProvider
|
||||
appCtx context.Context
|
||||
@ -37,7 +37,7 @@ type AmbientWeather struct {
|
||||
|
||||
func New(appCtx context.Context, awConfig *config.AmbientLocalExporterConfig) *AmbientWeather {
|
||||
return &AmbientWeather{
|
||||
config: awConfig,
|
||||
Config: awConfig,
|
||||
appCtx: appCtx,
|
||||
}
|
||||
}
|
||||
@ -48,7 +48,7 @@ func (aw *AmbientWeather) Init() *AmbientWeather {
|
||||
aw.wuProvider = &wunderground.WUProvider{}
|
||||
aw.l = zerolog.Ctx(aw.appCtx)
|
||||
|
||||
aw.l.Trace().Any("awConfig", aw.config).Send()
|
||||
aw.l.Trace().Any("awConfig", aw.Config).Send()
|
||||
return aw
|
||||
}
|
||||
|
||||
@ -227,15 +227,15 @@ func (aw *AmbientWeather) proxyUpdate(
|
||||
}
|
||||
|
||||
func (aw *AmbientWeather) InitMetrics() {
|
||||
if aw.config.MetricPrefix != "" {
|
||||
weather.MetricPrefix = aw.config.MetricPrefix
|
||||
if aw.Config.MetricPrefix != "" {
|
||||
weather.MetricPrefix = aw.Config.MetricPrefix
|
||||
}
|
||||
aw.metrics = weather.MustInitMetrics(aw.appCtx)
|
||||
}
|
||||
|
||||
func (aw *AmbientWeather) enrichStation(update *weather.WeatherUpdate) {
|
||||
if update != nil && update.StationID != nil && *update.StationID != "" {
|
||||
for _, station := range aw.config.WeatherStations {
|
||||
for _, station := range aw.Config.WeatherStations {
|
||||
if *update.StationID == station.AWNPassKey || *update.StationID == station.WundergroundID {
|
||||
update.StationConfig = &station
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import (
|
||||
// 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
|
||||
UpdatesToKeep *int `yaml:"updatesToKeep" default:"1" env:"AMBIENT_UPDATES_TO_KEEP"`
|
||||
WeatherStations []WeatherStation `yaml:"weatherStations" env:"weatherStations"` // No env, too complex, not worth the time
|
||||
*config.AppConfig // Extends app config
|
||||
}
|
||||
|
||||
|
@ -25,25 +25,44 @@ func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
|
||||
TempIndoorF: u.TempIndoorF,
|
||||
HumidityOutdoor: ptr.To(int32(*u.HumidityOudoor)),
|
||||
HumidityIndoor: ptr.To(int32(*u.HumidityIndoor)),
|
||||
WindSpeedMph: new(float64),
|
||||
WindGustMph: new(float64),
|
||||
MaxDailyGust: new(float64),
|
||||
WindDir: new(int32),
|
||||
WindDirAvg_10M: new(int32),
|
||||
Uv: new(int32),
|
||||
SolarRadiation: new(float64),
|
||||
HourlyRainIn: new(float64),
|
||||
EventRainIn: new(float64),
|
||||
DailyRainIn: new(float64),
|
||||
WeeklyRainIn: new(float64),
|
||||
MonthlyRainIn: new(float64),
|
||||
YearlyRainIn: new(float64),
|
||||
TotalRainIn: new(float64),
|
||||
WindSpeedMph: ptr.To(*u.WindSpeedMPH),
|
||||
WindGustMph: ptr.To(*u.WindGustMPH),
|
||||
MaxDailyGust: ptr.To(*u.MaxDailyGust),
|
||||
WindDir: ptr.To(int32(*u.WindDir)),
|
||||
WindDirAvg_10M: ptr.To(int32(*u.WindDirAvg10m)),
|
||||
Uv: ptr.To(int32(*u.UV)),
|
||||
SolarRadiation: ptr.To(*u.SolarRadiation),
|
||||
HourlyRainIn: ptr.To(*u.HourlyRainIn),
|
||||
EventRainIn: ptr.To(*u.EventRainIn),
|
||||
DailyRainIn: ptr.To(*u.DailyRainIn),
|
||||
WeeklyRainIn: ptr.To(*u.WeeklyRainIn),
|
||||
MonthlyRainIn: ptr.To(*u.MonthlyRainIn),
|
||||
YearlyRainIn: ptr.To(*u.YearlyRainIn),
|
||||
TotalRainIn: ptr.To(*u.TotalRainIn),
|
||||
Batteries: []*pb.BatteryStatus{},
|
||||
BaromRelativeIn: new(float64),
|
||||
BaromAbsoluteIn: new(float64),
|
||||
DewPointF: new(float64),
|
||||
WindChillF: new(float64),
|
||||
BaromRelativeIn: ptr.To(*u.BaromRelativeIn),
|
||||
BaromAbsoluteIn: ptr.To(*u.BaromAbsoluteIn),
|
||||
DewPointF: ptr.To(*u.DewPointF),
|
||||
WindChillF: ptr.To(*u.WindChillF),
|
||||
TempHumiditySensors: []*pb.TempHumiditySensor{},
|
||||
}
|
||||
}
|
||||
|
||||
func BatteriesToPbBatteries(batteries []weather.BatteryStatus) []*pb.BatteryStatus {
|
||||
pbBatteries := make([]*pb.BatteryStatus, len(batteries))
|
||||
for i, b := range batteries {
|
||||
pbBatteries[i] = &pb.BatteryStatus{
|
||||
Component: b.Component,
|
||||
Status: ptr.To(int32(*b.Status)),
|
||||
}
|
||||
}
|
||||
return pbBatteries
|
||||
}
|
||||
|
||||
func nilOrValPtr[T *int32 | *float64](v T) *T {
|
||||
switch T.(type) {
|
||||
case *int32:
|
||||
return v.(*int32)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/state"
|
||||
)
|
||||
|
||||
// TODO: Implement
|
||||
type GRPCWeather struct {
|
||||
ctx context.Context
|
||||
state *state.WeatherState
|
||||
|
Reference in New Issue
Block a user