Skip to content

Commit 9bff9c5

Browse files
authored
Ensure screenlogic retries if the protocol adapter is still booting (#133444)
* Ensure screenlogic retries if the protocol adapter is still booting If the protocol adapter is still booting, it will disconnect and never retry ``` Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/screenlogic/__init__.py", line 65, in async_setup_entry await gateway.async_connect(**connect_info) File "/usr/local/lib/python3.13/site-packages/screenlogicpy/gateway.py", line 142, in async_connect connectPkg = await async_connect_to_gateway( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<4 lines>... ) ^ File "/usr/local/lib/python3.13/site-packages/screenlogicpy/requests/login.py", line 107, in async_connect_to_gateway mac_address = await async_gateway_connect(transport, protocol, max_retries) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.13/site-packages/screenlogicpy/requests/login.py", line 77, in async_gateway_connect raise ScreenLogicConnectionError("Host unexpectedly disconnected.") screenlogicpy.const.common.ScreenLogicConnectionError: Host unexpectedly disconnected. ``` * coverage
1 parent e73512e commit 9bff9c5

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

homeassistant/components/screenlogic/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Any
55

66
from screenlogicpy import ScreenLogicError, ScreenLogicGateway
7+
from screenlogicpy.const.common import ScreenLogicConnectionError
78
from screenlogicpy.const.data import SHARED_VALUES
89

910
from homeassistant.config_entries import ConfigEntry
@@ -64,7 +65,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ScreenLogicConfigEntry)
6465
try:
6566
await gateway.async_connect(**connect_info)
6667
await gateway.async_update()
67-
except ScreenLogicError as ex:
68+
except (ScreenLogicConnectionError, ScreenLogicError) as ex:
6869
raise ConfigEntryNotReady(ex.msg) from ex
6970

7071
coordinator = ScreenlogicDataUpdateCoordinator(

tests/components/screenlogic/test_init.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from unittest.mock import DEFAULT, patch
55

66
import pytest
7-
from screenlogicpy import ScreenLogicGateway
7+
from screenlogicpy import ScreenLogicError, ScreenLogicGateway
8+
from screenlogicpy.const.common import ScreenLogicConnectionError
89

910
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
1011
from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN
1112
from homeassistant.components.screenlogic import DOMAIN
1213
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
14+
from homeassistant.config_entries import ConfigEntryState
1315
from homeassistant.core import HomeAssistant
1416
from homeassistant.helpers import device_registry as dr, entity_registry as er
1517
from homeassistant.util import slugify
@@ -284,3 +286,35 @@ def stub_connect(*args, **kwargs):
284286

285287
for entity_id in tested_entity_ids:
286288
assert hass.states.get(entity_id) is not None
289+
290+
291+
@pytest.mark.parametrize(
292+
"exception",
293+
[ScreenLogicConnectionError, ScreenLogicError],
294+
)
295+
async def test_retry_on_connect_exception(
296+
hass: HomeAssistant, mock_config_entry: MockConfigEntry, exception: Exception
297+
) -> None:
298+
"""Test setup retries on expected exceptions."""
299+
300+
def stub_connect(*args, **kwargs):
301+
raise exception
302+
303+
mock_config_entry.add_to_hass(hass)
304+
305+
with (
306+
patch(
307+
GATEWAY_DISCOVERY_IMPORT_PATH,
308+
return_value={},
309+
),
310+
patch.multiple(
311+
ScreenLogicGateway,
312+
async_connect=stub_connect,
313+
is_connected=False,
314+
_async_connected_request=DEFAULT,
315+
),
316+
):
317+
assert not await hass.config_entries.async_setup(mock_config_entry.entry_id)
318+
await hass.async_block_till_done()
319+
320+
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY

0 commit comments

Comments
 (0)