Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/goodwe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: GoodweConfigEntry) -> bo
host=host,
port=port,
family=model_family,
retries=10,
retries=3,
)
except InverterError as err:
try:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/goodwe/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ async def async_detect_inverter_port(
"""Detects the port of the Inverter."""
port = GOODWE_UDP_PORT
try:
inverter = await connect(host=host, port=port, retries=10)
inverter = await connect(host=host, port=port, retries=3)
except InverterError:
port = GOODWE_TCP_PORT
inverter = await connect(host=host, port=port, retries=10)
inverter = await connect(host=host, port=port, retries=3)
return inverter, port
36 changes: 35 additions & 1 deletion tests/components/goodwe/test_init.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Test the GoodWe initialization."""

from unittest.mock import MagicMock
from unittest.mock import MagicMock, patch

from goodwe import InverterError

from homeassistant.components.goodwe import CONF_MODEL_FAMILY, DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
Expand Down Expand Up @@ -34,3 +37,34 @@ async def test_migration(
assert config_entry.data[CONF_HOST] == TEST_HOST
assert config_entry.data[CONF_MODEL_FAMILY] == "MagicMock"
assert config_entry.data[CONF_PORT] == TEST_PORT


async def test_setup_connect_not_ready(hass: HomeAssistant) -> None:
"""Test that setup raises ConfigEntryNotReady when inverter is unreachable."""
config_entry = MockConfigEntry(
version=2,
domain=DOMAIN,
data={
CONF_HOST: TEST_HOST,
CONF_PORT: TEST_PORT,
CONF_MODEL_FAMILY: "ET",
},
)
config_entry.add_to_hass(hass)

with (
patch(
"homeassistant.components.goodwe.connect",
side_effect=InverterError,
) as mock_connect,
patch(
"homeassistant.components.goodwe.config_flow.connect",
side_effect=InverterError,
),
Comment on lines +60 to +63
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

assert config_entry.state is ConfigEntryState.SETUP_RETRY
# Verify connect is called with limited retries to avoid blocking startup
assert mock_connect.call_args.kwargs["retries"] <= 3