skip nil sensors data in grpc
This commit is contained in:
		
							
								
								
									
										5
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								TODO.md
									
									
									
									
									
								
							@@ -1,13 +1,14 @@
 | 
				
			|||||||
# Issues
 | 
					# Issues
 | 
				
			||||||
- [ ] Redis recorder panic
 | 
					- [x] Redis recorder panic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# TODO
 | 
					# TODO
 | 
				
			||||||
 | 
					- [ ] Stop Marshaling sensors / batteries with no data
 | 
				
			||||||
- [ ] Add json schema to CI and README
 | 
					- [ ] Add json schema to CI and README
 | 
				
			||||||
- [ ] Finish implementing weather GRPC
 | 
					 | 
				
			||||||
- [ ] Update README
 | 
					- [ ] Update README
 | 
				
			||||||
- [ ] Add Grafana dashboard
 | 
					- [ ] Add Grafana dashboard
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Done
 | 
					## Done
 | 
				
			||||||
 | 
					- [x] Finish implementing weather GRPC
 | 
				
			||||||
- [x] Add json schema for config
 | 
					- [x] Add json schema for config
 | 
				
			||||||
- [x] Add new spans
 | 
					- [x] Add new spans
 | 
				
			||||||
- [x] Helm Chart
 | 
					- [x] Helm Chart
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,8 @@
 | 
				
			|||||||
package grpc
 | 
					package grpc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"slices"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
 | 
						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/util"
 | 
				
			||||||
	"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
 | 
						"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
 | 
				
			||||||
@@ -47,24 +49,28 @@ func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func batteriesToPbBatteries(batteries []weather.BatteryStatus) []*pb.BatteryStatus {
 | 
					func batteriesToPbBatteries(batteries []weather.BatteryStatus) []*pb.BatteryStatus {
 | 
				
			||||||
	pbBatteries := make([]*pb.BatteryStatus, len(batteries))
 | 
						pbBatteries := make([]*pb.BatteryStatus, 0, len(batteries))
 | 
				
			||||||
	for i, b := range batteries {
 | 
						for _, b := range batteries {
 | 
				
			||||||
		pbBatteries[i] = &pb.BatteryStatus{
 | 
							if b.Status != nil {
 | 
				
			||||||
 | 
								pbBatteries = append(pbBatteries, &pb.BatteryStatus{
 | 
				
			||||||
				Component: b.Component,
 | 
									Component: b.Component,
 | 
				
			||||||
				Status:    util.Int32ptr(b.Status),
 | 
									Status:    util.Int32ptr(b.Status),
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return pbBatteries
 | 
						return slices.Clip(pbBatteries)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func thSensorsToPbSensors(sensors []*weather.TempHumiditySensor) []*pb.TempHumiditySensor {
 | 
					func thSensorsToPbSensors(sensors []*weather.TempHumiditySensor) []*pb.TempHumiditySensor {
 | 
				
			||||||
	pbSensors := make([]*pb.TempHumiditySensor, len(sensors))
 | 
						pbSensors := make([]*pb.TempHumiditySensor, 0, len(sensors))
 | 
				
			||||||
	for i, s := range sensors {
 | 
						for _, s := range sensors {
 | 
				
			||||||
		pbSensors[i] = &pb.TempHumiditySensor{
 | 
							if s.TempF != nil || s.Humidity != nil {
 | 
				
			||||||
 | 
								pbSensors = append(pbSensors, &pb.TempHumiditySensor{
 | 
				
			||||||
				Name:     s.Name,
 | 
									Name:     s.Name,
 | 
				
			||||||
				TempF:    s.TempF,
 | 
									TempF:    s.TempF,
 | 
				
			||||||
				Humidity: util.Int32ptr(s.Humidity),
 | 
									Humidity: util.Int32ptr(s.Humidity),
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return pbSensors
 | 
						return slices.Clip(pbSensors)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,7 +77,7 @@ func (r *RedisRecorder) get(ctx context.Context, req *pb.GetWeatherRequest) (
 | 
				
			|||||||
		Int("updatesFiltered", len(updates)-len(filtered)).
 | 
							Int("updatesFiltered", len(updates)-len(filtered)).
 | 
				
			||||||
		Msg("updates retrieved from redis")
 | 
							Msg("updates retrieved from redis")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return updates, err
 | 
						return filtered, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func jsonDatasToUpdates(datas []string) ([]*weather.WeatherUpdate, error) {
 | 
					func jsonDatasToUpdates(datas []string) ([]*weather.WeatherUpdate, error) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user