|
1 | | -"""ATA tests.""" |
2 | | -import json |
3 | | -import os |
4 | | - |
5 | | -import pytest |
6 | | -from asynctest import CoroutineMock, Mock, patch |
| 1 | +"""ATA tests.""" |
| 2 | +import json |
| 3 | +import os |
| 4 | + |
| 5 | +import pytest |
| 6 | +from asynctest import CoroutineMock, Mock, patch |
7 | 7 | from pymelcloud import DEVICE_TYPE_ATA |
8 | 8 | from pymelcloud.ata_device import ( |
9 | 9 | OPERATION_MODE_HEAT, |
|
32 | 32 | ) |
33 | 33 |
|
34 | 34 |
|
35 | | -def _build_device(device_conf_name: str, device_state_name: str) -> AtaDevice: |
36 | | - test_dir = os.path.join(os.path.dirname(__file__), "samples") |
37 | | - with open(os.path.join(test_dir, device_conf_name), "r") as json_file: |
38 | | - device_conf = json.load(json_file) |
39 | | - |
40 | | - with open(os.path.join(test_dir, device_state_name), "r") as json_file: |
41 | | - device_state = json.load(json_file) |
42 | | - |
43 | | - with patch("pymelcloud.client.Client") as _client: |
44 | | - _client.update_confs = CoroutineMock() |
45 | | - _client.device_confs.__iter__ = Mock(return_value=[device_conf].__iter__()) |
46 | | - _client.fetch_device_units = CoroutineMock(return_value=[]) |
47 | | - _client.fetch_device_state = CoroutineMock(return_value=device_state) |
48 | | - client = _client |
49 | | - |
50 | | - return AtaDevice(device_conf, client) |
51 | | - |
52 | | -@pytest.mark.asyncio |
53 | | -async def test_ata(): |
54 | | - device = _build_device("ata_listdevice.json", "ata_get.json") |
55 | | - |
56 | | - assert device.name == "" |
57 | | - assert device.device_type == DEVICE_TYPE_ATA |
| 35 | +def _build_device(device_conf_name: str, device_state_name: str) -> AtaDevice: |
| 36 | + test_dir = os.path.join(os.path.dirname(__file__), "samples") |
| 37 | + with open(os.path.join(test_dir, device_conf_name), "r") as json_file: |
| 38 | + device_conf = json.load(json_file) |
| 39 | + |
| 40 | + with open(os.path.join(test_dir, device_state_name), "r") as json_file: |
| 41 | + device_state = json.load(json_file) |
| 42 | + |
| 43 | + with patch("pymelcloud.client.Client") as _client: |
| 44 | + _client.update_confs = CoroutineMock() |
| 45 | + _client.device_confs.__iter__ = Mock(return_value=[device_conf].__iter__()) |
| 46 | + _client.fetch_device_units = CoroutineMock(return_value=[]) |
| 47 | + _client.fetch_device_state = CoroutineMock(return_value=device_state) |
| 48 | + client = _client |
| 49 | + |
| 50 | + return AtaDevice(device_conf, client) |
| 51 | + |
| 52 | + |
| 53 | +@pytest.mark.asyncio |
| 54 | +async def test_ata(): |
| 55 | + device = _build_device("ata_listdevice.json", "ata_get.json") |
| 56 | + |
| 57 | + assert device.name == "" |
| 58 | + assert device.device_type == DEVICE_TYPE_ATA |
58 | 59 | assert device.temperature_increment == 0.5 |
59 | 60 | assert device.has_energy_consumed_meter is False |
60 | | - assert device.room_temperature is None |
61 | | - |
| 61 | + assert device.room_temperature is None |
| 62 | + |
62 | 63 | assert device.operation_modes == [ |
63 | 64 | OPERATION_MODE_HEAT, |
64 | 65 | OPERATION_MODE_DRY, |
65 | 66 | OPERATION_MODE_COOL, |
66 | 67 | OPERATION_MODE_FAN_ONLY, |
67 | 68 | OPERATION_MODE_HEAT_COOL, |
68 | 69 | ] |
69 | | - assert device.fan_speed is None |
70 | | - assert device.fan_speeds is None |
71 | | - |
72 | | - await device.update() |
73 | | - |
74 | | - assert device.room_temperature == 28.0 |
75 | | - assert device.target_temperature == 22.0 |
76 | | - |
| 70 | + assert device.fan_speed is None |
| 71 | + assert device.fan_speeds is None |
| 72 | + |
| 73 | + await device.update() |
| 74 | + |
| 75 | + assert device.room_temperature == 28.0 |
| 76 | + assert device.target_temperature == 22.0 |
| 77 | + |
77 | 78 | assert device.operation_mode == OPERATION_MODE_COOL |
78 | | - assert device.fan_speed == "3" |
79 | | - assert device.actual_fan_speed == "0" |
80 | | - assert device.fan_speeds == ["auto", "1", "2", "3", "4", "5"] |
81 | | - |
| 79 | + assert device.fan_speed == "3" |
| 80 | + assert device.actual_fan_speed == "0" |
| 81 | + assert device.fan_speeds == ["auto", "1", "2", "3", "4", "5"] |
| 82 | + |
82 | 83 | assert device.vane_vertical == V_VANE_POSITION_AUTO |
83 | 84 | assert device.vane_horizontal == H_VANE_POSITION_3 |
84 | 85 |
|
85 | 86 | assert device.wifi_signal == -51 |
86 | 87 | assert device.has_error is False |
87 | 88 | assert device.error_code == 8000 |
88 | | - |
0 commit comments