diff --git a/homeassistant/components/risco/__init__.py b/homeassistant/components/risco/__init__.py index 2c55b474e00..02e51bcc4ea 100644 --- a/homeassistant/components/risco/__init__.py +++ b/homeassistant/components/risco/__init__.py @@ -38,12 +38,10 @@ from homeassistant.helpers.storage import Store from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import ( - CONF_COMMUNICATION_DELAY, DATA_COORDINATOR, DEFAULT_SCAN_INTERVAL, DOMAIN, EVENTS_COORDINATOR, - MAX_COMMUNICATION_DELAY, TYPE_LOCAL, ) @@ -86,31 +84,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def _async_setup_local_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: data = entry.data - comm_delay = initial_delay = data.get(CONF_COMMUNICATION_DELAY, 0) + risco = RiscoLocal(data[CONF_HOST], data[CONF_PORT], data[CONF_PIN]) - while True: - risco = RiscoLocal( - data[CONF_HOST], - data[CONF_PORT], - data[CONF_PIN], - communication_delay=comm_delay, - ) - try: - await risco.connect() - except CannotConnectError as error: - if comm_delay >= MAX_COMMUNICATION_DELAY: - raise ConfigEntryNotReady() from error - comm_delay += 1 - except UnauthorizedError: - _LOGGER.exception("Failed to login to Risco cloud") - return False - else: - break - - if comm_delay > initial_delay: - new_data = data.copy() - new_data[CONF_COMMUNICATION_DELAY] = comm_delay - hass.config_entries.async_update_entry(entry, data=new_data) + try: + await risco.connect() + except CannotConnectError as error: + raise ConfigEntryNotReady() from error + except UnauthorizedError: + _LOGGER.exception("Failed to login to Risco cloud") + return False async def _error(error: Exception) -> None: _LOGGER.error("Error in Risco library: %s", error) diff --git a/tests/components/risco/conftest.py b/tests/components/risco/conftest.py index 6e86e04be7d..a27225fce84 100644 --- a/tests/components/risco/conftest.py +++ b/tests/components/risco/conftest.py @@ -172,16 +172,6 @@ def connect_with_error(exception): yield -@pytest.fixture -def connect_with_single_error(exception): - """Fixture to simulate error on connect.""" - with patch( - "homeassistant.components.risco.RiscoLocal.connect", - side_effect=[exception, None], - ): - yield - - @pytest.fixture async def setup_risco_local(hass, local_config_entry): """Set up a local Risco integration for testing.""" diff --git a/tests/components/risco/test_init.py b/tests/components/risco/test_init.py deleted file mode 100644 index 18378c5c9c4..00000000000 --- a/tests/components/risco/test_init.py +++ /dev/null @@ -1,22 +0,0 @@ -"""Tests for the Risco initialization.""" - -import pytest - -from homeassistant.components.risco import CannotConnectError -from homeassistant.components.risco.const import CONF_COMMUNICATION_DELAY -from homeassistant.core import HomeAssistant - - -@pytest.mark.parametrize("exception", [CannotConnectError]) -async def test_single_error_on_connect( - hass: HomeAssistant, connect_with_single_error, local_config_entry -) -> None: - """Test single error on connect to validate communication delay update from 0 (default) to 1.""" - expected_data = { - **local_config_entry.data, - **{"type": "local", CONF_COMMUNICATION_DELAY: 1}, - } - - await hass.config_entries.async_setup(local_config_entry.entry_id) - await hass.async_block_till_done() - assert local_config_entry.data == expected_data