diff --git a/homeassistant/components/risco/__init__.py b/homeassistant/components/risco/__init__.py index b1847b002ea..7255c724e3f 100644 --- a/homeassistant/components/risco/__init__.py +++ b/homeassistant/components/risco/__init__.py @@ -90,6 +90,9 @@ async def _async_setup_local_entry(hass: HomeAssistant, entry: ConfigEntry) -> b async def _error(error: Exception) -> None: _LOGGER.error("Error in Risco library", exc_info=error) + if isinstance(error, ConnectionResetError) and not hass.is_stopping: + _LOGGER.debug("Disconnected from panel. Reloading integration") + hass.async_create_task(hass.config_entries.async_reload(entry.entry_id)) entry.async_on_unload(risco.add_error_handler(_error)) diff --git a/homeassistant/components/risco/manifest.json b/homeassistant/components/risco/manifest.json index 25520d1f96e..372d8e0c629 100644 --- a/homeassistant/components/risco/manifest.json +++ b/homeassistant/components/risco/manifest.json @@ -7,5 +7,5 @@ "iot_class": "local_push", "loggers": ["pyrisco"], "quality_scale": "platinum", - "requirements": ["pyrisco==0.6.2"] + "requirements": ["pyrisco==0.6.4"] } diff --git a/requirements_all.txt b/requirements_all.txt index 5356fa75d9b..3de5ee532da 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2126,7 +2126,7 @@ pyrecswitch==1.0.2 pyrepetierng==0.1.0 # homeassistant.components.risco -pyrisco==0.6.2 +pyrisco==0.6.4 # homeassistant.components.rituals_perfume_genie pyrituals==0.0.6 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index c33072d9b79..496eff4d327 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1671,7 +1671,7 @@ pyqwikswitch==0.93 pyrainbird==6.0.1 # homeassistant.components.risco -pyrisco==0.6.2 +pyrisco==0.6.4 # homeassistant.components.rituals_perfume_genie pyrituals==0.0.6 diff --git a/tests/components/risco/test_init.py b/tests/components/risco/test_init.py new file mode 100644 index 00000000000..4f604c75fe9 --- /dev/null +++ b/tests/components/risco/test_init.py @@ -0,0 +1,30 @@ +"""Tests for the Risco integration.""" + +from unittest.mock import patch + +import pytest + +from homeassistant.core import HomeAssistant + + +@pytest.fixture +def mock_error_handler(): + """Create a mock for add_error_handler.""" + with patch("homeassistant.components.risco.RiscoLocal.add_error_handler") as mock: + yield mock + + +async def test_connection_reset( + hass: HomeAssistant, two_zone_local, mock_error_handler, setup_risco_local +) -> None: + """Test config entry reload on connection reset.""" + + callback = mock_error_handler.call_args.args[0] + assert callback is not None + + with patch.object(hass.config_entries, "async_reload") as reload_mock: + await callback(Exception()) + reload_mock.assert_not_awaited() + + await callback(ConnectionResetError()) + reload_mock.assert_awaited_once()