support sensor name mapping
All checks were successful
Build and Publish / release (push) Successful in 4m6s

This commit is contained in:
2025-03-05 12:53:57 -05:00
parent f98a4cf348
commit 29433cddd7
8 changed files with 231 additions and 60 deletions

View File

@ -10,6 +10,7 @@ import (
// Attempts to complete missing fields that may not
// be set by a specific provider, such as DewPoint and WindChill
// TODO: Add span
func (u *WeatherUpdate) Enrich(weatherStations ...*config.WeatherStation) {
if u == nil {
return
@ -49,6 +50,24 @@ func (u *WeatherUpdate) Enrich(weatherStations ...*config.WeatherStation) {
}
}
// Swaps sensor and component names based on
// user provided configuration
func (u *WeatherUpdate) MapSensors() {
if u.StationConfig == nil {
return
}
// Map sensor battery components
for i, batt := range u.Batteries {
u.Batteries[i].Component = u.StationConfig.MapSensor(batt.Component)
}
// Map other sensors
for _, th := range u.TempHumiditySensors {
th.Name = u.StationConfig.MapSensor(th.Name)
}
}
func CalculateDewPoint(tempF, humidity float64) float64 {
// Convert temperature from Fahrenheit to Celsius
tempC := (tempF - 32) * 5 / 9