-
Notifications
You must be signed in to change notification settings - Fork 3
/
vallox_test.go
101 lines (88 loc) · 2.63 KB
/
vallox_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package valloxrs485
import (
"testing"
"time"
)
func TestOutGoingAllowed(t *testing.T) {
v := new(Vallox)
assertBoolean(true, isOutgoingAllowed(v, 0), t)
assertBoolean(false, isOutgoingAllowed(v, FanSpeed), t)
assertBoolean(false, isOutgoingAllowed(v, TempIncomingInside), t)
v.writeAllowed = true
assertBoolean(true, isOutgoingAllowed(v, 0), t)
assertBoolean(true, isOutgoingAllowed(v, FanSpeed), t)
assertBoolean(false, isOutgoingAllowed(v, TempIncomingInside), t)
}
func TestValueToTemp(t *testing.T) {
assertTemp(0, -74, t)
assertTemp(255, 100, t)
assertTemp(246, 97, t)
assertTemp(247, 100, t)
}
func TestValueToSpeed(t *testing.T) {
assertSpeed(1, 1, t)
assertSpeed(3, 2, t)
assertSpeed(7, 3, t)
assertSpeed(15, 4, t)
assertSpeed(31, 5, t)
assertSpeed(63, 6, t)
assertSpeed(127, 7, t)
assertSpeed(255, 8, t)
}
func assertBoolean(expected bool, value bool, t *testing.T) {
if expected != value {
t.Errorf("exptected %v got %v", expected, value)
}
}
func assertTemp(raw byte, value int16, t *testing.T) {
if c, _ := valueToTemp(raw, nil); c != value {
t.Errorf("temp %d was not converted to %d but to %d", raw, value, c)
}
}
func assertSpeed(raw byte, value int16, t *testing.T) {
if c, _ := valueToSpeed(raw, nil); c != value {
t.Errorf("raw %d to speed was not converted to %d but to %d", raw, value, c)
}
if c := speedToValue(int8(value)); c != raw {
t.Errorf("speed %d to raw was not converted to %d but to %d", value, raw, c)
}
}
func TestValueToRh(t *testing.T) {
assertRh(t, 0x33, 0)
assertRh(t, 0xff, 100)
assertRh(t, 0x99, 50)
if _, ok := valueToRh(0x32, nil); ok {
t.Errorf("vallox rh 0x32 expected !ok, but was ok")
}
}
func assertRh(t *testing.T, valloxValue byte, rh int16) {
if v, _ := valueToRh(valloxValue, nil); v != rh {
t.Errorf("vallox rh %d expexted rh %d but was %d", valloxValue, rh, v)
}
}
func TestValueToCo2(t *testing.T) {
v := new(Vallox)
e := event(&valloxPackage{Register: Co2HighestHighByte, Value: 1}, v)
if e != nil {
t.Errorf("expected no value, but got one")
}
e = event(&valloxPackage{Register: Co2HighestLowByte, Value: 0xf4}, v)
if e.Value != 0x1f4 {
t.Errorf("expected 0x1fe but got %x", e.Value)
}
if e.Register != Co2HighestLowByte {
t.Errorf("expected register %d but got %d", Co2HighestLowByte, e.Register)
}
}
func TestDelayedToCo2(t *testing.T) {
v := new(Vallox)
e := event(&valloxPackage{Register: Co2HighestHighByte, Value: 1}, v)
if e != nil {
t.Errorf("expected no value, but got one")
}
time.Sleep(600 * time.Millisecond)
e = event(&valloxPackage{Register: Co2HighestLowByte, Value: 0xf4}, v)
if e != nil {
t.Errorf("expected no value, but got one")
}
}