File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed
pkg/messageprocessors/normalizedpayload Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,16 @@ type Water struct {
76
76
Temperature * float64
77
77
}
78
78
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
+
79
89
// Position is a position measurement.
80
90
type Position struct {
81
91
Latitude * float64
@@ -91,6 +101,7 @@ type Measurement struct {
91
101
Wind Wind
92
102
Rain Rain
93
103
Water Water
104
+ Metering Metering
94
105
Action Action
95
106
Position Position
96
107
}
@@ -444,6 +455,22 @@ var fieldParsers = map[string]fieldParser{
444
455
return & dst .Water .Temperature
445
456
},
446
457
),
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
+ ),
447
474
"action" : object (
448
475
func (dst * Measurement ) * Action {
449
476
return & dst .Action
Original file line number Diff line number Diff line change @@ -688,6 +688,45 @@ func TestUplink(t *testing.T) {
688
688
},
689
689
},
690
690
},
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
+ },
691
730
} {
692
731
tc := tc
693
732
t .Run (tc .name , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments