File: test_v2_device.py

package info (click to toggle)
python-homewizard-energy 10.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,104 kB
  • sloc: python: 3,523; makefile: 3
file content (173 lines) | stat: -rw-r--r-- 5,311 bytes parent folder | download
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"""Test for Device model."""

import json

import pytest
from awesomeversion import AwesomeVersion
from syrupy.assertion import SnapshotAssertion

from homewizard_energy.const import Model
from homewizard_energy.models import Batteries, Device

from . import load_fixtures

pytestmark = [pytest.mark.asyncio]


@pytest.mark.parametrize(
    ("model", "fixtures"),
    [
        ("HWE-P1", ["device"]),
        ("HWE-KWH1", ["device"]),
        ("HWE-KWH3", ["device"]),
        ("HWE-BAT", ["device"]),
    ],
)
async def test_device(model: str, fixtures: str, snapshot: SnapshotAssertion):
    """Test Device model."""
    for fixture in fixtures:
        data = Device.from_dict(json.loads(load_fixtures(f"{model}/{fixture}.json")))
        assert data
        assert snapshot == data


# pylint: disable=too-many-arguments,too-many-positional-arguments
@pytest.mark.parametrize(
    (
        "model",
        "supports_state",
        "supports_identify",
        "supports_cloud_enable",
        "supports_reboot",
        "supports_telegram",
    ),
    [
        ("HWE-P1", False, True, True, True, True),
        ("HWE-KWH1", False, False, True, True, False),
        ("HWE-KWH3", False, False, True, True, False),
        ("HWE-BAT", False, True, False, False, False),
    ],
)
async def test_device_support_functions(
    model: str,
    supports_state: bool,
    supports_identify: bool,
    supports_cloud_enable: bool,
    supports_reboot: bool,
    supports_telegram: bool,
):
    """Test Device model support functions."""
    device = Device.from_dict(json.loads(load_fixtures(f"{model}/device.json")))
    assert device
    assert device.supports_state() == supports_state
    assert device.supports_identify() == supports_identify
    assert device.supports_cloud_enable() == supports_cloud_enable
    assert device.supports_reboot() == supports_reboot
    assert device.supports_telegram() == supports_telegram


@pytest.mark.parametrize(
    "product_type,api_version,expected_modes",
    [  # Devices that do not support batteries
        (Model.ENERGY_SOCKET, "2.2.0", None),
        (Model.WATER_METER, "2.2.0", None),
        # Devices that support batteries, API < 2.2.0
        (
            Model.P1_METER,
            "2.1.0",
            [Batteries.Mode.ZERO, Batteries.Mode.TO_FULL, Batteries.Mode.STANDBY],
        ),
        (
            Model.ENERGY_METER_1_PHASE,
            "2.1.0",
            [Batteries.Mode.ZERO, Batteries.Mode.TO_FULL, Batteries.Mode.STANDBY],
        ),
        (
            Model.ENERGY_METER_3_PHASE,
            "2.1.0",
            [Batteries.Mode.ZERO, Batteries.Mode.TO_FULL, Batteries.Mode.STANDBY],
        ),
        (
            Model.ENERGY_METER_EASTRON_SDM230,
            "2.1.0",
            [Batteries.Mode.ZERO, Batteries.Mode.TO_FULL, Batteries.Mode.STANDBY],
        ),
        (
            Model.ENERGY_METER_EASTRON_SDM630,
            "2.1.0",
            [Batteries.Mode.ZERO, Batteries.Mode.TO_FULL, Batteries.Mode.STANDBY],
        ),
        # Devices that support batteries, API >= 2.2.0
        (
            Model.P1_METER,
            "2.2.0",
            [
                Batteries.Mode.ZERO,
                Batteries.Mode.TO_FULL,
                Batteries.Mode.STANDBY,
                Batteries.Mode.ZERO_CHARGE_ONLY,
                Batteries.Mode.ZERO_DISCHARGE_ONLY,
            ],
        ),
        (
            Model.ENERGY_METER_1_PHASE,
            "2.2.0",
            [
                Batteries.Mode.ZERO,
                Batteries.Mode.TO_FULL,
                Batteries.Mode.STANDBY,
                Batteries.Mode.ZERO_CHARGE_ONLY,
                Batteries.Mode.ZERO_DISCHARGE_ONLY,
            ],
        ),
        (
            Model.ENERGY_METER_3_PHASE,
            "2.2.0",
            [
                Batteries.Mode.ZERO,
                Batteries.Mode.TO_FULL,
                Batteries.Mode.STANDBY,
                Batteries.Mode.ZERO_CHARGE_ONLY,
                Batteries.Mode.ZERO_DISCHARGE_ONLY,
            ],
        ),
        (
            Model.ENERGY_METER_EASTRON_SDM230,
            "2.2.0",
            [
                Batteries.Mode.ZERO,
                Batteries.Mode.TO_FULL,
                Batteries.Mode.STANDBY,
                Batteries.Mode.ZERO_CHARGE_ONLY,
                Batteries.Mode.ZERO_DISCHARGE_ONLY,
            ],
        ),
        (
            Model.ENERGY_METER_EASTRON_SDM630,
            "2.2.0",
            [
                Batteries.Mode.ZERO,
                Batteries.Mode.TO_FULL,
                Batteries.Mode.STANDBY,
                Batteries.Mode.ZERO_CHARGE_ONLY,
                Batteries.Mode.ZERO_DISCHARGE_ONLY,
            ],
        ),
    ],
)
def test_supported_battery_modes(product_type, api_version, expected_modes):
    """Test supported_battery_modes method of Device."""
    device = Device(
        product_name="Test Device",
        product_type=product_type,
        serial="1234567890",
        api_version=AwesomeVersion(api_version),
        firmware_version="1.0.0",
    )
    result = device.supported_battery_modes()
    if expected_modes is None:
        assert result is None
    else:
        assert set(result) == set(
            expected_modes
        )  # We don't care about order, just presence