86 lines
2.4 KiB
Go
86 lines
2.4 KiB
Go
package grpc
|
|
|
|
import (
|
|
"k8s.io/utils/ptr"
|
|
|
|
pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
|
)
|
|
|
|
func UpdatesToPbUpdates(u []*weather.WeatherUpdate) []*pb.WeatherUpdate {
|
|
updates := make([]*pb.WeatherUpdate, len(u))
|
|
for i, update := range u {
|
|
updates[i] = UpdateToPbUpdate(update)
|
|
}
|
|
return updates
|
|
}
|
|
|
|
func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
|
|
return &pb.WeatherUpdate{
|
|
StationName: u.StationConfig.Name,
|
|
StationType: derefStr(u.StationType),
|
|
StationId: derefStr(u.StationID),
|
|
TempOutdoorF: u.TempOutdoorF,
|
|
TempIndoorF: u.TempIndoorF,
|
|
HumidityOutdoor: int32ptr(u.HumidityOudoor),
|
|
HumidityIndoor: int32ptr(u.HumidityIndoor),
|
|
WindSpeedMph: u.WindSpeedMPH,
|
|
WindGustMph: u.WindGustMPH,
|
|
MaxDailyGust: u.MaxDailyGust,
|
|
WindDir: int32ptr(u.WindDir),
|
|
WindDirAvg_10M: int32ptr(u.WindDirAvg10m),
|
|
Uv: int32ptr(u.UV),
|
|
SolarRadiation: u.SolarRadiation,
|
|
HourlyRainIn: u.HourlyRainIn,
|
|
EventRainIn: u.EventRainIn,
|
|
DailyRainIn: u.DailyRainIn,
|
|
WeeklyRainIn: u.WeeklyRainIn,
|
|
MonthlyRainIn: u.MonthlyRainIn,
|
|
YearlyRainIn: u.YearlyRainIn,
|
|
TotalRainIn: u.TotalRainIn,
|
|
Batteries: batteriesToPbBatteries(u.Batteries),
|
|
BaromRelativeIn: u.BaromRelativeIn,
|
|
BaromAbsoluteIn: u.BaromAbsoluteIn,
|
|
DewPointF: u.DewPointF,
|
|
WindChillF: u.WindChillF,
|
|
TempHumiditySensors: thSensorsToPbSensors(u.TempHumiditySensors),
|
|
}
|
|
}
|
|
|
|
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: int32ptr(b.Status),
|
|
}
|
|
}
|
|
return pbBatteries
|
|
}
|
|
|
|
func thSensorsToPbSensors(sensors []*weather.TempHumiditySensor) []*pb.TempHumiditySensor {
|
|
pbSensors := make([]*pb.TempHumiditySensor, len(sensors))
|
|
for i, s := range sensors {
|
|
pbSensors[i] = &pb.TempHumiditySensor{
|
|
Name: s.Name,
|
|
TempF: s.TempF,
|
|
Humidity: int32ptr(s.Humidity),
|
|
}
|
|
}
|
|
return pbSensors
|
|
}
|
|
|
|
func derefStr(s *string) string {
|
|
if s == nil {
|
|
return ""
|
|
}
|
|
return *s
|
|
}
|
|
|
|
func int32ptr(i *int) *int32 {
|
|
if i == nil {
|
|
return nil
|
|
}
|
|
return ptr.To(int32(*i))
|
|
}
|