Print the exact reason if the WebSocket event to Core fails (#5609)

* Print the exact reason if the WebSocket event to Core fails

* Improve error at backup end too, fix tests

* Fix text

* Address ruff check issue
This commit is contained in:
Stefan Agner
2025-02-06 18:17:46 +01:00
committed by GitHub
parent 2078044062
commit 7348745049
2 changed files with 8 additions and 7 deletions

View File

@@ -90,13 +90,13 @@ async def test_begin_backup_ws_error(coresys: CoreSys):
"""Test WS error when beginning backup."""
# pylint: disable-next=protected-access
coresys.homeassistant.websocket._client.async_send_command.side_effect = (
HomeAssistantWSConnectionError
HomeAssistantWSConnectionError("Connection was closed")
)
with (
patch.object(HomeAssistantWebSocket, "_can_send", return_value=True),
pytest.raises(
HomeAssistantBackupError,
match="Preparing backup of Home Assistant Core failed. Check HA Core logs.",
match="Preparing backup of Home Assistant Core failed. Failed to inform HA Core: Connection was closed.",
),
):
await coresys.homeassistant.begin_backup()
@@ -106,13 +106,13 @@ async def test_end_backup_ws_error(coresys: CoreSys, caplog: pytest.LogCaptureFi
"""Test WS error when ending backup."""
# pylint: disable-next=protected-access
coresys.homeassistant.websocket._client.async_send_command.side_effect = (
HomeAssistantWSConnectionError
HomeAssistantWSConnectionError("Connection was closed")
)
with patch.object(HomeAssistantWebSocket, "_can_send", return_value=True):
await coresys.homeassistant.end_backup()
assert (
"Error resuming normal operations after backup of Home Assistant Core. Check HA Core logs."
"Error resuming normal operations after backup of Home Assistant Core. Failed to inform HA Core: Connection was closed."
in caplog.text
)