Weather service proxy support
All checks were successful
Build and Publish / release (push) Successful in 3m51s

This commit is contained in:
2025-01-12 17:23:32 -05:00
parent 7fc1fc9b56
commit 19823ea08f
13 changed files with 285 additions and 255 deletions

View File

@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/ambient/config"
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider"
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/awn"
"gitea.libretechconsulting.com/rmcguire/ambient-weather-local-exporter/pkg/provider/wunderground"
@ -24,7 +25,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
config *config.AmbientLocalExporterConfig
awnProvider provider.AmbientProvider
wuProvider provider.AmbientProvider
appCtx context.Context
@ -32,7 +33,7 @@ type AmbientWeather struct {
l *zerolog.Logger
}
func New(appCtx context.Context, awConfig *AmbientLocalExporterConfig) *AmbientWeather {
func New(appCtx context.Context, awConfig *config.AmbientLocalExporterConfig) *AmbientWeather {
return &AmbientWeather{
config: awConfig,
appCtx: appCtx,
@ -118,7 +119,7 @@ func (aw *AmbientWeather) handleProviderRequest(
// Proxy update to one or both services if configured to do so
// Uses a weather update to allow awn to publish to wunderground and
// visa versa.
if station := aw.config.GetStation(update.GetStationName()); station != nil {
if station := update.StationConfig; station != nil {
if station.ProxyToAWN {
err := aw.awnProvider.ProxyReq(ctx, update)
if err != nil {
@ -126,14 +127,12 @@ func (aw *AmbientWeather) handleProviderRequest(
}
}
if station.ProxyToWunderground {
err := aw.awnProvider.ProxyReq(ctx, update)
err := aw.wuProvider.ProxyReq(ctx, update)
if err != nil {
zerolog.Ctx(aw.appCtx).Err(err).Msg("failed to proxy to ambient weather")
}
}
}
return
}
func (aw *AmbientWeather) InitMetrics() {
@ -147,13 +146,7 @@ func (aw *AmbientWeather) enrichStation(update *weather.WeatherUpdate) {
if update != nil && update.StationID != nil && *update.StationID != "" {
for _, station := range aw.config.WeatherStations {
if *update.StationID == station.AWNPassKey || *update.StationID == station.WundergroundID {
update.StationInfo = &weather.StationInfo{
Type: update.StationType,
Equipment: &station.Equipment,
Name: &station.Name,
Keep: station.KeepMetrics,
Drop: station.DropMetrics,
}
update.StationConfig = &station
}
}
}