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 <marhje52@gmail.com>pull/41412/head
parent
306ee30574
commit
d3bc4efa89
|
@ -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")
|
||||
|
|
|
@ -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%]"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue