add lightning sensor
Some checks failed
Build and Publish / check-chart (push) Successful in 15s
Build and Publish / helm-release (push) Has been skipped
Build and Publish / release (push) Failing after 1m14s

This commit is contained in:
Ryan McGuire 2025-04-02 20:09:44 -04:00
parent 35374ab6e0
commit 53c22ab8c7
6 changed files with 84 additions and 46 deletions

View File

@ -296,6 +296,8 @@ type WeatherUpdate struct {
WindChillF *float64 `protobuf:"fixed64,26,opt,name=wind_chill_f,json=windChillF,proto3,oneof" json:"wind_chill_f,omitempty"`
TempHumiditySensors []*TempHumiditySensor `protobuf:"bytes,27,rep,name=temp_humidity_sensors,json=tempHumiditySensors,proto3" json:"temp_humidity_sensors,omitempty"`
UpdateTimestamp *timestamppb.Timestamp `protobuf:"bytes,28,opt,name=update_timestamp,json=updateTimestamp,proto3" json:"update_timestamp,omitempty"`
LightningDay *int32 `protobuf:"varint,29,opt,name=lightning_day,json=lightningDay,proto3,oneof" json:"lightning_day,omitempty"`
LightningDistance *int32 `protobuf:"varint,30,opt,name=lightning_distance,json=lightningDistance,proto3,oneof" json:"lightning_distance,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -526,6 +528,20 @@ func (x *WeatherUpdate) GetUpdateTimestamp() *timestamppb.Timestamp {
return nil
}
func (x *WeatherUpdate) GetLightningDay() int32 {
if x != nil && x.LightningDay != nil {
return *x.LightningDay
}
return 0
}
func (x *WeatherUpdate) GetLightningDistance() int32 {
if x != nil && x.LightningDistance != nil {
return *x.LightningDistance
}
return 0
}
// Represents a temperature and humidity sensor
type TempHumiditySensor struct {
state protoimpl.MessageState `protogen:"open.v1"`
@ -660,7 +676,7 @@ const file_weather_weather_proto_rawDesc = "" +
"\fstation_name\x18\x01 \x01(\tH\x00R\vstationName\x88\x01\x01\x12&\n" +
"\fstation_type\x18\x02 \x01(\tH\x01R\vstationType\x88\x01\x01B\x0f\n" +
"\r_station_nameB\x0f\n" +
"\r_station_type\"\xfe\f\n" +
"\r_station_type\"\x85\x0e\n" +
"\rWeatherUpdate\x12!\n" +
"\fstation_name\x18\x01 \x01(\tR\vstationName\x12!\n" +
"\fstation_type\x18\x02 \x01(\tR\vstationType\x12\x1d\n" +
@ -693,7 +709,9 @@ const file_weather_weather_proto_rawDesc = "" +
"\fwind_chill_f\x18\x1a \x01(\x01H\x15R\n" +
"windChillF\x88\x01\x01\x12W\n" +
"\x15temp_humidity_sensors\x18\x1b \x03(\v2#.ambient.weather.TempHumiditySensorR\x13tempHumiditySensors\x12E\n" +
"\x10update_timestamp\x18\x1c \x01(\v2\x1a.google.protobuf.TimestampR\x0fupdateTimestampB\x11\n" +
"\x10update_timestamp\x18\x1c \x01(\v2\x1a.google.protobuf.TimestampR\x0fupdateTimestamp\x12(\n" +
"\rlightning_day\x18\x1d \x01(\x05H\x16R\flightningDay\x88\x01\x01\x122\n" +
"\x12lightning_distance\x18\x1e \x01(\x05H\x17R\x11lightningDistance\x88\x01\x01B\x11\n" +
"\x0f_temp_outdoor_fB\x10\n" +
"\x0e_temp_indoor_fB\x13\n" +
"\x11_humidity_outdoorB\x12\n" +
@ -715,7 +733,9 @@ const file_weather_weather_proto_rawDesc = "" +
"\x12_barom_relative_inB\x14\n" +
"\x12_barom_absolute_inB\x0e\n" +
"\f_dew_point_fB\x0f\n" +
"\r_wind_chill_f\"}\n" +
"\r_wind_chill_fB\x10\n" +
"\x0e_lightning_dayB\x15\n" +
"\x13_lightning_distance\"}\n" +
"\x12TempHumiditySensor\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name\x12\x1a\n" +
"\x06temp_f\x18\x02 \x01(\x01H\x00R\x05tempF\x88\x01\x01\x12\x1f\n" +

View File

@ -308,6 +308,14 @@
"updateTimestamp": {
"type": "string",
"format": "date-time"
},
"lightningDay": {
"type": "integer",
"format": "int32"
},
"lightningDistance": {
"type": "integer",
"format": "int32"
}
}
}

View File

@ -59,6 +59,8 @@ func UpdateToPbUpdate(u *weather.WeatherUpdate) *pb.WeatherUpdate {
WindChillF: u.WindChillF,
TempHumiditySensors: thSensorsToPbSensors(u.TempHumiditySensors),
UpdateTimestamp: timestamppb.New(*u.DateUTC),
LightningDay: util.Int32ptr(u.LightningDay),
LightningDistance: util.Int32ptr(u.LightningDistance),
}
}

View File

@ -52,6 +52,10 @@ var mockUpdate = &weather.WeatherUpdate{
TempHumiditySensors: []*weather.TempHumiditySensor{
{Name: "sensor1", TempF: ptr.To(99.999), Humidity: nil},
},
LightningData: &weather.LightningData{
LightningDay: ptr.To(1),
LightningDistance: ptr.To(20),
},
}
func TestUpdateToPbUpdate(t *testing.T) {

View File

@ -78,8 +78,10 @@ func (wm *WeatherMetrics) Update(u *WeatherUpdate) {
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.BaromAbsoluteIn, FloatVal: u.BaromAbsoluteIn, Field: FieldBaromAbsoluteIn, Attributes: attributes, Station: u.StationConfig})
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.DewPointF, FloatVal: u.DewPointF, Field: FieldDewPointF, Attributes: attributes, Station: u.StationConfig})
wm.recorder.Record(&RecordOpts{Float64Gauge: wm.WindChillF, FloatVal: u.WindChillF, Field: FieldWindChillF, Attributes: attributes, Station: u.StationConfig})
lightningAttributes := append(attributes, attribute.String("unit", "km"))
wm.recorder.Record(&RecordOpts{Int64Gauge: wm.LightningLastDistance, IntVal: u.LightningDistance, Field: FieldLightningDistance, Attributes: lightningAttributes, Station: u.StationConfig})
wm.recorder.Record(&RecordOpts{Int64Gauge: wm.LightningCountDay, IntVal: u.LightningDay, Field: FieldLightningDay, Attributes: attributes, Station: u.StationConfig})
wm.recorder.Record(&RecordOpts{Int64Gauge: wm.LightningLastDistance, IntVal: u.LightningDistance, Field: FieldLightningDistance, Attributes: attributes, Station: u.StationConfig})
wm.RecordBatteries(u, attributes)
wm.RecordTempHumiditySensors(u, attributes)

View File

@ -57,6 +57,8 @@ message WeatherUpdate {
optional double wind_chill_f = 26;
repeated TempHumiditySensor temp_humidity_sensors = 27;
google.protobuf.Timestamp update_timestamp = 28;
optional int32 lightning_day = 29;
optional int32 lightning_distance = 30;
}
// Represents a temperature and humidity sensor