mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 02:24:51 -05:00
Localize exception messages for CentriConnect (#179752)
This commit is contained in:
@@ -71,7 +71,9 @@ class CentriConnectCoordinator(DataUpdateCoordinator[Tank]):
|
||||
try:
|
||||
tank_data = await self.api_client.async_get_tank_data()
|
||||
except CentriConnectError as err:
|
||||
raise UpdateFailed("Could not fetch device info") from err
|
||||
raise UpdateFailed(
|
||||
translation_domain=DOMAIN, translation_key="entry_setup_failed"
|
||||
) from err
|
||||
self.device_info = CentriConnectDeviceInfo(
|
||||
device_id=tank_data.device_id,
|
||||
device_name=tank_data.device_name,
|
||||
@@ -87,7 +89,19 @@ class CentriConnectCoordinator(DataUpdateCoordinator[Tank]):
|
||||
try:
|
||||
state = await self.api_client.async_get_tank_data()
|
||||
except CentriConnectConnectionError as err:
|
||||
raise UpdateFailed(f"Error communicating with device: {err}") from err
|
||||
raise UpdateFailed(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="communication_error",
|
||||
translation_placeholders={
|
||||
"error": repr(err),
|
||||
},
|
||||
) from err
|
||||
except CentriConnectError as err:
|
||||
raise UpdateFailed(f"Unexpected response: {err}") from err
|
||||
raise UpdateFailed(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="unexpected_response",
|
||||
translation_placeholders={
|
||||
"error": repr(err),
|
||||
},
|
||||
) from err
|
||||
return state
|
||||
|
||||
@@ -68,7 +68,7 @@ rules:
|
||||
entity-device-class: done
|
||||
entity-disabled-by-default: done
|
||||
entity-translations: done
|
||||
exception-translations: todo
|
||||
exception-translations: done
|
||||
icon-translations: done
|
||||
reconfiguration-flow: todo
|
||||
repair-issues:
|
||||
|
||||
@@ -65,5 +65,16 @@
|
||||
"name": "Tank size"
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"communication_error": {
|
||||
"message": "Error communicating with device: {error}"
|
||||
},
|
||||
"entry_setup_failed": {
|
||||
"message": "Could not fetch device info"
|
||||
},
|
||||
"unexpected_response": {
|
||||
"message": "Unexpected response: {error}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
"""Tests for the CentriConnect/MyPropane configuration initialization."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from aiocentriconnect.exceptions import CentriConnectConnectionError
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_config_entry_not_ready(
|
||||
hass: HomeAssistant,
|
||||
mock_centriconnect_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test config entry not ready."""
|
||||
mock_centriconnect_client.async_get_tank_data.side_effect = (
|
||||
CentriConnectConnectionError
|
||||
)
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
mock_centriconnect_client.async_get_tank_data.side_effect = None
|
||||
Reference in New Issue
Block a user