-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add ed device testcase, to be done
- Loading branch information
Showing
1 changed file
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,350 @@ | ||
"""Test ED message.""" | ||
|
||
import pytest | ||
|
||
from midealocal.devices.ed.message import ( | ||
EDMessageBody01, | ||
EDMessageBody03, | ||
EDMessageBody05, | ||
EDMessageBody06, | ||
EDMessageBody07, | ||
EDMessageBodyFF, | ||
MessageEDBase, | ||
MessageEDResponse, | ||
MessageNewSet, | ||
MessageQuery, | ||
) | ||
|
||
|
||
class TestMessageEDBase: | ||
"""Test ED Message Base.""" | ||
|
||
def test_body_not_implemented(self) -> None: | ||
"""Test body not implemented.""" | ||
msg = MessageEDBase(protocol_version=1, message_type=1, body_type=1) | ||
with pytest.raises(NotImplementedError): | ||
_ = msg.body | ||
|
||
|
||
class TestMessageQuery: | ||
"""Test Message Query.""" | ||
|
||
def test_query_body(self) -> None: | ||
"""Test query body.""" | ||
query = MessageQuery(protocol_version=1, body_type=2) | ||
expected_body = bytearray([0x02, 0x01]) | ||
assert query.body == expected_body | ||
|
||
|
||
class TestMessageNewSet: | ||
"""Test MessageNewSet.""" | ||
|
||
def test_message_newset(self) -> None: | ||
"""Test MessageNewSet.""" | ||
new_set = MessageNewSet(protocol_version=1) | ||
expected_body = bytearray([0x15, 0x01, 0x00]) | ||
assert new_set.body == expected_body | ||
new_set.power = True | ||
expected_body = bytearray([0x15, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00]) | ||
assert new_set.body == expected_body | ||
new_set.lock = True | ||
expected_body = bytearray( | ||
[ | ||
0x15, | ||
0x01, | ||
0x02, | ||
0x00, | ||
0x01, | ||
0x01, | ||
0x00, | ||
0x00, | ||
0x01, | ||
0x02, | ||
0x01, | ||
0x00, | ||
0x00, | ||
], | ||
) | ||
assert new_set.body == expected_body | ||
new_set.power = None | ||
expected_body = bytearray([0x15, 0x01, 0x01, 0x01, 0x02, 0x01, 0x00, 0x00]) | ||
assert new_set.body == expected_body | ||
|
||
|
||
class TestEDMessageBody01: | ||
"""Test EDMessageBody01.""" | ||
|
||
def test_ed_message_body01(self) -> None: | ||
"""Test EDMessageBody01.""" | ||
body = bytearray(40) | ||
body[0] = 0x01 # Body Type | ||
body[2] = 1 # Set power to True | ||
body[7] = 2 # Set water_consumption bit1 | ||
body[8] = 3 # Set water_consumption bit2 | ||
body[36] = 4 # Set in_tds bit1 | ||
body[37] = 5 # Set in_tds bit2 | ||
body[38] = 6 # Set out_tds bit1 | ||
body[39] = 7 # Set out_tds bit2 | ||
body[15] = 7 # Set child_lock | ||
body[25] = 4 # Set filter1 bit1 | ||
body[26] = 5 # Set filter1 bit2 | ||
body[27] = 5 # Set filter2 bit1 | ||
body[28] = 6 # Set filter2 bit2 | ||
body[29] = 6 # Set filter3 bit1 | ||
body[30] = 7 # Set filter3 bit2 | ||
body[16] = 2 # Set life1 | ||
body[17] = 3 # Set life2 | ||
body[18] = 4 # Set life3 | ||
message_body = EDMessageBody01(body=body) | ||
assert hasattr(message_body, "body_type") | ||
assert message_body.body_type == 1 | ||
assert hasattr(message_body, "power") | ||
assert message_body.power | ||
assert hasattr(message_body, "water_consumption") | ||
assert message_body.water_consumption == 770 | ||
assert hasattr(message_body, "in_tds") | ||
assert message_body.in_tds == 1284 | ||
assert hasattr(message_body, "out_tds") | ||
assert message_body.out_tds == 1798 | ||
assert hasattr(message_body, "child_lock") | ||
assert message_body.child_lock | ||
assert hasattr(message_body, "filter1") | ||
assert message_body.filter1 == 54 | ||
assert hasattr(message_body, "filter2") | ||
assert message_body.filter2 == 64 | ||
assert hasattr(message_body, "filter3") | ||
assert message_body.filter3 == 75 | ||
assert hasattr(message_body, "life1") | ||
assert message_body.life1 == 2 | ||
assert hasattr(message_body, "life2") | ||
assert message_body.life2 == 3 | ||
assert hasattr(message_body, "life3") | ||
assert message_body.life3 == 4 | ||
|
||
|
||
class TestEDMessageBody03: | ||
"""Test EDMessageBody03.""" | ||
|
||
def test_ed_message_body03(self) -> None: | ||
"""Test EDMessageBody03.""" | ||
body = bytearray(52) | ||
body[0] = 0x03 # Body Type | ||
body[51] = 1 # Set power to True | ||
body[20] = 2 # Set water_consumption bit1 | ||
body[21] = 3 # Set water_consumption bit2 | ||
body[27] = 4 # Set in_tds bit1 | ||
body[28] = 5 # Set in_tds bit2 | ||
body[29] = 6 # Set out_tds bit1 | ||
body[30] = 7 # Set out_tds bit2 | ||
body[22] = 2 # Set life1 | ||
body[23] = 3 # Set life2 | ||
body[24] = 4 # Set life3 | ||
message_body = EDMessageBody03(body=body) | ||
assert hasattr(message_body, "body_type") | ||
assert message_body.body_type == 3 | ||
assert hasattr(message_body, "power") | ||
assert message_body.power | ||
assert hasattr(message_body, "water_consumption") | ||
assert message_body.water_consumption == 770 | ||
assert hasattr(message_body, "in_tds") | ||
assert message_body.in_tds == 1284 | ||
assert hasattr(message_body, "out_tds") | ||
assert message_body.out_tds == 1798 | ||
assert hasattr(message_body, "child_lock") | ||
assert not message_body.child_lock | ||
assert hasattr(message_body, "life1") | ||
assert message_body.life1 == 2 | ||
assert hasattr(message_body, "life2") | ||
assert message_body.life2 == 3 | ||
assert hasattr(message_body, "life3") | ||
assert message_body.life3 == 4 | ||
|
||
|
||
class TestEDMessageBody05: | ||
"""Test EDMessageBody05.""" | ||
|
||
def test_ed_message_body05(self) -> None: | ||
"""Test EDMessageBody05.""" | ||
body = bytearray(52) | ||
body[0] = 0x05 # Body Type | ||
body[51] = 1 # Set power to True | ||
body[20] = 2 # Set water_consumption bit1 | ||
body[21] = 3 # Set water_consumption bit2 | ||
message_body = EDMessageBody05(body=body) | ||
assert hasattr(message_body, "body_type") | ||
assert message_body.body_type == 5 | ||
assert hasattr(message_body, "power") | ||
assert message_body.power | ||
assert hasattr(message_body, "water_consumption") | ||
assert message_body.water_consumption == 770 | ||
assert hasattr(message_body, "child_lock") | ||
assert not message_body.child_lock | ||
|
||
|
||
class TestEDMessageBody06: | ||
"""Test EDMessageBody06.""" | ||
|
||
def test_ed_message_body06(self) -> None: | ||
"""Test EDMessageBody06.""" | ||
body = bytearray(52) | ||
body[0] = 0x06 # Body Type | ||
body[51] = 1 # Set power to True | ||
body[25] = 2 # Set water_consumption bit1 | ||
body[26] = 3 # Set water_consumption bit2 | ||
message_body = EDMessageBody06(body=body) | ||
assert hasattr(message_body, "body_type") | ||
assert message_body.body_type == 6 | ||
assert hasattr(message_body, "power") | ||
assert message_body.power | ||
assert hasattr(message_body, "water_consumption") | ||
assert message_body.water_consumption == 770 | ||
assert hasattr(message_body, "child_lock") | ||
assert not message_body.child_lock | ||
|
||
|
||
class TestEDMessageBody07: | ||
"""Test EDMessageBody07.""" | ||
|
||
def test_ed_message_body07(self) -> None: | ||
"""Test EDMessageBody07.""" | ||
body = bytearray(52) | ||
body[0] = 0x07 # Body Type | ||
body[51] = 1 # Set power to True | ||
body[20] = 2 # Set water_consumption bit1 | ||
body[21] = 3 # Set water_consumption bit2 | ||
message_body = EDMessageBody07(body=body) | ||
assert hasattr(message_body, "body_type") | ||
assert message_body.body_type == 7 | ||
assert hasattr(message_body, "power") | ||
assert message_body.power | ||
assert hasattr(message_body, "water_consumption") | ||
assert message_body.water_consumption == 770 | ||
assert hasattr(message_body, "child_lock") | ||
assert not message_body.child_lock | ||
|
||
|
||
class TestEDMessageBodyFF: | ||
"""Test EDMessageBodyFF.""" | ||
|
||
def test_ed_message_body_ff(self) -> None: | ||
"""Test EDMessageBodyFF.""" | ||
body = bytearray( | ||
[ | ||
0xFF, # body_type | ||
0x01, | ||
0x07, # category | ||
0x00, # part 1, offset+1, attr bit1, test 0x00/CHILD_LOCK | ||
0x40, # part 1, offset+2, attr bit2 and length bit | ||
0x00, # part 1, offset+3, | ||
0x00, # part 1, offset+4, | ||
0x01, # part 1, offset+5, child_lock | ||
0x01, # part 1, offset+6, power | ||
0x10, # part 2, offset+1, attr bit1, test 0x10/LIFE | ||
0x40, # part 2, offset+2, attr bit2 and length bit | ||
0x01, # part 2, offset+3, life1 | ||
0x02, # part 2, offset+4, life2 | ||
0x03, # part 2, offset+5, life3 | ||
0x00, # part 2, | ||
0x11, # part 3, offset+1, attr bit1, test 0x11/WATER_CONSUMPTION | ||
0x40, # part 3, offset+2, attr bit2 and length bit | ||
0x01, # part 3, offset+3, water_consumption bit1 | ||
0x02, # part 3, offset+4, water_consumption bit2 | ||
0x03, # part 3, offset+5, water_consumption bit3 | ||
0x04, # part 3, offset+6, water_consumption bit4 | ||
0x13, # part 4, offset+1, attr bit1, test 0x13/TDS | ||
0x40, # part 4, offset+2, attr bit2 and length bit | ||
0x04, # part 4, offset+3, in_tds bit1 | ||
0x03, # part 4, offset+4, in_tds bit2 | ||
0x02, # part 4, offset+5, out_tds bit1 | ||
0x01, # part 4, offset+6, out_tds bit2 | ||
], | ||
) | ||
|
||
message_body = EDMessageBodyFF(body=body) | ||
assert hasattr(message_body, "body_type") | ||
assert message_body.body_type == 255 | ||
assert hasattr(message_body, "power") | ||
assert message_body.power | ||
assert hasattr(message_body, "water_consumption") | ||
assert message_body.water_consumption == 67305.985 | ||
assert hasattr(message_body, "in_tds") | ||
assert message_body.in_tds == 772 | ||
assert hasattr(message_body, "out_tds") | ||
assert message_body.out_tds == 258 | ||
assert hasattr(message_body, "child_lock") | ||
assert message_body.child_lock | ||
assert hasattr(message_body, "life1") | ||
assert message_body.life1 == 1 | ||
assert hasattr(message_body, "life2") | ||
assert message_body.life2 == 2 | ||
assert hasattr(message_body, "life3") | ||
assert message_body.life3 == 3 | ||
|
||
|
||
class TestMessageEDResponse: | ||
"""Test Message ED Response.""" | ||
|
||
def test_ed_general_response(self) -> None: | ||
"""Test general response.""" | ||
header = bytearray( | ||
[ | ||
0xAA, | ||
0x00, | ||
0xDA, | ||
0x00, | ||
0x00, | ||
0x00, | ||
0x00, | ||
0x00, | ||
0x01, | ||
0x03, | ||
], | ||
) | ||
body = bytearray(26) | ||
body[0] = 0x04 # Body Type | ||
body[1] = 1 # Set power to True | ||
body[2] = 2 # Set start condition to True | ||
body[24] = 10 # Mock error_code | ||
body[4] = 5 # Mock program | ||
body[9] = 30 # Mock wash_time | ||
body[12] = 10 # Mock soak_time | ||
body[10] = (2 << 4) | 3 # Mock dehydration_time and rinse_count | ||
body[6] = (3 << 4) | 2 # Mock dehydration_speed and wash_strength | ||
body[5] = (4 << 4) | 1 # Mock rinse_level and wash_level | ||
body[8] = (5 << 4) | 4 # Mock softener and detergent | ||
body[16] = 2 << 1 # Mock progress | ||
body[17] = 15 # Mock time_remaining lower byte | ||
body[18] = 1 # Mock time_remaining upper byte | ||
response = MessageEDResponse(header + body) | ||
assert hasattr(response, "power") | ||
assert response.power | ||
assert hasattr(response, "start") | ||
assert response.start | ||
assert hasattr(response, "error_code") | ||
assert response.error_code == 10 | ||
assert hasattr(response, "program") | ||
assert response.program == 5 | ||
assert hasattr(response, "wash_time") | ||
assert response.wash_time == 30 | ||
assert hasattr(response, "soak_time") | ||
assert response.soak_time == 10 | ||
assert hasattr(response, "dehydration_time") | ||
assert response.dehydration_time == 2 | ||
assert hasattr(response, "dehydration_speed") | ||
assert response.dehydration_speed == 3 | ||
assert hasattr(response, "rinse_count") | ||
assert response.rinse_count == 3 | ||
assert hasattr(response, "rinse_level") | ||
assert response.rinse_level == 4 | ||
assert hasattr(response, "wash_level") | ||
assert response.wash_level == 1 | ||
assert hasattr(response, "wash_strength") | ||
assert response.wash_strength == 2 | ||
assert hasattr(response, "softener") | ||
assert response.softener == 5 | ||
assert hasattr(response, "detergent") | ||
assert response.detergent == 4 | ||
assert hasattr(response, "progress") | ||
assert response.progress == 2 | ||
assert hasattr(response, "time_remaining") | ||
assert response.time_remaining == 15 + 60 |