69 lines
2.2 KiB
Go
69 lines
2.2 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
|
|
}
|
|
|
|
// TODO: Finish Implementing
|
|
func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
|
|
return &pb.WeatherUpdate{
|
|
StationName: u.StationConfig.Name,
|
|
StationType: *u.StationType,
|
|
StationId: *u.StationID,
|
|
TempOutdoorF: u.TempOutdoorF,
|
|
TempIndoorF: u.TempIndoorF,
|
|
HumidityOutdoor: ptr.To(int32(*u.HumidityOudoor)),
|
|
HumidityIndoor: ptr.To(int32(*u.HumidityIndoor)),
|
|
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: 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
|
|
}
|