1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Search/replace RESULT_TYPE_* by FlowResultType enum (#74656)

This commit is contained in:
Franck Nijhof
2022-07-07 21:28:18 +02:00
committed by GitHub
parent 46beae9061
commit a6244eea28
142 changed files with 1463 additions and 1849 deletions

View File

@@ -15,11 +15,7 @@ from homeassistant import config_entries
from homeassistant.components import dhcp, zeroconf
from homeassistant.components.esphome import CONF_NOISE_PSK, DOMAIN, DomainData
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
from homeassistant.data_entry_flow import (
RESULT_TYPE_ABORT,
RESULT_TYPE_CREATE_ENTRY,
RESULT_TYPE_FORM,
)
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
@@ -66,7 +62,7 @@ async def test_user_connection_works(hass, mock_client, mock_zeroconf):
data=None,
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test"))
@@ -77,7 +73,7 @@ async def test_user_connection_works(hass, mock_client, mock_zeroconf):
data={CONF_HOST: "127.0.0.1", CONF_PORT: 80},
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"] == {
CONF_HOST: "127.0.0.1",
CONF_PORT: 80,
@@ -109,7 +105,7 @@ async def test_user_resolve_error(hass, mock_client, mock_zeroconf):
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "resolve_error"}
@@ -128,7 +124,7 @@ async def test_user_connection_error(hass, mock_client, mock_zeroconf):
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "connection_error"}
@@ -147,14 +143,14 @@ async def test_user_with_password(hass, mock_client, mock_zeroconf):
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "authenticate"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_PASSWORD: "password1"}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"] == {
CONF_HOST: "127.0.0.1",
CONF_PORT: 6053,
@@ -174,7 +170,7 @@ async def test_user_invalid_password(hass, mock_client, mock_zeroconf):
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "authenticate"
mock_client.connect.side_effect = InvalidAuthAPIError
@@ -183,7 +179,7 @@ async def test_user_invalid_password(hass, mock_client, mock_zeroconf):
result["flow_id"], user_input={CONF_PASSWORD: "invalid"}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "authenticate"
assert result["errors"] == {"base": "invalid_auth"}
@@ -198,7 +194,7 @@ async def test_login_connection_error(hass, mock_client, mock_zeroconf):
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "authenticate"
mock_client.connect.side_effect = APIConnectionError
@@ -207,7 +203,7 @@ async def test_login_connection_error(hass, mock_client, mock_zeroconf):
result["flow_id"], user_input={CONF_PASSWORD: "valid"}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "authenticate"
assert result["errors"] == {"base": "connection_error"}
@@ -233,7 +229,7 @@ async def test_discovery_initiation(hass, mock_client, mock_zeroconf):
flow["flow_id"], user_input={}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "test8266"
assert result["data"][CONF_HOST] == "192.168.43.183"
assert result["data"][CONF_PORT] == 6053
@@ -264,7 +260,7 @@ async def test_discovery_already_configured_hostname(hass, mock_client):
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266"
@@ -292,7 +288,7 @@ async def test_discovery_already_configured_ip(hass, mock_client):
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266"
@@ -324,7 +320,7 @@ async def test_discovery_already_configured_name(hass, mock_client):
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266"
@@ -348,13 +344,13 @@ async def test_discovery_duplicate_data(hass, mock_client):
result = await hass.config_entries.flow.async_init(
"esphome", data=service_info, context={"source": config_entries.SOURCE_ZEROCONF}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "discovery_confirm"
result = await hass.config_entries.flow.async_init(
"esphome", data=service_info, context={"source": config_entries.SOURCE_ZEROCONF}
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_in_progress"
@@ -380,7 +376,7 @@ async def test_discovery_updates_unique_id(hass, mock_client):
"esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266"
@@ -396,7 +392,7 @@ async def test_user_requires_psk(hass, mock_client, mock_zeroconf):
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "encryption_key"
assert result["errors"] == {}
@@ -416,7 +412,7 @@ async def test_encryption_key_valid_psk(hass, mock_client, mock_zeroconf):
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "encryption_key"
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test"))
@@ -424,7 +420,7 @@ async def test_encryption_key_valid_psk(hass, mock_client, mock_zeroconf):
result["flow_id"], user_input={CONF_NOISE_PSK: VALID_NOISE_PSK}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["data"] == {
CONF_HOST: "127.0.0.1",
CONF_PORT: 6053,
@@ -445,7 +441,7 @@ async def test_encryption_key_invalid_psk(hass, mock_client, mock_zeroconf):
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "encryption_key"
mock_client.device_info.side_effect = InvalidEncryptionKeyAPIError
@@ -453,7 +449,7 @@ async def test_encryption_key_invalid_psk(hass, mock_client, mock_zeroconf):
result["flow_id"], user_input={CONF_NOISE_PSK: INVALID_NOISE_PSK}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "encryption_key"
assert result["errors"] == {"base": "invalid_psk"}
assert mock_client.noise_psk == INVALID_NOISE_PSK
@@ -475,7 +471,7 @@ async def test_reauth_initiation(hass, mock_client, mock_zeroconf):
"unique_id": entry.unique_id,
},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@@ -501,7 +497,7 @@ async def test_reauth_confirm_valid(hass, mock_client, mock_zeroconf):
result["flow_id"], user_input={CONF_NOISE_PSK: VALID_NOISE_PSK}
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
assert entry.data[CONF_NOISE_PSK] == VALID_NOISE_PSK
@@ -528,7 +524,7 @@ async def test_reauth_confirm_invalid(hass, mock_client, mock_zeroconf):
result["flow_id"], user_input={CONF_NOISE_PSK: INVALID_NOISE_PSK}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
assert result["errors"]
assert result["errors"]["base"] == "invalid_psk"
@@ -556,7 +552,7 @@ async def test_discovery_dhcp_updates_host(hass, mock_client):
"esphome", context={"source": config_entries.SOURCE_DHCP}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266"
@@ -585,7 +581,7 @@ async def test_discovery_dhcp_no_changes(hass, mock_client):
"esphome", context={"source": config_entries.SOURCE_DHCP}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266"