File: test_dhw_time_switch.py

package info (click to toggle)
python-bsblan 2.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 784 kB
  • sloc: python: 2,890; makefile: 3
file content (180 lines) | stat: -rw-r--r-- 5,801 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
174
175
176
177
178
179
180
"""Tests for DHW time switch functionality."""

# pylint: disable=duplicate-code
# pylint: disable=protected-access
# file deepcode ignore W0212: this is a testfile

from unittest.mock import AsyncMock

import pytest

from bsblan import BSBLAN, BSBLANError
from bsblan.constants import MULTI_PARAMETER_ERROR_MSG
from bsblan.models import DHWTimeSwitchPrograms


@pytest.mark.asyncio
async def test_set_dhw_time_program(mock_bsblan: BSBLAN) -> None:
    """Test setting DHW time program.

    Args:
        mock_bsblan (BSBLAN): The mock BSBLAN instance.

    """
    # Test setting time program for Monday
    assert isinstance(mock_bsblan._request, AsyncMock)
    dhw_programs = DHWTimeSwitchPrograms(monday="13:00-14:00 ##:##-##:## ##:##-##:##")
    await mock_bsblan.set_hot_water(dhw_time_programs=dhw_programs)
    mock_bsblan._request.assert_awaited_with(
        base_path="/JS",
        data={
            "Parameter": "561",
            "Value": "13:00-14:00 ##:##-##:## ##:##-##:##",
            "Type": "1",
        },
    )

    # Test setting time program for Tuesday
    dhw_programs = DHWTimeSwitchPrograms(tuesday="06:00-08:00 17:00-20:00 ##:##-##:##")
    await mock_bsblan.set_hot_water(dhw_time_programs=dhw_programs)
    mock_bsblan._request.assert_awaited_with(
        base_path="/JS",
        data={
            "Parameter": "562",
            "Value": "06:00-08:00 17:00-20:00 ##:##-##:##",
            "Type": "1",
        },
    )

    # Test setting time program for Wednesday
    dhw_programs = DHWTimeSwitchPrograms(
        wednesday="07:30-09:00 18:00-21:30 ##:##-##:##"
    )
    await mock_bsblan.set_hot_water(dhw_time_programs=dhw_programs)
    mock_bsblan._request.assert_awaited_with(
        base_path="/JS",
        data={
            "Parameter": "563",
            "Value": "07:30-09:00 18:00-21:30 ##:##-##:##",
            "Type": "1",
        },
    )

    # Test setting time program for Thursday
    dhw_programs = DHWTimeSwitchPrograms(thursday="06:00-09:00 16:00-22:00 ##:##-##:##")
    await mock_bsblan.set_hot_water(dhw_time_programs=dhw_programs)
    mock_bsblan._request.assert_awaited_with(
        base_path="/JS",
        data={
            "Parameter": "564",
            "Value": "06:00-09:00 16:00-22:00 ##:##-##:##",
            "Type": "1",
        },
    )

    # Test setting time program for Friday
    dhw_programs = DHWTimeSwitchPrograms(friday="06:00-09:00 15:00-23:00 ##:##-##:##")
    await mock_bsblan.set_hot_water(dhw_time_programs=dhw_programs)
    mock_bsblan._request.assert_awaited_with(
        base_path="/JS",
        data={
            "Parameter": "565",
            "Value": "06:00-09:00 15:00-23:00 ##:##-##:##",
            "Type": "1",
        },
    )

    # Test setting time program for Saturday
    dhw_programs = DHWTimeSwitchPrograms(saturday="08:00-23:00 ##:##-##:## ##:##-##:##")
    await mock_bsblan.set_hot_water(dhw_time_programs=dhw_programs)
    mock_bsblan._request.assert_awaited_with(
        base_path="/JS",
        data={
            "Parameter": "566",
            "Value": "08:00-23:00 ##:##-##:## ##:##-##:##",
            "Type": "1",
        },
    )

    # Test setting time program for Sunday
    dhw_programs = DHWTimeSwitchPrograms(sunday="08:00-22:00 ##:##-##:## ##:##-##:##")
    await mock_bsblan.set_hot_water(dhw_time_programs=dhw_programs)
    mock_bsblan._request.assert_awaited_with(
        base_path="/JS",
        data={
            "Parameter": "567",
            "Value": "08:00-22:00 ##:##-##:## ##:##-##:##",
            "Type": "1",
        },
    )

    # Test setting standard values
    dhw_programs = DHWTimeSwitchPrograms(standard_values="0")
    await mock_bsblan.set_hot_water(dhw_time_programs=dhw_programs)
    mock_bsblan._request.assert_awaited_with(
        base_path="/JS",
        data={
            "Parameter": "576",
            "Value": "0",
            "Type": "1",
        },
    )

    # Test setting multiple parameters (should raise an error)
    dhw_programs = DHWTimeSwitchPrograms(
        monday="13:00-14:00 ##:##-##:## ##:##-##:##",
        tuesday="06:00-08:00 17:00-20:00 ##:##-##:##",
    )
    with pytest.raises(BSBLANError, match=MULTI_PARAMETER_ERROR_MSG):
        await mock_bsblan.set_hot_water(dhw_time_programs=dhw_programs)


@pytest.mark.asyncio
async def test_prepare_dhw_time_program_state(mock_bsblan: BSBLAN) -> None:
    """Test preparing DHW time program state.

    Args:
        mock_bsblan (BSBLAN): The mock BSBLAN instance.

    """
    # Test preparing Monday time program
    dhw_programs = DHWTimeSwitchPrograms(monday="13:00-14:00 ##:##-##:## ##:##-##:##")
    state = mock_bsblan._prepare_hot_water_state(
        nominal_setpoint=None,
        reduced_setpoint=None,
        operating_mode=None,
        dhw_time_programs=dhw_programs,
    )
    assert state == {
        "Parameter": "561",
        "Value": "13:00-14:00 ##:##-##:## ##:##-##:##",
        "Type": "1",
    }

    # Test preparing Tuesday time program
    dhw_programs = DHWTimeSwitchPrograms(tuesday="06:00-08:00 17:00-20:00 ##:##-##:##")
    state = mock_bsblan._prepare_hot_water_state(
        nominal_setpoint=None,
        reduced_setpoint=None,
        operating_mode=None,
        dhw_time_programs=dhw_programs,
    )
    assert state == {
        "Parameter": "562",
        "Value": "06:00-08:00 17:00-20:00 ##:##-##:##",
        "Type": "1",
    }

    # Test preparing standard values
    dhw_programs = DHWTimeSwitchPrograms(standard_values="0")
    state = mock_bsblan._prepare_hot_water_state(
        nominal_setpoint=None,
        reduced_setpoint=None,
        operating_mode=None,
        dhw_time_programs=dhw_programs,
    )
    assert state == {
        "Parameter": "576",
        "Value": "0",
        "Type": "1",
    }