Reload Risco on connection reset (#120150)
parent
6a19808718
commit
6d0ae77288
|
@ -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))
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
"iot_class": "local_push",
|
||||
"loggers": ["pyrisco"],
|
||||
"quality_scale": "platinum",
|
||||
"requirements": ["pyrisco==0.6.2"]
|
||||
"requirements": ["pyrisco==0.6.4"]
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue