This repository was archived by the owner on May 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathobis_parser_test.go
79 lines (66 loc) · 1.68 KB
/
obis_parser_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"bytes"
"context"
"github.com/stretchr/testify/assert"
"sync"
"testing"
)
const invalidMsg = `
.0*255(228.3*V)
1-0:96.5.0*255(001C0104)
0-0:96.8.0*255(00F1AD31)
!
`
const singleValidMsg = `
/EZB23092834
1-0:0.0.0*255(1EBZ0100183277)
1-0:96.1.0*255(1EBZ0100183277)
1-0:1.8.0*255(002236.29107286*kWh)
1-0:1.8.1*255(001236.29107286*kWh)
1-0:1.8.2*255(002136.29107286*kWh)
1-0:2.8.0*255(002130.29107286*kWh)
1-0:16.7.0*255(000550.25*W)
1-0:36.7.0*255(000322.14*W)
1-0:56.7.0*255(000052.55*W)
1-0:76.7.0*255(000175.56*W)
1-0:32.7.0*255(227.6*V)
1-0:52.7.0*255(229.3*V)
1-0:72.7.0*255(228.3*V)
1-0:96.5.0*255(001C0104)
0-0:96.8.0*255(00F1AD31)
!
`
func TestObisParser_ParseValid(t *testing.T) {
as := assert.New(t)
parser := NewObisParser(context.Background())
wg := sync.WaitGroup{}
wg.Add(1)
parser.Parse(bytes.NewReader([]byte(singleValidMsg)), func(measurement Measurement, err error) {
as.NoError(err)
as.Equal(2130.29107286, measurement.TotalKwhNeg)
as.Equal(2236.29107286, measurement.TotalKwhPos)
as.Equal(1236.29107286, measurement.TotalT1KwhPos)
as.Equal(2136.29107286, measurement.TotalT2KwhPos)
as.Equal(550.25, measurement.PTotal)
as.Equal(322.14, measurement.P1)
as.Equal(52.55, measurement.P2)
as.Equal(175.56, measurement.P3)
as.Equal(227.6, measurement.V1)
as.Equal(229.3, measurement.V2)
as.Equal(228.3, measurement.V3)
wg.Done()
})
wg.Wait()
}
func TestObisParser_ParseInvalid(t *testing.T) {
as := assert.New(t)
parser := NewObisParser(context.Background())
wg := sync.WaitGroup{}
wg.Add(1)
parser.Parse(bytes.NewReader([]byte(invalidMsg)), func(measurement Measurement, err error) {
as.Error(err)
wg.Done()
})
wg.Wait()
}