Skip to content

Commit d88388c

Browse files
committed
fix tests
1 parent c9ccb5f commit d88388c

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

tests/conftest.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from unittest.mock import patch
2020

2121
import pytest
22-
from pymodbus.pdu.register_read_message import (
22+
from pymodbus.pdu.register_message import (
2323
ReadHoldingRegistersResponse,
2424
ReadInputRegistersResponse,
2525
)
@@ -72,45 +72,46 @@ def bypass_get_data_fixture():
7272
yield
7373

7474

75-
def read_input_register(register, start, count) -> ReadInputRegistersResponse:
75+
def read_input_register(
76+
address: int, register, start, count
77+
) -> ReadInputRegistersResponse:
7678
"""Read a slice from the input register."""
77-
return ReadInputRegistersResponse(register[start : start + count])
79+
return ReadInputRegistersResponse(
80+
address=address, count=count, registers=register[start : start + count]
81+
)
7882

7983

8084
async def read_input_registers_wpm(
81-
address: int,
82-
count: int = 1,
83-
slave: int = 0,
84-
**kwargs: Any,
85+
address: int, *, count: int = 1, slave: int = 0, no_response_expected: bool = False
8586
):
8687
"""Simulate reads on the input registers on wpm models."""
8788
system_info = [2, 390]
8889
if address >= 5000:
89-
return read_input_register(system_info, address - 5000, count)
90-
return ReadInputRegistersResponse(list(range(count)))
90+
return read_input_register(address, system_info, address - 5000, count)
91+
return ReadInputRegistersResponse(
92+
address=address, count=count, registers=list(range(count))
93+
)
9194

9295

9396
async def read_input_registers_lwz(
94-
address: int,
95-
count: int = 1,
96-
slave: int = 0,
97-
**kwargs: Any,
97+
address: int, *, count: int = 1, slave: int = 0, no_response_expected: bool = False
9898
):
9999
"""Simulate reads on the input registers on lwz models ."""
100100
system_info = [2, 103]
101101
if address >= 5000:
102-
return read_input_register(system_info, address - 5000, count)
103-
return ReadInputRegistersResponse(list(range(count)))
102+
return read_input_register(address, system_info, address - 5000, count)
103+
return ReadInputRegistersResponse(
104+
address=address, count=count, registers=list(range(count))
105+
)
104106

105107

106108
async def read_holding_registers(
107-
address: int,
108-
count: int = 1,
109-
slave: int = 0,
110-
**kwargs: Any,
109+
address: int, *, count: int = 1, slave: int = 0, no_response_expected: bool = False
111110
):
112111
"""Simulate reads on the holding registers on lwz models ."""
113-
return ReadHoldingRegistersResponse(list(range(count)))
112+
return ReadHoldingRegistersResponse(
113+
address=address, count=count, registers=list(range(count))
114+
)
114115

115116

116117
# This fixture, when used, will result in calls to read_input_registers to return mock data. To have the call

tests/test_config_flow.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from unittest.mock import patch
44

55
import pytest
6-
from homeassistant import config_entries, data_entry_flow
6+
from homeassistant import config_entries
77
from homeassistant.const import CONF_HOST
8+
from homeassistant.data_entry_flow import FlowResultType
89

910
from custom_components.stiebel_eltron_isg.const import (
1011
DOMAIN,
@@ -45,7 +46,7 @@ async def test_successful_config_flow(hass, bypass_get_data):
4546
)
4647

4748
# Check that the config flow shows the user form as the first step
48-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
49+
assert result["type"] == FlowResultType.FORM
4950
assert result["step_id"] == "user"
5051

5152
# If a user were to enter `test_username` for username and `test_password`
@@ -57,7 +58,7 @@ async def test_successful_config_flow(hass, bypass_get_data):
5758

5859
# Check that the config flow is complete and a new entry is created with
5960
# the input data
60-
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
61+
assert result["type"] == FlowResultType.CREATE_ENTRY
6162
assert result["title"] == "Stiebel Eltron ISG"
6263
assert result["data"] == MOCK_CONFIG
6364
assert result["result"]
@@ -75,13 +76,13 @@ async def test_failed_config_flow(hass, error_on_get_data):
7576
context={"source": config_entries.SOURCE_USER},
7677
)
7778

78-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
79+
assert result["type"] == FlowResultType.FORM
7980
assert result["step_id"] == "user"
8081

8182
result = await hass.config_entries.flow.async_configure(
8283
result["flow_id"],
8384
user_input=MOCK_INVALID_IP_CONFIG,
8485
)
8586

86-
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
87+
assert result["type"] == FlowResultType.FORM
8788
assert result["errors"] == {CONF_HOST: "invalid_host_IP"}

tests/test_init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def test_setup_unload_and_reload_entry(
5050
@pytest.mark.asyncio()
5151
async def test_data_coordinator_wpm(hass: HomeAssistant, mock_modbus_wpm) -> None:
5252
"""Test creating a data coordinator for wpm models."""
53-
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test_wpm")
53+
config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG, entry_id="test")
5454
config_entry.add_to_hass(hass)
5555

5656
await hass.config_entries.async_setup(config_entry.entry_id)

0 commit comments

Comments
 (0)