mirror of
https://github.com/home-assistant/core.git
synced 2026-07-11 16:47:52 +01:00
Translate coordinator exceptions for Twente Milieu (#168005)
This commit is contained in:
@@ -4,12 +4,17 @@ from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
|
||||
from twentemilieu import TwenteMilieu, WasteType
|
||||
from twentemilieu import (
|
||||
TwenteMilieu,
|
||||
TwenteMilieuConnectionError,
|
||||
TwenteMilieuError,
|
||||
WasteType,
|
||||
)
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import (
|
||||
CONF_HOUSE_LETTER,
|
||||
@@ -46,4 +51,15 @@ class TwenteMilieuDataUpdateCoordinator(
|
||||
|
||||
async def _async_update_data(self) -> dict[WasteType, list[date]]:
|
||||
"""Fetch Twente Milieu data."""
|
||||
return await self.twentemilieu.update()
|
||||
try:
|
||||
return await self.twentemilieu.update()
|
||||
except TwenteMilieuConnectionError as err:
|
||||
raise UpdateFailed(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="communication_error",
|
||||
) from err
|
||||
except TwenteMilieuError as err:
|
||||
raise UpdateFailed(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="unknown_error",
|
||||
) from err
|
||||
|
||||
@@ -70,10 +70,7 @@ rules:
|
||||
comment: |
|
||||
This integration has a fixed single device which represents the service.
|
||||
diagnostics: done
|
||||
exception-translations:
|
||||
status: todo
|
||||
comment: |
|
||||
The coordinator raises, and currently, doesn't provide a translation for it.
|
||||
exception-translations: done
|
||||
icon-translations: done
|
||||
reconfiguration-flow: todo
|
||||
dynamic-devices:
|
||||
|
||||
@@ -41,5 +41,13 @@
|
||||
"name": "Paper waste pickup"
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"communication_error": {
|
||||
"message": "An error occurred while communicating with the Twente Milieu service."
|
||||
},
|
||||
"unknown_error": {
|
||||
"message": "An unknown error occurred while communicating with the Twente Milieu service."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"""Tests for the Twente Milieu integration."""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from twentemilieu import TwenteMilieuConnectionError, TwenteMilieuError
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
@@ -28,19 +29,21 @@ async def test_load_unload_config_entry(
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
@patch(
|
||||
"homeassistant.components.twentemilieu.coordinator.TwenteMilieu.update",
|
||||
side_effect=RuntimeError,
|
||||
@pytest.mark.parametrize(
|
||||
"side_effect", [TwenteMilieuConnectionError, TwenteMilieuError]
|
||||
)
|
||||
async def test_config_entry_not_ready(
|
||||
mock_request: MagicMock,
|
||||
hass: HomeAssistant,
|
||||
mock_twentemilieu: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
side_effect: type[Exception],
|
||||
) -> None:
|
||||
"""Test the Twente Milieu configuration entry not ready."""
|
||||
mock_twentemilieu.update.side_effect = side_effect
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_request.call_count == 1
|
||||
assert mock_twentemilieu.update.call_count == 1
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
Reference in New Issue
Block a user