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
|
return updates
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Finish Implementing
|
|
||||||
func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
|
func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
|
||||||
return &pb.WeatherUpdate{
|
return &pb.WeatherUpdate{
|
||||||
StationName: u.StationConfig.Name,
|
StationName: u.StationConfig.Name,
|
||||||
StationType: *u.StationType,
|
StationType: derefStr(u.StationType),
|
||||||
StationId: *u.StationID,
|
StationId: derefStr(u.StationID),
|
||||||
TempOutdoorF: u.TempOutdoorF,
|
TempOutdoorF: u.TempOutdoorF,
|
||||||
TempIndoorF: u.TempIndoorF,
|
TempIndoorF: u.TempIndoorF,
|
||||||
HumidityOutdoor: ptr.To(int32(*u.HumidityOudoor)),
|
HumidityOutdoor: int32ptr(u.HumidityOudoor),
|
||||||
HumidityIndoor: ptr.To(int32(*u.HumidityIndoor)),
|
HumidityIndoor: int32ptr(u.HumidityIndoor),
|
||||||
WindSpeedMph: ptr.To(*u.WindSpeedMPH),
|
WindSpeedMph: u.WindSpeedMPH,
|
||||||
WindGustMph: ptr.To(*u.WindGustMPH),
|
WindGustMph: u.WindGustMPH,
|
||||||
MaxDailyGust: ptr.To(*u.MaxDailyGust),
|
MaxDailyGust: u.MaxDailyGust,
|
||||||
WindDir: ptr.To(int32(*u.WindDir)),
|
WindDir: int32ptr(u.WindDir),
|
||||||
WindDirAvg_10M: ptr.To(int32(*u.WindDirAvg10m)),
|
WindDirAvg_10M: int32ptr(u.WindDirAvg10m),
|
||||||
Uv: ptr.To(int32(*u.UV)),
|
Uv: int32ptr(u.UV),
|
||||||
SolarRadiation: ptr.To(*u.SolarRadiation),
|
SolarRadiation: u.SolarRadiation,
|
||||||
HourlyRainIn: ptr.To(*u.HourlyRainIn),
|
HourlyRainIn: u.HourlyRainIn,
|
||||||
EventRainIn: ptr.To(*u.EventRainIn),
|
EventRainIn: u.EventRainIn,
|
||||||
DailyRainIn: ptr.To(*u.DailyRainIn),
|
DailyRainIn: u.DailyRainIn,
|
||||||
WeeklyRainIn: ptr.To(*u.WeeklyRainIn),
|
WeeklyRainIn: u.WeeklyRainIn,
|
||||||
MonthlyRainIn: ptr.To(*u.MonthlyRainIn),
|
MonthlyRainIn: u.MonthlyRainIn,
|
||||||
YearlyRainIn: ptr.To(*u.YearlyRainIn),
|
YearlyRainIn: u.YearlyRainIn,
|
||||||
TotalRainIn: ptr.To(*u.TotalRainIn),
|
TotalRainIn: u.TotalRainIn,
|
||||||
Batteries: []*pb.BatteryStatus{},
|
Batteries: batteriesToPbBatteries(u.Batteries),
|
||||||
BaromRelativeIn: ptr.To(*u.BaromRelativeIn),
|
BaromRelativeIn: u.BaromRelativeIn,
|
||||||
BaromAbsoluteIn: ptr.To(*u.BaromAbsoluteIn),
|
BaromAbsoluteIn: u.BaromAbsoluteIn,
|
||||||
DewPointF: ptr.To(*u.DewPointF),
|
DewPointF: u.DewPointF,
|
||||||
WindChillF: ptr.To(*u.WindChillF),
|
WindChillF: u.WindChillF,
|
||||||
TempHumiditySensors: []*pb.TempHumiditySensor{},
|
TempHumiditySensors: thSensorsToPbSensors(u.TempHumiditySensors),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BatteriesToPbBatteries(batteries []weather.BatteryStatus) []*pb.BatteryStatus {
|
func batteriesToPbBatteries(batteries []weather.BatteryStatus) []*pb.BatteryStatus {
|
||||||
pbBatteries := make([]*pb.BatteryStatus, len(batteries))
|
pbBatteries := make([]*pb.BatteryStatus, len(batteries))
|
||||||
for i, b := range batteries {
|
for i, b := range batteries {
|
||||||
pbBatteries[i] = &pb.BatteryStatus{
|
pbBatteries[i] = &pb.BatteryStatus{
|
||||||
Component: b.Component,
|
Component: b.Component,
|
||||||
Status: ptr.To(int32(*b.Status)),
|
Status: int32ptr(b.Status),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pbBatteries
|
return pbBatteries
|
||||||
}
|
}
|
||||||
|
|
||||||
func nilOrValPtr[T *int32 | *float64](v T) *T {
|
func thSensorsToPbSensors(sensors []*weather.TempHumiditySensor) []*pb.TempHumiditySensor {
|
||||||
switch T.(type) {
|
pbSensors := make([]*pb.TempHumiditySensor, len(sensors))
|
||||||
case *int32:
|
for i, s := range sensors {
|
||||||
return v.(*int32)
|
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