mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Revert setting communication delay in Risco init (#113497)
This commit is contained in:
parent
c69495b64f
commit
99e29b75cc
@ -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)
|
||||
|
@ -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."""
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user