Fix missing translation string in emoncms (#129859)

This commit is contained in:
Alexandre CUER 2024-11-05 14:58:25 +01:00 committed by GitHub
parent 4729b19dc6
commit 6caa4baa00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 10 deletions

View File

@ -79,6 +79,7 @@ class EmoncmsConfigFlow(ConfigFlow, domain=DOMAIN):
) -> ConfigFlowResult:
"""Initiate a flow via the UI."""
errors: dict[str, str] = {}
description_placeholders = {}
if user_input is not None:
self._async_abort_entries_match(
@ -91,7 +92,8 @@ class EmoncmsConfigFlow(ConfigFlow, domain=DOMAIN):
self.hass, user_input[CONF_URL], user_input[CONF_API_KEY]
)
if not result[CONF_SUCCESS]:
errors["base"] = result[CONF_MESSAGE]
errors["base"] = "api_error"
description_placeholders = {"details": result[CONF_MESSAGE]}
else:
self.include_only_feeds = user_input.get(CONF_ONLY_INCLUDE_FEEDID)
self.url = user_input[CONF_URL]
@ -115,6 +117,7 @@ class EmoncmsConfigFlow(ConfigFlow, domain=DOMAIN):
user_input,
),
errors=errors,
description_placeholders=description_placeholders,
)
async def async_step_choose_feeds(
@ -177,6 +180,7 @@ class EmoncmsOptionsFlow(OptionsFlow):
) -> ConfigFlowResult:
"""Manage the options."""
errors: dict[str, str] = {}
description_placeholders = {}
data = self.options if self.options else self.config_entry.data
url = data[CONF_URL]
api_key = data[CONF_API_KEY]
@ -184,7 +188,8 @@ class EmoncmsOptionsFlow(OptionsFlow):
options: list = include_only_feeds
result = await get_feed_list(self.hass, url, api_key)
if not result[CONF_SUCCESS]:
errors["base"] = result[CONF_MESSAGE]
errors["base"] = "api_error"
description_placeholders = {"details": result[CONF_MESSAGE]}
else:
options = get_options(result[CONF_MESSAGE])
dropdown = {"options": options, "mode": "dropdown", "multiple": True}
@ -209,4 +214,5 @@ class EmoncmsOptionsFlow(OptionsFlow):
}
),
errors=errors,
description_placeholders=description_placeholders,
)

View File

@ -1,5 +1,8 @@
{
"config": {
"error": {
"api_error": "An error occured in the pyemoncms API : {details}"
},
"step": {
"user": {
"data": {
@ -19,6 +22,9 @@
}
},
"options": {
"error": {
"api_error": "[%key:component::emoncms::config::error::api_error%]"
},
"step": {
"init": {
"data": {

View File

@ -2,8 +2,6 @@
from unittest.mock import AsyncMock
import pytest
from homeassistant.components.emoncms.const import CONF_ONLY_INCLUDE_FEEDID, DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.const import CONF_API_KEY, CONF_URL
@ -44,7 +42,7 @@ async def test_flow_import_failure(
data=YAML,
)
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == EMONCMS_FAILURE["message"]
assert result["reason"] == "api_error"
async def test_flow_import_already_configured(
@ -129,10 +127,6 @@ async def test_options_flow(
assert config_entry.options == CONFIG_ENTRY
@pytest.mark.parametrize( # Remove when translations fixed
"ignore_translations",
["component.emoncms.options.error.failure"],
)
async def test_options_flow_failure(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
@ -144,6 +138,7 @@ async def test_options_flow_failure(
await setup_integration(hass, config_entry)
result = await hass.config_entries.options.async_init(config_entry.entry_id)
await hass.async_block_till_done()
assert result["errors"]["base"] == "failure"
assert result["errors"]["base"] == "api_error"
assert result["description_placeholders"]["details"] == "failure"
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "init"