From f42eca3fcf70de9dcbf475ab298ed19d802f66b0 Mon Sep 17 00:00:00 2001 From: Fredrik Erlandsson Date: Thu, 8 Oct 2020 21:25:54 +0200 Subject: [PATCH] Add common strings in daikin config flow (#41419) --- homeassistant/components/daikin/__init__.py | 6 +++--- homeassistant/components/daikin/config_flow.py | 18 +++++++++--------- homeassistant/components/daikin/const.py | 1 - homeassistant/components/daikin/strings.json | 10 +++++----- tests/components/daikin/test_config_flow.py | 8 ++++---- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/daikin/__init__.py b/homeassistant/components/daikin/__init__.py index 65a3bf28c3b..7b9c1ded673 100644 --- a/homeassistant/components/daikin/__init__.py +++ b/homeassistant/components/daikin/__init__.py @@ -9,7 +9,7 @@ from pydaikin.daikin_base import Appliance import voluptuous as vol from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import CONF_HOST, CONF_HOSTS, CONF_PASSWORD +from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_HOSTS, CONF_PASSWORD from homeassistant.exceptions import ConfigEntryNotReady import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC @@ -17,7 +17,7 @@ from homeassistant.helpers.typing import HomeAssistantType from homeassistant.util import Throttle from . import config_flow # noqa: F401 -from .const import CONF_KEY, CONF_UUID, KEY_MAC, TIMEOUT +from .const import CONF_UUID, KEY_MAC, TIMEOUT _LOGGER = logging.getLogger(__name__) @@ -77,7 +77,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry): daikin_api = await daikin_api_setup( hass, conf[CONF_HOST], - conf.get(CONF_KEY), + conf.get(CONF_API_KEY), conf.get(CONF_UUID), conf.get(CONF_PASSWORD), ) diff --git a/homeassistant/components/daikin/config_flow.py b/homeassistant/components/daikin/config_flow.py index 7142771a7c3..b9956a87af0 100644 --- a/homeassistant/components/daikin/config_flow.py +++ b/homeassistant/components/daikin/config_flow.py @@ -10,9 +10,9 @@ from pydaikin.discovery import Discovery import voluptuous as vol from homeassistant import config_entries -from homeassistant.const import CONF_HOST, CONF_PASSWORD +from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD -from .const import CONF_KEY, CONF_UUID, KEY_IP, KEY_MAC, TIMEOUT +from .const import CONF_UUID, KEY_IP, KEY_MAC, TIMEOUT _LOGGER = logging.getLogger(__name__) @@ -34,7 +34,7 @@ class FlowHandler(config_entries.ConfigFlow): return vol.Schema( { vol.Required(CONF_HOST, default=self.host): str, - vol.Optional(CONF_KEY): str, + vol.Optional(CONF_API_KEY): str, vol.Optional(CONF_PASSWORD): str, } ) @@ -50,7 +50,7 @@ class FlowHandler(config_entries.ConfigFlow): data={ CONF_HOST: host, KEY_MAC: mac, - CONF_KEY: key, + CONF_API_KEY: key, CONF_UUID: uuid, CONF_PASSWORD: password, }, @@ -81,27 +81,27 @@ class FlowHandler(config_entries.ConfigFlow): return self.async_show_form( step_id="user", data_schema=self.schema, - errors={"base": "device_timeout"}, + errors={"base": "cannot_connect"}, ) except web_exceptions.HTTPForbidden: return self.async_show_form( step_id="user", data_schema=self.schema, - errors={"base": "forbidden"}, + errors={"base": "invalid_auth"}, ) except ClientError: _LOGGER.exception("ClientError") return self.async_show_form( step_id="user", data_schema=self.schema, - errors={"base": "device_fail"}, + errors={"base": "unknown"}, ) except Exception: # pylint: disable=broad-except _LOGGER.exception("Unexpected error creating device") return self.async_show_form( step_id="user", data_schema=self.schema, - errors={"base": "device_fail"}, + errors={"base": "unknown"}, ) mac = device.mac @@ -113,7 +113,7 @@ class FlowHandler(config_entries.ConfigFlow): return self.async_show_form(step_id="user", data_schema=self.schema) return await self._create_device( user_input[CONF_HOST], - user_input.get(CONF_KEY), + user_input.get(CONF_API_KEY), user_input.get(CONF_PASSWORD), ) diff --git a/homeassistant/components/daikin/const.py b/homeassistant/components/daikin/const.py index 6662954c1dc..00bbbefd051 100644 --- a/homeassistant/components/daikin/const.py +++ b/homeassistant/components/daikin/const.py @@ -76,7 +76,6 @@ SENSOR_TYPES = { }, } -CONF_KEY = "key" CONF_UUID = "uuid" KEY_MAC = "mac" diff --git a/homeassistant/components/daikin/strings.json b/homeassistant/components/daikin/strings.json index a8ebe0911b6..fc2b6e79a5e 100644 --- a/homeassistant/components/daikin/strings.json +++ b/homeassistant/components/daikin/strings.json @@ -3,10 +3,10 @@ "step": { "user": { "title": "Configure Daikin AC", - "description": "Enter IP address of your Daikin AC.\n\nNote that [%key:common::config_flow::data::api_key%] and [%key:common::config_flow::data::password%] are used by BRP072Cxx and SKYFi devices respectively.", + "description": "Enter [%key:common::config_flow::data::ip%] of your Daikin AC.\n\nNote that [%key:common::config_flow::data::api_key%] and [%key:common::config_flow::data::password%] only are used by BRP072Cxx and SKYFi devices respectively.", "data": { "host": "[%key:common::config_flow::data::host%]", - "key": "[%key:common::config_flow::data::api_key%]", + "api_key": "[%key:common::config_flow::data::api_key%]", "password": "[%key:common::config_flow::data::password%]" } } @@ -16,9 +16,9 @@ "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" }, "error": { - "device_fail": "[%key:common::config_flow::error::unknown%]", - "forbidden": "[%key:common::config_flow::error::invalid_auth%]", - "device_timeout": "[%key:common::config_flow::error::cannot_connect%]" + "unknown": "[%key:common::config_flow::error::unknown%]", + "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", + "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]" } } } diff --git a/tests/components/daikin/test_config_flow.py b/tests/components/daikin/test_config_flow.py index 324c73dfb81..3e4ddb6d3fd 100644 --- a/tests/components/daikin/test_config_flow.py +++ b/tests/components/daikin/test_config_flow.py @@ -109,10 +109,10 @@ async def test_import(hass, mock_daikin): @pytest.mark.parametrize( "s_effect,reason", [ - (asyncio.TimeoutError, "device_timeout"), - (HTTPForbidden, "forbidden"), - (ClientError, "device_fail"), - (Exception, "device_fail"), + (asyncio.TimeoutError, "cannot_connect"), + (HTTPForbidden, "invalid_auth"), + (ClientError, "unknown"), + (Exception, "unknown"), ], ) async def test_device_abort(hass, mock_daikin, s_effect, reason):