move recorder to interface
This commit is contained in:
@ -1,9 +1,8 @@
|
||||
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/util"
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||
)
|
||||
|
||||
@ -18,18 +17,18 @@ func UpdatesToPbUpdates(u []*weather.WeatherUpdate) []*pb.WeatherUpdate {
|
||||
func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
|
||||
return &pb.WeatherUpdate{
|
||||
StationName: u.StationConfig.Name,
|
||||
StationType: derefStr(u.StationType),
|
||||
StationId: derefStr(u.StationID),
|
||||
StationType: util.DerefStr(u.StationType),
|
||||
StationId: util.DerefStr(u.StationID),
|
||||
TempOutdoorF: u.TempOutdoorF,
|
||||
TempIndoorF: u.TempIndoorF,
|
||||
HumidityOutdoor: int32ptr(u.HumidityOudoor),
|
||||
HumidityIndoor: int32ptr(u.HumidityIndoor),
|
||||
HumidityOutdoor: util.Int32ptr(u.HumidityOudoor),
|
||||
HumidityIndoor: util.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),
|
||||
WindDir: util.Int32ptr(u.WindDir),
|
||||
WindDirAvg_10M: util.Int32ptr(u.WindDirAvg10m),
|
||||
Uv: util.Int32ptr(u.UV),
|
||||
SolarRadiation: u.SolarRadiation,
|
||||
HourlyRainIn: u.HourlyRainIn,
|
||||
EventRainIn: u.EventRainIn,
|
||||
@ -52,7 +51,7 @@ func batteriesToPbBatteries(batteries []weather.BatteryStatus) []*pb.BatteryStat
|
||||
for i, b := range batteries {
|
||||
pbBatteries[i] = &pb.BatteryStatus{
|
||||
Component: b.Component,
|
||||
Status: int32ptr(b.Status),
|
||||
Status: util.Int32ptr(b.Status),
|
||||
}
|
||||
}
|
||||
return pbBatteries
|
||||
@ -64,22 +63,8 @@ func thSensorsToPbSensors(sensors []*weather.TempHumiditySensor) []*pb.TempHumid
|
||||
pbSensors[i] = &pb.TempHumiditySensor{
|
||||
Name: s.Name,
|
||||
TempF: s.TempF,
|
||||
Humidity: int32ptr(s.Humidity),
|
||||
Humidity: util.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))
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func (w *GRPCWeather) GetWeather(ctx context.Context, req *pb.GetWeatherRequest)
|
||||
|
||||
span.SetAttributes(attribute.Int("limit", limit))
|
||||
|
||||
updates, err := w.recorder.Get(ctx, limit)
|
||||
updates, err := w.recorder.Get(ctx, req)
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(otelcodes.Error, err.Error())
|
||||
|
Reference in New Issue
Block a user