Skip to content

Commit 390fbcf

Browse files
committed
as: Add metering to normalized uplink
1 parent d1d3a67 commit 390fbcf

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

pkg/messageprocessors/normalizedpayload/uplink.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ type Water struct {
7676
Temperature *float64
7777
}
7878

79+
// WaterMetering is a water metering measurement.
80+
type WaterMetering struct {
81+
Total *float64
82+
}
83+
84+
// Metering is a metering measurement.
85+
type Metering struct {
86+
Water WaterMetering
87+
}
88+
7989
// Position is a position measurement.
8090
type Position struct {
8191
Latitude *float64
@@ -91,6 +101,7 @@ type Measurement struct {
91101
Wind Wind
92102
Rain Rain
93103
Water Water
104+
Metering Metering
94105
Action Action
95106
Position Position
96107
}
@@ -444,6 +455,22 @@ var fieldParsers = map[string]fieldParser{
444455
return &dst.Water.Temperature
445456
},
446457
),
458+
"metering": object(
459+
func(dst *Measurement) *Metering {
460+
return &dst.Metering
461+
},
462+
),
463+
"metering.water": object(
464+
func(dst *Measurement) *WaterMetering {
465+
return &dst.Metering.Water
466+
},
467+
),
468+
"metering.water.total": parseNumber(
469+
func(dst *Measurement) **float64 {
470+
return &dst.Metering.Water.Total
471+
},
472+
minimum(0.0),
473+
),
447474
"action": object(
448475
func(dst *Measurement) *Action {
449476
return &dst.Action

pkg/messageprocessors/normalizedpayload/uplink_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,45 @@ func TestUplink(t *testing.T) {
688688
},
689689
},
690690
},
691+
{
692+
name: "metering",
693+
normalizedPayload: []*structpb.Struct{
694+
{
695+
Fields: map[string]*structpb.Value{
696+
"metering": {
697+
Kind: &structpb.Value_StructValue{
698+
StructValue: &structpb.Struct{
699+
Fields: map[string]*structpb.Value{
700+
"water": {
701+
Kind: &structpb.Value_StructValue{
702+
StructValue: &structpb.Struct{
703+
Fields: map[string]*structpb.Value{
704+
"total": {
705+
Kind: &structpb.Value_NumberValue{
706+
NumberValue: 100.5,
707+
},
708+
},
709+
},
710+
},
711+
},
712+
},
713+
},
714+
},
715+
},
716+
},
717+
},
718+
},
719+
},
720+
expected: []normalizedpayload.Measurement{
721+
{
722+
Metering: normalizedpayload.Metering{
723+
Water: normalizedpayload.WaterMetering{
724+
Total: float64Ptr(100.5),
725+
},
726+
},
727+
},
728+
},
729+
},
691730
} {
692731
tc := tc
693732
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)