Skip to content

Commit 0ee2fae

Browse files
committed
test: refactor decode tests
1 parent e07bdf6 commit 0ee2fae

File tree

5 files changed

+59
-106
lines changed

5 files changed

+59
-106
lines changed

tests/unit/test_decode.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import pytest
2+
from typing import ClassVar
3+
4+
import tion_btle
5+
6+
7+
@pytest.mark.parametrize(
8+
"tion_instance, data, result",
9+
[
10+
[
11+
tion_btle.s3.S3,
12+
[0xb3, 0x10, 0x24, 0x14, 0x03, 0x00, 0x15, 0x14, 0x14, 0x8f,
13+
0x00, 0x0c, 0x0a, 0x00, 0x4b, 0x0a, 0x00, 0x33, 0x00, 0x5a],
14+
{
15+
'state': 'on',
16+
'heater': 'on',
17+
'sound': 'off',
18+
'mode': 'outside',
19+
'out_temp': 20,
20+
'in_temp': 20,
21+
'target_temp': 20,
22+
'fan_speed': 4,
23+
'_filter_remain': 143,
24+
'model': 'S3',
25+
}
26+
],
27+
[
28+
tion_btle.lite.Lite,
29+
[0xcf, 0xd8, 0x02, 0x0f, 0x04, 0x09, 0x0f, 0x1a, 0x80, 0x8e, 0x05, 0x00, 0xe9, 0x8b, 0x05, 0x00, 0x17, 0xc2,
30+
0xe7, 0x00, 0x26, 0x1b, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
31+
0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x14, 0x19, 0x02, 0x04, 0x06,
32+
0x06, 0x18, 0x00],
33+
{
34+
'state': 'on',
35+
'heater': 'on',
36+
'sound': 'on',
37+
'mode': 'outside',
38+
'out_temp': 15,
39+
'in_temp': 9,
40+
'target_temp': 15,
41+
'fan_speed': 4,
42+
'_filter_remain': 175.7928587962963,
43+
'model': 'Lite',
44+
'_device_work_time': 18.284884259259258,
45+
'_electronic_work_time': 4.214814814814815,
46+
'_electronic_temp': 26,
47+
'_co2_auto_control': 0,
48+
'_filter_change_required': 0,
49+
'light': 'on',
50+
}
51+
]
52+
]
53+
)
54+
def test_decode(tion_instance: ClassVar[tion_btle.tion.tion], data: bytearray, result: dict):
55+
tion = tion_instance(mac="")
56+
tion._decode_response(data)
57+
for parameter in result.keys():
58+
assert getattr(tion, parameter) == result[parameter]
59+

tests/unit/test_light_decode.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/unit/test_s3_decode.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

tion_btle/lite.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,3 @@ def _packages(self) -> list:
140140
bytearray([0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00]),
141141
bytearray([0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x14, 0x19, 0x02, 0x04, 0x06, 0x06, 0x18, 0x00, 0xb5, 0xad])
142142
]
143-
144-
@property
145-
def _dummy_data(self) -> bytearray:
146-
return bytearray([
147-
0xcf, 0xd8, 0x02, 0x0f, 0x04, 0x09, 0x0f, 0x1a, 0x80, 0x8e, 0x05, 0x00, 0xe9, 0x8b, 0x05, 0x00, 0x17,
148-
0xc2, 0xe7, 0x00, 0x26, 0x1b, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149-
0x00, 0x03, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x14, 0x19,
150-
0x02, 0x04, 0x06, 0x06, 0x18, 0x00
151-
])

tion_btle/s3.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,3 @@ def _encode_request(self, request: dict) -> bytearray:
132132

133133
def _send_request(self, request: bytearray):
134134
self._try_write(request)
135-
136-
@property
137-
def _dummy_data(self) -> bytearray:
138-
return bytearray([0xb3, 0x10, 0x24, 0x14, 0x03, 0x00, 0x15, 0x14, 0x14, 0x8f, 0x00, 0x0c, 0x0a, 0x00, 0x4b,
139-
0x0a, 0x00, 0x33, 0x00, 0x5a])

0 commit comments

Comments
 (0)