forked from erwindouna/python-melcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ata_properties.py
More file actions
103 lines (85 loc) · 3.18 KB
/
Copy pathtest_ata_properties.py
File metadata and controls
103 lines (85 loc) · 3.18 KB
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
"""ATA tests."""
import json
import os
import pytest
from unittest.mock import AsyncMock, Mock, patch
from aiohttp.web import HTTPForbidden
from src.pymelcloud import DEVICE_TYPE_ATA
import src.pymelcloud
from src.pymelcloud.const import ACCESS_LEVEL
from src.pymelcloud.ata_device import (
OPERATION_MODE_HEAT,
OPERATION_MODE_DRY,
OPERATION_MODE_COOL,
OPERATION_MODE_FAN_ONLY,
OPERATION_MODE_HEAT_COOL,
V_VANE_POSITION_AUTO,
V_VANE_POSITION_1,
V_VANE_POSITION_2,
V_VANE_POSITION_3,
V_VANE_POSITION_4,
V_VANE_POSITION_5,
V_VANE_POSITION_SWING,
V_VANE_POSITION_UNDEFINED,
H_VANE_POSITION_AUTO,
H_VANE_POSITION_1,
H_VANE_POSITION_2,
H_VANE_POSITION_3,
H_VANE_POSITION_4,
H_VANE_POSITION_5,
H_VANE_POSITION_SPLIT,
H_VANE_POSITION_SWING,
H_VANE_POSITION_UNDEFINED,
AtaDevice,
)
def _build_device(device_conf_name: str, device_state_name: str) -> AtaDevice:
test_dir = os.path.join(os.path.dirname(__file__), "samples")
with open(os.path.join(test_dir, device_conf_name), "r") as json_file:
device_conf = json.load(json_file)
with open(os.path.join(test_dir, device_state_name), "r") as json_file:
device_state = json.load(json_file)
with patch("src.pymelcloud.client.Client") as _client:
_client.update_confs = AsyncMock()
_client.device_confs.__iter__ = Mock(return_value=[device_conf].__iter__())
_client.fetch_device_units = AsyncMock(return_value=[])
_client.fetch_device_state = AsyncMock(return_value=device_state)
_client.fetch_energy_report = AsyncMock(return_value=None)
client = _client
return AtaDevice(device_conf, client)
@pytest.mark.asyncio
async def test_ata():
device = _build_device("ata_listdevice.json", "ata_get.json")
assert device.name == ""
assert device.device_type == DEVICE_TYPE_ATA
assert device.access_level == ACCESS_LEVEL["OWNER"]
assert device.temperature_increment == 0.5
assert device.has_energy_consumed_meter is False
assert device.room_temperature is None
assert device.operation_modes == [
OPERATION_MODE_HEAT,
OPERATION_MODE_DRY,
OPERATION_MODE_COOL,
OPERATION_MODE_FAN_ONLY,
OPERATION_MODE_HEAT_COOL,
]
assert device.fan_speed is None
assert device.fan_speeds is None
await device.update()
assert device.room_temperature == 28.0
assert device.target_temperature == 22.0
assert device.operation_mode == OPERATION_MODE_COOL
assert device.fan_speed == "3"
assert device.actual_fan_speed == "0"
assert device.fan_speeds == ["auto", "1", "2", "3", "4", "5"]
assert device.vane_vertical == V_VANE_POSITION_AUTO
assert device.vane_horizontal == H_VANE_POSITION_3
assert device.wifi_signal == -51
assert device.has_error is False
assert device.error_code == 8000
@pytest.mark.asyncio
async def test_ata_guest():
device = _build_device("ata_guest_listdevices.json", "ata_guest_get.json")
device._client.fetch_device_units = AsyncMock(side_effect=HTTPForbidden)
assert device.device_type == DEVICE_TYPE_ATA
assert device.access_level == ACCESS_LEVEL["GUEST"]
await device.update()