map weather update
This commit is contained in:
parent
220cc818e7
commit
133c6f7315
@ -15,54 +15,71 @@ func UpdatesToPbUpdates(u []*weather.WeatherUpdate) []*pb.WeatherUpdate {
|
||||
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,
|
||||
StationType: derefStr(u.StationType),
|
||||
StationId: derefStr(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{},
|
||||
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 {
|
||||
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)),
|
||||
Status: int32ptr(b.Status),
|
||||
}
|
||||
}
|
||||
return pbBatteries
|
||||
}
|
||||
|
||||
func nilOrValPtr[T *int32 | *float64](v T) *T {
|
||||
switch T.(type) {
|
||||
case *int32:
|
||||
return v.(*int32)
|
||||
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 nil
|
||||
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))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user