Add return code to integration application credentials in config flow (#71986)

* Add return code to integration application credentials in config flow

* Update google tests to use new return code

* Update spotify test for no auth configured

* Add translation for oauth2_missing_credentials

* Add new return code to yolink

* Update homeassistant/strings.json

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Allen Porter 2022-05-18 06:30:57 -07:00 committed by GitHub
parent 23cb5cfd3f
commit 26ee289be3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 5 deletions

View file

@ -25,6 +25,7 @@ from homeassistant import config_entries
from homeassistant.components import http from homeassistant.components import http
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResult from homeassistant.data_entry_flow import FlowResult
from homeassistant.loader import async_get_application_credentials
from .aiohttp_client import async_get_clientsession from .aiohttp_client import async_get_clientsession
from .network import NoURLAvailableError from .network import NoURLAvailableError
@ -239,6 +240,8 @@ class AbstractOAuth2FlowHandler(config_entries.ConfigFlow, metaclass=ABCMeta):
return await self.async_step_auth() return await self.async_step_auth()
if not implementations: if not implementations:
if self.DOMAIN in await async_get_application_credentials(self.hass):
return self.async_abort(reason="missing_credentials")
return self.async_abort(reason="missing_configuration") return self.async_abort(reason="missing_configuration")
req = http.current_request.get() req = http.current_request.get()

View file

@ -71,6 +71,7 @@
"webhook_not_internet_accessible": "Your Home Assistant instance needs to be accessible from the internet to receive webhook messages.", "webhook_not_internet_accessible": "Your Home Assistant instance needs to be accessible from the internet to receive webhook messages.",
"oauth2_error": "Received invalid token data.", "oauth2_error": "Received invalid token data.",
"oauth2_missing_configuration": "The component is not configured. Please follow the documentation.", "oauth2_missing_configuration": "The component is not configured. Please follow the documentation.",
"oauth2_missing_credentials": "The integration requires application credentials.",
"oauth2_authorize_url_timeout": "Timeout generating authorize URL.", "oauth2_authorize_url_timeout": "Timeout generating authorize URL.",
"oauth2_no_url_available": "No URL available. For information about this error, [check the help section]({docs_url})", "oauth2_no_url_available": "No URL available. For information about this error, [check the help section]({docs_url})",
"reauth_successful": "Re-authentication was successful", "reauth_successful": "Re-authentication was successful",

View file

@ -327,7 +327,7 @@ async def test_missing_configuration(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
) )
assert result.get("type") == "abort" assert result.get("type") == "abort"
assert result.get("reason") == "missing_configuration" assert result.get("reason") == "missing_credentials"
@pytest.mark.parametrize("google_config", [None]) @pytest.mark.parametrize("google_config", [None])
@ -342,7 +342,7 @@ async def test_missing_configuration_yaml_empty(
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
) )
assert result.get("type") == "abort" assert result.get("type") == "abort"
assert result.get("reason") == "missing_configuration" assert result.get("reason") == "missing_credentials"
async def test_wrong_configuration( async def test_wrong_configuration(

View file

@ -31,14 +31,14 @@ async def test_abort_if_no_configuration(hass):
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "missing_configuration" assert result["reason"] == "missing_credentials"
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_ZEROCONF}, data=BLANK_ZEROCONF_INFO DOMAIN, context={"source": SOURCE_ZEROCONF}, data=BLANK_ZEROCONF_INFO
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "missing_configuration" assert result["reason"] == "missing_credentials"
async def test_zeroconf_abort_if_existing_entry(hass): async def test_zeroconf_abort_if_existing_entry(hass):

View file

@ -25,7 +25,7 @@ async def test_abort_if_no_configuration(hass):
DOMAIN, context={"source": config_entries.SOURCE_USER} DOMAIN, context={"source": config_entries.SOURCE_USER}
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "missing_configuration" assert result["reason"] == "missing_credentials"
async def test_abort_if_existing_entry(hass: HomeAssistant): async def test_abort_if_existing_entry(hass: HomeAssistant):

View file

@ -114,6 +114,17 @@ async def test_abort_if_no_implementation(hass, flow_handler):
assert result["reason"] == "missing_configuration" assert result["reason"] == "missing_configuration"
async def test_missing_credentials_for_domain(hass, flow_handler):
"""Check flow abort for integration supporting application credentials."""
flow = flow_handler()
flow.hass = hass
with patch("homeassistant.loader.APPLICATION_CREDENTIALS", [TEST_DOMAIN]):
result = await flow.async_step_user()
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "missing_credentials"
async def test_abort_if_authorization_timeout( async def test_abort_if_authorization_timeout(
hass, flow_handler, local_impl, current_request_with_host hass, flow_handler, local_impl, current_request_with_host
): ):