-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_scan_delegate.py
120 lines (103 loc) · 3.67 KB
/
test_scan_delegate.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from scale import Scale
from miScale import ScanDelegate
class TestHandleData(object):
def test_data_not_stabilized_load_removed(self):
# Arrange
input_scale = Scale(
UUID="181d",
address="c8:0f:10:bf:cc:66",
manufacturerData= bytes.fromhex("5701c80f10bfcc66"),
rawData= bytes.fromhex("820000e2070b0f082924"),
)
expected_scale = Scale(
UUID="181d",
address="c8:0f:10:bf:cc:66",
isStabilized=False,
loadRemoved=True,
manufacturerData= bytes.fromhex("5701c80f10bfcc66"),
rawData= bytes.fromhex("820000e2070b0f082924"),
sequence= 10532,
unit= "kg",
weight= 0.0
)
# Act
def callback(result_scale):
# Assert
assert expected_scale == result_scale
delegate = ScanDelegate("c8:0f:10:bf:cc:66", callback, False)
delegate.handleData(input_scale)
def test_data_stabilized_load_not_removed(self):
# Arrange
input_scale = Scale(
UUID="181d",
address="c8:0f:10:bf:cc:66",
manufacturerData= bytes.fromhex("5701c80f10bfcc66"),
rawData= bytes.fromhex("226455e2070b0f0c1d1b"),
)
expected_scale = Scale(
UUID="181d",
address="c8:0f:10:bf:cc:66",
isStabilized=True,
loadRemoved=False,
manufacturerData= bytes.fromhex("5701c80f10bfcc66"),
rawData= bytes.fromhex("226455e2070b0f0c1d1b"),
sequence= 7451,
unit= "kg",
weight= 109.3
)
# Act
def callback(result_scale):
# Assert
assert expected_scale == result_scale
delegate = ScanDelegate("c8:0f:10:bf:cc:66", callback, False)
delegate.handleData(input_scale)
def test_data_stabilized_load_removed(self):
# Arrange
input_scale = Scale(
UUID="181d",
address="c8:0f:10:bf:cc:66",
manufacturerData= bytes.fromhex("5701c80f10bfcc66"),
rawData= bytes.fromhex("a26455e2070b0f082a23"),
)
expected_scale = Scale(
UUID="181d",
address="c8:0f:10:bf:cc:66",
isStabilized=True,
loadRemoved=True,
manufacturerData= bytes.fromhex("5701c80f10bfcc66"),
rawData= bytes.fromhex("a26455e2070b0f082a23"),
sequence= 10787,
unit= "kg",
weight= 109.3
)
# Act
def callback(result_scale):
# Assert
assert expected_scale == result_scale
delegate = ScanDelegate("c8:0f:10:bf:cc:66", callback, False)
delegate.handleData(input_scale)
def test_data_not_stabilized_load_not_removed(self):
# Arrange
input_scale = Scale(
UUID="181d",
address="c8:0f:10:bf:cc:66",
manufacturerData= bytes.fromhex("5701c80f10bfcc66"),
rawData= bytes.fromhex("02e402b2080101010422"),
)
expected_scale = Scale(
UUID="181d",
address="c8:0f:10:bf:cc:66",
isStabilized=False,
loadRemoved=False,
manufacturerData= bytes.fromhex("5701c80f10bfcc66"),
rawData= bytes.fromhex("02e402b2080101010422"),
sequence= 1058,
unit= "kg",
weight= 3.7
)
# Act
def callback(result_scale):
# Assert
assert expected_scale == result_scale
delegate = ScanDelegate("c8:0f:10:bf:cc:66", callback, False)
delegate.handleData(input_scale)