mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
Add exception translations for pyLoad integration (#120520)
This commit is contained in:
parent
e06d7050f2
commit
45dedf73c8
@ -20,6 +20,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import PyLoadCoordinator
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.BUTTON, Platform.SENSOR, Platform.SWITCH]
|
||||
@ -51,13 +52,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: PyLoadConfigEntry) -> bo
|
||||
await pyloadapi.login()
|
||||
except CannotConnect as e:
|
||||
raise ConfigEntryNotReady(
|
||||
"Unable to connect and retrieve data from pyLoad API"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="setup_request_exception",
|
||||
) from e
|
||||
except ParserError as e:
|
||||
raise ConfigEntryNotReady("Unable to parse data from pyLoad API") from e
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="setup_parse_exception",
|
||||
) from e
|
||||
except InvalidAuth as e:
|
||||
raise ConfigEntryAuthFailed(
|
||||
f"Authentication failed for {entry.data[CONF_USERNAME]}, check your login credentials"
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="setup_authentication_exception",
|
||||
translation_placeholders={CONF_USERNAME: entry.data[CONF_USERNAME]},
|
||||
) from e
|
||||
coordinator = PyLoadCoordinator(hass, pyloadapi)
|
||||
|
||||
|
@ -7,6 +7,7 @@ import logging
|
||||
from pyloadapi import CannotConnect, InvalidAuth, ParserError, PyLoadAPI
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
@ -64,7 +65,9 @@ class PyLoadCoordinator(DataUpdateCoordinator[pyLoadData]):
|
||||
await self.pyload.login()
|
||||
except InvalidAuth as exc:
|
||||
raise ConfigEntryAuthFailed(
|
||||
f"Authentication failed for {self.pyload.username}, check your login credentials",
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="setup_authentication_exception",
|
||||
translation_placeholders={CONF_USERNAME: self.pyload.username},
|
||||
) from exc
|
||||
|
||||
raise UpdateFailed(
|
||||
|
@ -89,6 +89,17 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"exceptions": {
|
||||
"setup_request_exception": {
|
||||
"message": "Unable to connect and retrieve data from pyLoad API, try again later"
|
||||
},
|
||||
"setup_parse_exception": {
|
||||
"message": "Unable to parse data from pyLoad API, try again later"
|
||||
},
|
||||
"setup_authentication_exception": {
|
||||
"message": "Authentication failed for {username}, verify your login credentials"
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_yaml_import_issue_cannot_connect": {
|
||||
"title": "The pyLoad YAML configuration import failed",
|
||||
|
@ -96,7 +96,7 @@ async def test_sensor_invalid_auth(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert (
|
||||
"Authentication failed for username, check your login credentials"
|
||||
"Authentication failed for username, verify your login credentials"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user