From 7eaa304fc3b278a90322bae09d718589bec41038 Mon Sep 17 00:00:00 2001 From: Pigotka Date: Mon, 5 Oct 2020 19:22:02 +0200 Subject: [PATCH] Use of reference strings in Heos config flow (#41282) --- homeassistant/components/heos/config_flow.py | 6 +++--- homeassistant/components/heos/strings.json | 4 ++-- tests/components/heos/test_config_flow.py | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/heos/config_flow.py b/homeassistant/components/heos/config_flow.py index 138d1c4462c..efffb93e978 100644 --- a/homeassistant/components/heos/config_flow.py +++ b/homeassistant/components/heos/config_flow.py @@ -32,7 +32,7 @@ class HeosFlowHandler(config_entries.ConfigFlow): self.hass.data[DATA_DISCOVERED_HOSTS][friendly_name] = hostname # Abort if other flows in progress or an entry already exists if self._async_in_progress() or self._async_current_entries(): - return self.async_abort(reason="already_setup") + return self.async_abort(reason="single_instance_allowed") await self.async_set_unique_id(DOMAIN) # Show selection form return self.async_show_form(step_id="user") @@ -50,7 +50,7 @@ class HeosFlowHandler(config_entries.ConfigFlow): self.hass.data.setdefault(DATA_DISCOVERED_HOSTS, {}) # Only a single entry is needed for all devices if self._async_current_entries(): - return self.async_abort(reason="already_setup") + return self.async_abort(reason="single_instance_allowed") # Try connecting to host if provided errors = {} host = None @@ -64,7 +64,7 @@ class HeosFlowHandler(config_entries.ConfigFlow): self.hass.data.pop(DATA_DISCOVERED_HOSTS) return await self.async_step_import({CONF_HOST: host}) except HeosError: - errors[CONF_HOST] = "connection_failure" + errors[CONF_HOST] = "cannot_connect" finally: await heos.disconnect() diff --git a/homeassistant/components/heos/strings.json b/homeassistant/components/heos/strings.json index b633b3c82b6..09ada292afd 100644 --- a/homeassistant/components/heos/strings.json +++ b/homeassistant/components/heos/strings.json @@ -10,10 +10,10 @@ } }, "error": { - "connection_failure": "Unable to connect to the specified host." + "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" }, "abort": { - "already_setup": "You can only configure a single Heos connection as it will support all devices on the network." + "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" } } } diff --git a/tests/components/heos/test_config_flow.py b/tests/components/heos/test_config_flow.py index 800814df013..bcc2ed67b29 100644 --- a/tests/components/heos/test_config_flow.py +++ b/tests/components/heos/test_config_flow.py @@ -20,7 +20,7 @@ async def test_flow_aborts_already_setup(hass, config_entry): flow.hass = hass result = await flow.async_step_user() assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "already_setup" + assert result["reason"] == "single_instance_allowed" async def test_no_host_shows_form(hass): @@ -41,7 +41,7 @@ async def test_cannot_connect_shows_error_form(hass, controller): ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" - assert result["errors"][CONF_HOST] == "connection_failure" + assert result["errors"][CONF_HOST] == "cannot_connect" assert controller.connect.call_count == 1 assert controller.disconnect.call_count == 1 controller.connect.reset_mock() @@ -118,7 +118,7 @@ async def test_discovery_flow_aborts_already_setup( flow.hass = hass result = await flow.async_step_ssdp(discovery_data) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "already_setup" + assert result["reason"] == "single_instance_allowed" async def test_discovery_sets_the_unique_id(hass, controller, discovery_data):