forked from erwindouna/python-melcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_device.py
More file actions
73 lines (57 loc) · 2.51 KB
/
Copy pathtest_device.py
File metadata and controls
73 lines (57 loc) · 2.51 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
"""Device tests."""
from typing import Any, Dict, Optional
import pytest
from unittest.mock import AsyncMock, Mock, patch
from src.pymelcloud.ata_device import AtaDevice
from .util import build_device
import src.pymelcloud
def _build_device(device_conf_name: str, device_state_name: str, energy_report: Optional[Dict[Any, Any]] = None) -> AtaDevice:
device_conf, client = build_device(device_conf_name, device_state_name, energy_report)
return AtaDevice(device_conf, client)
@pytest.mark.asyncio
async def test_round_temperature():
device = _build_device("ata_listdevice.json", "ata_get.json")
device._device_conf.get("Device")["TemperatureIncrement"] = 0.5
assert device.round_temperature(23.99999) == 24.0
assert device.round_temperature(24.0) == 24.0
assert device.round_temperature(24.00001) == 24.0
assert device.round_temperature(24.24999) == 24.0
assert device.round_temperature(24.25) == 24.5
assert device.round_temperature(24.25001) == 24.5
assert device.round_temperature(24.5) == 24.5
assert device.round_temperature(24.74999) == 24.5
assert device.round_temperature(24.75) == 25.0
assert device.round_temperature(24.75001) == 25.0
device._device_conf.get("Device")["TemperatureIncrement"] = 1
assert device.round_temperature(23.99999) == 24.0
assert device.round_temperature(24.0) == 24.0
assert device.round_temperature(24.00001) == 24.0
assert device.round_temperature(24.49999) == 24.0
assert device.round_temperature(24.5) == 25.0
assert device.round_temperature(24.50001) == 25.0
assert device.round_temperature(25.0) == 25.0
assert device.round_temperature(25.00001) == 25.0
assert device.round_temperature(25.49999) == 25.0
assert device.round_temperature(25.5) == 26.0
@pytest.mark.asyncio
async def test_energy_report_none_if_no_report():
device = _build_device("ata_listdevice.json", "ata_get.json")
await device.update()
assert device.daily_energy_consumed is None
def test_energy_report_before_update():
device = _build_device("ata_listdevice.json", "ata_get.json")
assert device.daily_energy_consumed is None
@pytest.mark.asyncio
async def test_round_temperature():
device = _build_device(
"ata_listdevice.json",
"ata_get.json",
{
"Heating": [0.0, 0.0, 1.0],
"Cooling": [0.0, 0.1, 10.0],
"Dry": [0.2, 0.0, 100.0],
"Fan": [0.3, 1000.0],
},
)
await device.update()
assert device.daily_energy_consumed == 1111.0