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})"
|
title = f"{user.email} ({user.user_id})"
|
||||||
return self.async_create_entry(title=title, data=user_input)
|
return self.async_create_entry(title=title, data=user_input)
|
||||||
|
|
||||||
if error != "auth":
|
if error != "invalid_access_token":
|
||||||
return self.async_abort(reason=error)
|
return self.async_abort(reason=error)
|
||||||
|
|
||||||
errors = {CONF_ACCESS_TOKEN: "auth"}
|
errors = {CONF_ACCESS_TOKEN: "invalid_access_token"}
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
|
@ -78,7 +78,7 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
return self.async_abort(reason="reauth_successful")
|
||||||
|
|
||||||
if error != "auth":
|
if error != "invalid_access_token":
|
||||||
return self.async_abort(reason=error)
|
return self.async_abort(reason=error)
|
||||||
|
|
||||||
errors = {CONF_ACCESS_TOKEN: error}
|
errors = {CONF_ACCESS_TOKEN: error}
|
||||||
|
@ -98,12 +98,12 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
user = await awair.user()
|
user = await awair.user()
|
||||||
devices = await user.devices()
|
devices = await user.devices()
|
||||||
if not devices:
|
if not devices:
|
||||||
return (None, "no_devices")
|
return (None, "no_devices_found")
|
||||||
|
|
||||||
return (user, None)
|
return (user, None)
|
||||||
|
|
||||||
except AuthError:
|
except AuthError:
|
||||||
return (None, "auth")
|
return (None, "invalid_access_token")
|
||||||
except AwairError as err:
|
except AwairError as err:
|
||||||
LOGGER.error("Unexpected API error: %s", err)
|
LOGGER.error("Unexpected API error: %s", err)
|
||||||
return (None, "unknown")
|
return (None, "unknown")
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"auth": "[%key:common::config_flow::error::invalid_access_token%]",
|
"invalid_access_token": "[%key:common::config_flow::error::invalid_access_token%]",
|
||||||
"unknown": "Unknown Awair API error."
|
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
|
"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%]"
|
"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
|
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):
|
async def test_unexpected_api_error(hass):
|
||||||
|
@ -78,7 +78,7 @@ async def test_no_devices_error(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
assert result["reason"] == "no_devices"
|
assert result["reason"] == "no_devices_found"
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass):
|
async def test_import(hass):
|
||||||
|
@ -169,7 +169,7 @@ async def test_reauth(hass):
|
||||||
data=CONFIG,
|
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()):
|
with patch("python_awair.AwairClient.query", side_effect=AwairError()):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
|
Loading…
Reference in New Issue