From d3bc4efa89b50873464acea571a4852e1f797dee Mon Sep 17 00:00:00 2001 From: Dave T <17680170+davet2001@users.noreply.github.com> Date: Wed, 7 Oct 2020 14:17:10 +0100 Subject: [PATCH] Use common strings in Awair (#41313) * awair use common strings * Use common strings: 'auth' to invalid_access_token * Use reauth successful ref Co-authored-by: Martin Hjelmare --- homeassistant/components/awair/config_flow.py | 10 +++++----- homeassistant/components/awair/strings.json | 6 +++--- tests/components/awair/test_config_flow.py | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/awair/config_flow.py b/homeassistant/components/awair/config_flow.py index 886a51342c53..a4768014f96a 100644 --- a/homeassistant/components/awair/config_flow.py +++ b/homeassistant/components/awair/config_flow.py @@ -50,10 +50,10 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN): title = f"{user.email} ({user.user_id})" return self.async_create_entry(title=title, data=user_input) - if error != "auth": + if error != "invalid_access_token": return self.async_abort(reason=error) - errors = {CONF_ACCESS_TOKEN: "auth"} + errors = {CONF_ACCESS_TOKEN: "invalid_access_token"} return self.async_show_form( step_id="user", @@ -78,7 +78,7 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN): return self.async_abort(reason="reauth_successful") - if error != "auth": + if error != "invalid_access_token": return self.async_abort(reason=error) errors = {CONF_ACCESS_TOKEN: error} @@ -98,12 +98,12 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN): user = await awair.user() devices = await user.devices() if not devices: - return (None, "no_devices") + return (None, "no_devices_found") return (user, None) except AuthError: - return (None, "auth") + return (None, "invalid_access_token") except AwairError as err: LOGGER.error("Unexpected API error: %s", err) return (None, "unknown") diff --git a/homeassistant/components/awair/strings.json b/homeassistant/components/awair/strings.json index 10041e19e569..f9b1f40e0479 100644 --- a/homeassistant/components/awair/strings.json +++ b/homeassistant/components/awair/strings.json @@ -17,12 +17,12 @@ } }, "error": { - "auth": "[%key:common::config_flow::error::invalid_access_token%]", - "unknown": "Unknown Awair API error." + "invalid_access_token": "[%key:common::config_flow::error::invalid_access_token%]", + "unknown": "[%key:common::config_flow::error::unknown%]" }, "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_account%]", - "no_devices": "[%key:common::config_flow::abort::no_devices_found%]", + "no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]", "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" } } diff --git a/tests/components/awair/test_config_flow.py b/tests/components/awair/test_config_flow.py index 632539931175..6dcbc7eac9ec 100644 --- a/tests/components/awair/test_config_flow.py +++ b/tests/components/awair/test_config_flow.py @@ -31,7 +31,7 @@ async def test_invalid_access_token(hass): DOMAIN, context={"source": SOURCE_USER}, data=CONFIG ) - assert result["errors"] == {CONF_ACCESS_TOKEN: "auth"} + assert result["errors"] == {CONF_ACCESS_TOKEN: "invalid_access_token"} async def test_unexpected_api_error(hass): @@ -78,7 +78,7 @@ async def test_no_devices_error(hass): ) assert result["type"] == "abort" - assert result["reason"] == "no_devices" + assert result["reason"] == "no_devices_found" async def test_import(hass): @@ -169,7 +169,7 @@ async def test_reauth(hass): data=CONFIG, ) - assert result["errors"] == {CONF_ACCESS_TOKEN: "auth"} + assert result["errors"] == {CONF_ACCESS_TOKEN: "invalid_access_token"} with patch("python_awair.AwairClient.query", side_effect=AwairError()): result = await hass.config_entries.flow.async_init(