mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Handle http connection errors to Prusa printers (#120456)
This commit is contained in:
parent
1f0e47b251
commit
5983344746
@ -9,6 +9,7 @@ import logging
|
||||
from time import monotonic
|
||||
from typing import TypeVar
|
||||
|
||||
from httpx import ConnectError
|
||||
from pyprusalink import JobInfo, LegacyPrinterStatus, PrinterStatus, PrusaLink
|
||||
from pyprusalink.types import InvalidAuth, PrusaLinkError
|
||||
|
||||
@ -47,6 +48,8 @@ class PrusaLinkUpdateCoordinator(DataUpdateCoordinator[T], ABC):
|
||||
raise UpdateFailed("Invalid authentication") from None
|
||||
except PrusaLinkError as err:
|
||||
raise UpdateFailed(str(err)) from err
|
||||
except (TimeoutError, ConnectError) as err:
|
||||
raise UpdateFailed("Cannot connect") from err
|
||||
|
||||
self.update_interval = self._get_update_interval(data)
|
||||
return data
|
||||
|
@ -3,6 +3,7 @@
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from httpx import ConnectError
|
||||
from pyprusalink.types import InvalidAuth, PrusaLinkError
|
||||
import pytest
|
||||
|
||||
@ -36,7 +37,10 @@ async def test_unloading(
|
||||
assert state.state == "unavailable"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exception", [InvalidAuth, PrusaLinkError])
|
||||
@pytest.mark.parametrize(
|
||||
"exception",
|
||||
[InvalidAuth, PrusaLinkError, ConnectError("All connection attempts failed")],
|
||||
)
|
||||
async def test_failed_update(
|
||||
hass: HomeAssistant, mock_config_entry: ConfigEntry, exception
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user