From 6caa4baa007e160d673029c4d84eb0fb35980292 Mon Sep 17 00:00:00 2001 From: Alexandre CUER Date: Tue, 5 Nov 2024 14:58:25 +0100 Subject: [PATCH] Fix missing translation string in emoncms (#129859) --- homeassistant/components/emoncms/config_flow.py | 10 ++++++++-- homeassistant/components/emoncms/strings.json | 6 ++++++ tests/components/emoncms/test_config_flow.py | 11 +++-------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/emoncms/config_flow.py b/homeassistant/components/emoncms/config_flow.py index fa684188713..e2e08217b3c 100644 --- a/homeassistant/components/emoncms/config_flow.py +++ b/homeassistant/components/emoncms/config_flow.py @@ -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, ) diff --git a/homeassistant/components/emoncms/strings.json b/homeassistant/components/emoncms/strings.json index 4a700cc8981..e2b7602f6f2 100644 --- a/homeassistant/components/emoncms/strings.json +++ b/homeassistant/components/emoncms/strings.json @@ -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": { diff --git a/tests/components/emoncms/test_config_flow.py b/tests/components/emoncms/test_config_flow.py index b554466639e..43710967a01 100644 --- a/tests/components/emoncms/test_config_flow.py +++ b/tests/components/emoncms/test_config_flow.py @@ -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"