Reload Risco on connection reset (#120150)

pull/117181/head^2
On Freund 2024-06-22 13:55:42 +03:00 committed by GitHub
parent 6a19808718
commit 6d0ae77288
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 3 deletions

View File

@ -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))

View File

@ -7,5 +7,5 @@
"iot_class": "local_push",
"loggers": ["pyrisco"],
"quality_scale": "platinum",
"requirements": ["pyrisco==0.6.2"]
"requirements": ["pyrisco==0.6.4"]
}

View File

@ -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

View File

@ -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

View File

@ -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()