diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py index d1ea3826e2f..2029903bedf 100644 --- a/homeassistant/components/deconz/config_flow.py +++ b/homeassistant/components/deconz/config_flow.py @@ -199,7 +199,7 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): parsed_url = urlparse(discovery_info[ssdp.ATTR_SSDP_LOCATION]) entry = await self.async_set_unique_id(self.bridge_id) - if entry and entry.source == "hassio": + if entry and entry.source == config_entries.SOURCE_HASSIO: return self.async_abort(reason="already_configured") self._abort_if_unique_id_configured( diff --git a/homeassistant/components/hassio/discovery.py b/homeassistant/components/hassio/discovery.py index c682e34c301..e7f8df3b61d 100644 --- a/homeassistant/components/hassio/discovery.py +++ b/homeassistant/components/hassio/discovery.py @@ -5,6 +5,7 @@ import logging from aiohttp import web from aiohttp.web_exceptions import HTTPServiceUnavailable +from homeassistant import config_entries from homeassistant.components.http import HomeAssistantView from homeassistant.const import ATTR_NAME, ATTR_SERVICE, EVENT_HOMEASSISTANT_START from homeassistant.core import callback @@ -87,7 +88,7 @@ class HassIODiscovery(HomeAssistantView): # Use config flow await self.hass.config_entries.flow.async_init( - service, context={"source": "hassio"}, data=config_data + service, context={"source": config_entries.SOURCE_HASSIO}, data=config_data ) async def async_process_del(self, data): @@ -106,6 +107,6 @@ class HassIODiscovery(HomeAssistantView): # Use config flow for entry in self.hass.config_entries.async_entries(service): - if entry.source != "hassio": + if entry.source != config_entries.SOURCE_HASSIO: continue await self.hass.config_entries.async_remove(entry) diff --git a/homeassistant/components/heos/__init__.py b/homeassistant/components/heos/__init__.py index fb51c1d158c..652aa844832 100644 --- a/homeassistant/components/heos/__init__.py +++ b/homeassistant/components/heos/__init__.py @@ -9,7 +9,7 @@ from pyheos import Heos, HeosError, const as heos_const import voluptuous as vol from homeassistant.components.media_player.const import DOMAIN as MEDIA_PLAYER_DOMAIN -from homeassistant.config_entries import ConfigEntry +from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import CONF_HOST, EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady @@ -47,7 +47,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType): # Create new entry based on config hass.async_create_task( hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data={CONF_HOST: host} + DOMAIN, context={"source": SOURCE_IMPORT}, data={CONF_HOST: host} ) ) else: diff --git a/homeassistant/components/samsungtv/__init__.py b/homeassistant/components/samsungtv/__init__.py index 8c17ff4794c..64646533b2d 100644 --- a/homeassistant/components/samsungtv/__init__.py +++ b/homeassistant/components/samsungtv/__init__.py @@ -3,6 +3,7 @@ import socket import voluptuous as vol +from homeassistant import config_entries from homeassistant.components.media_player.const import DOMAIN as MP_DOMAIN from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT import homeassistant.helpers.config_validation as cv @@ -53,7 +54,9 @@ async def async_setup(hass, config): } hass.async_create_task( hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=entry_config + DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data=entry_config, ) ) diff --git a/homeassistant/components/smartthings/__init__.py b/homeassistant/components/smartthings/__init__.py index 456857efc9b..d9a96301e66 100644 --- a/homeassistant/components/smartthings/__init__.py +++ b/homeassistant/components/smartthings/__init__.py @@ -10,7 +10,7 @@ from aiohttp.client_exceptions import ClientConnectionError, ClientResponseError from pysmartapp.event import EVENT_TYPE_DEVICE from pysmartthings import Attribute, Capability, SmartThings -from homeassistant.config_entries import ConfigEntry +from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.const import ( CONF_ACCESS_TOKEN, CONF_CLIENT_ID, @@ -75,7 +75,9 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry): flows = hass.config_entries.flow.async_progress() if not [flow for flow in flows if flow["handler"] == DOMAIN]: hass.async_create_task( - hass.config_entries.flow.async_init(DOMAIN, context={"source": "import"}) + hass.config_entries.flow.async_init( + DOMAIN, context={"source": SOURCE_IMPORT} + ) ) # Return False because it could not be migrated. @@ -182,7 +184,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): if not [flow for flow in flows if flow["handler"] == DOMAIN]: hass.async_create_task( hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"} + DOMAIN, context={"source": SOURCE_IMPORT} ) ) return False diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index 7d4205279ed..58d8ad21094 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -23,7 +23,7 @@ from zeroconf import ( Zeroconf, ) -from homeassistant import util +from homeassistant import config_entries, util from homeassistant.const import ( EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STARTED, @@ -401,7 +401,9 @@ def handle_homekit( hass.add_job( hass.config_entries.flow.async_init( - homekit_models[test_model], context={"source": "homekit"}, data=info + homekit_models[test_model], + context={"source": config_entries.SOURCE_HOMEKIT}, + data=info, ) # type: ignore ) return True diff --git a/tests/components/abode/test_config_flow.py b/tests/components/abode/test_config_flow.py index 026735ed536..806038194bb 100644 --- a/tests/components/abode/test_config_flow.py +++ b/tests/components/abode/test_config_flow.py @@ -7,7 +7,7 @@ from abodepy.helpers.errors import MFA_CODE_REQUIRED from homeassistant import data_entry_flow from homeassistant.components.abode import config_flow from homeassistant.components.abode.const import DOMAIN -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH, SOURCE_USER from homeassistant.const import ( CONF_PASSWORD, CONF_USERNAME, @@ -190,7 +190,7 @@ async def test_step_reauth(hass): ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth"}, + context={"source": SOURCE_REAUTH}, data=conf, ) diff --git a/tests/components/adguard/test_config_flow.py b/tests/components/adguard/test_config_flow.py index 17fcbda666d..872f9e5807e 100644 --- a/tests/components/adguard/test_config_flow.py +++ b/tests/components/adguard/test_config_flow.py @@ -96,7 +96,7 @@ async def test_integration_already_exists(hass: HomeAssistant) -> None: result = await hass.config_entries.flow.async_init( DOMAIN, data={"host": "mock-adguard", "port": "3000"}, - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, ) assert result["type"] == "abort" assert result["reason"] == "already_configured" @@ -111,7 +111,7 @@ async def test_hassio_already_configured(hass: HomeAssistant) -> None: result = await hass.config_entries.flow.async_init( DOMAIN, data={"addon": "AdGuard Home Addon", "host": "mock-adguard", "port": "3000"}, - context={"source": "hassio"}, + context={"source": config_entries.SOURCE_HASSIO}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" @@ -126,7 +126,7 @@ async def test_hassio_ignored(hass: HomeAssistant) -> None: result = await hass.config_entries.flow.async_init( DOMAIN, data={"addon": "AdGuard Home Addon", "host": "mock-adguard", "port": "3000"}, - context={"source": "hassio"}, + context={"source": config_entries.SOURCE_HASSIO}, ) assert "type" in result @@ -148,7 +148,7 @@ async def test_hassio_confirm( result = await hass.config_entries.flow.async_init( DOMAIN, data={"addon": "AdGuard Home Addon", "host": "mock-adguard", "port": 3000}, - context={"source": "hassio"}, + context={"source": config_entries.SOURCE_HASSIO}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "hassio_confirm" @@ -176,7 +176,7 @@ async def test_hassio_connection_error( result = await hass.config_entries.flow.async_init( DOMAIN, data={"addon": "AdGuard Home Addon", "host": "mock-adguard", "port": 3000}, - context={"source": "hassio"}, + context={"source": config_entries.SOURCE_HASSIO}, ) result = await hass.config_entries.flow.async_configure(result["flow_id"], {}) diff --git a/tests/components/airvisual/test_config_flow.py b/tests/components/airvisual/test_config_flow.py index 248abaf6b5f..d7c5a08b62a 100644 --- a/tests/components/airvisual/test_config_flow.py +++ b/tests/components/airvisual/test_config_flow.py @@ -19,7 +19,7 @@ from homeassistant.components.airvisual.const import ( INTEGRATION_TYPE_GEOGRAPHY_NAME, INTEGRATION_TYPE_NODE_PRO, ) -from homeassistant.config_entries import SOURCE_USER +from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER from homeassistant.const import ( CONF_API_KEY, CONF_IP_ADDRESS, @@ -349,7 +349,7 @@ async def test_step_reauth(hass): ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=entry_data + DOMAIN, context={"source": SOURCE_REAUTH}, data=entry_data ) assert result["step_id"] == "reauth_confirm" diff --git a/tests/components/almond/test_config_flow.py b/tests/components/almond/test_config_flow.py index 8f6b68e47ee..892abaa9650 100644 --- a/tests/components/almond/test_config_flow.py +++ b/tests/components/almond/test_config_flow.py @@ -49,7 +49,7 @@ async def test_hassio(hass): """Test that Hass.io can discover this integration.""" result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "hassio"}, + context={"source": config_entries.SOURCE_HASSIO}, data={"addon": "Almond add-on", "host": "almond-addon", "port": "1234"}, ) diff --git a/tests/components/apple_tv/test_config_flow.py b/tests/components/apple_tv/test_config_flow.py index c55bef8edfd..615a1f404f5 100644 --- a/tests/components/apple_tv/test_config_flow.py +++ b/tests/components/apple_tv/test_config_flow.py @@ -519,7 +519,7 @@ async def test_reconfigure_update_credentials(hass, mrp_device, pairing): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth"}, + context={"source": config_entries.SOURCE_REAUTH}, data={"identifier": "mrpid", "name": "apple tv"}, ) @@ -552,11 +552,11 @@ async def test_reconfigure_ongoing_aborts(hass, mrp_device): } await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=data + DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=data ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=data + DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=data ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_in_progress" diff --git a/tests/components/august/test_config_flow.py b/tests/components/august/test_config_flow.py index c87291e0f79..53dac38fb1e 100644 --- a/tests/components/august/test_config_flow.py +++ b/tests/components/august/test_config_flow.py @@ -238,7 +238,7 @@ async def test_form_reauth(hass): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=entry.data + DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=entry.data ) assert result["type"] == "form" assert result["errors"] == {} @@ -284,7 +284,7 @@ async def test_form_reauth_with_2fa(hass): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=entry.data + DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=entry.data ) assert result["type"] == "form" assert result["errors"] == {} diff --git a/tests/components/awair/test_config_flow.py b/tests/components/awair/test_config_flow.py index 92d92dd5a63..84b92229161 100644 --- a/tests/components/awair/test_config_flow.py +++ b/tests/components/awair/test_config_flow.py @@ -6,7 +6,7 @@ from python_awair.exceptions import AuthError, AwairError from homeassistant import data_entry_flow from homeassistant.components.awair.const import DOMAIN -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH, SOURCE_USER from homeassistant.const import CONF_ACCESS_TOKEN from .const import CONFIG, DEVICES_FIXTURE, NO_DEVICES_FIXTURE, UNIQUE_ID, USER_FIXTURE @@ -156,7 +156,7 @@ async def test_reauth(hass): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "unique_id": UNIQUE_ID}, + context={"source": SOURCE_REAUTH, "unique_id": UNIQUE_ID}, data=CONFIG, ) @@ -166,7 +166,7 @@ async def test_reauth(hass): with patch("python_awair.AwairClient.query", side_effect=AuthError()): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "unique_id": UNIQUE_ID}, + context={"source": SOURCE_REAUTH, "unique_id": UNIQUE_ID}, data=CONFIG, ) @@ -175,7 +175,7 @@ async def test_reauth(hass): with patch("python_awair.AwairClient.query", side_effect=AwairError()): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "unique_id": UNIQUE_ID}, + context={"source": SOURCE_REAUTH, "unique_id": UNIQUE_ID}, data=CONFIG, ) diff --git a/tests/components/azure_devops/test_config_flow.py b/tests/components/azure_devops/test_config_flow.py index 744d04042e0..7817f6fc570 100644 --- a/tests/components/azure_devops/test_config_flow.py +++ b/tests/components/azure_devops/test_config_flow.py @@ -62,7 +62,9 @@ async def test_reauth_authorization_error(hass: HomeAssistant) -> None: return_value=False, ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=FIXTURE_USER_INPUT + DOMAIN, + context={"source": config_entries.SOURCE_REAUTH}, + data=FIXTURE_USER_INPUT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -110,7 +112,9 @@ async def test_reauth_connection_error(hass: HomeAssistant) -> None: side_effect=aiohttp.ClientError, ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=FIXTURE_USER_INPUT + DOMAIN, + context={"source": config_entries.SOURCE_REAUTH}, + data=FIXTURE_USER_INPUT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -168,7 +172,9 @@ async def test_reauth_project_error(hass: HomeAssistant) -> None: return_value=None, ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=FIXTURE_USER_INPUT + DOMAIN, + context={"source": config_entries.SOURCE_REAUTH}, + data=FIXTURE_USER_INPUT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -197,7 +203,9 @@ async def test_reauth_flow(hass: HomeAssistant) -> None: mock_config.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=FIXTURE_USER_INPUT + DOMAIN, + context={"source": config_entries.SOURCE_REAUTH}, + data=FIXTURE_USER_INPUT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM diff --git a/tests/components/blink/test_config_flow.py b/tests/components/blink/test_config_flow.py index 2d1746b87ba..7da395a6f1f 100644 --- a/tests/components/blink/test_config_flow.py +++ b/tests/components/blink/test_config_flow.py @@ -246,7 +246,7 @@ async def test_form_unknown_error(hass): async def test_reauth_shows_user_step(hass): """Test reauth shows the user form.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"} + DOMAIN, context={"source": config_entries.SOURCE_REAUTH} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" diff --git a/tests/components/bmw_connected_drive/test_config_flow.py b/tests/components/bmw_connected_drive/test_config_flow.py index d56978deb27..ba3c69fe9c5 100644 --- a/tests/components/bmw_connected_drive/test_config_flow.py +++ b/tests/components/bmw_connected_drive/test_config_flow.py @@ -30,7 +30,7 @@ FIXTURE_CONFIG_ENTRY = { }, "options": {CONF_READ_ONLY: False, CONF_USE_LOCATION: False}, "system_options": {"disable_new_entities": False}, - "source": "user", + "source": config_entries.SOURCE_USER, "connection_class": config_entries.CONN_CLASS_CLOUD_POLL, "unique_id": f"{FIXTURE_USER_INPUT[CONF_REGION]}-{FIXTURE_USER_INPUT[CONF_REGION]}", } diff --git a/tests/components/broadlink/test_config_flow.py b/tests/components/broadlink/test_config_flow.py index 135362d62d9..68f1c54f697 100644 --- a/tests/components/broadlink/test_config_flow.py +++ b/tests/components/broadlink/test_config_flow.py @@ -733,7 +733,7 @@ async def test_flow_reauth_works(hass): with patch(DEVICE_FACTORY, return_value=mock_api): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=data + DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=data ) assert result["type"] == "form" @@ -769,7 +769,7 @@ async def test_flow_reauth_invalid_host(hass): with patch(DEVICE_FACTORY, return_value=mock_api): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=data + DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=data ) device.mac = get_device("Office").mac @@ -803,7 +803,7 @@ async def test_flow_reauth_valid_host(hass): with patch(DEVICE_FACTORY, return_value=mock_api): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=data + DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=data ) device.host = "192.168.1.128" @@ -834,7 +834,7 @@ async def test_dhcp_can_finish(hass): with patch(DEVICE_HELLO, return_value=mock_api): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "broadlink", IP_ADDRESS: "1.2.3.4", @@ -868,7 +868,7 @@ async def test_dhcp_fails_to_connect(hass): with patch(DEVICE_HELLO, side_effect=blke.NetworkTimeoutError()): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "broadlink", IP_ADDRESS: "1.2.3.4", @@ -887,7 +887,7 @@ async def test_dhcp_unreachable(hass): with patch(DEVICE_HELLO, side_effect=OSError(errno.ENETUNREACH, None)): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "broadlink", IP_ADDRESS: "1.2.3.4", @@ -906,7 +906,7 @@ async def test_dhcp_connect_unknown_error(hass): with patch(DEVICE_HELLO, side_effect=OSError()): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "broadlink", IP_ADDRESS: "1.2.3.4", @@ -928,7 +928,7 @@ async def test_dhcp_device_not_supported(hass): with patch(DEVICE_HELLO, return_value=mock_api): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "broadlink", IP_ADDRESS: device.host, @@ -952,7 +952,7 @@ async def test_dhcp_already_exists(hass): with patch(DEVICE_HELLO, return_value=mock_api): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "broadlink", IP_ADDRESS: "1.2.3.4", @@ -978,7 +978,7 @@ async def test_dhcp_updates_host(hass): with patch(DEVICE_HELLO, return_value=mock_api): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "broadlink", IP_ADDRESS: "4.5.6.7", diff --git a/tests/components/cast/test_config_flow.py b/tests/components/cast/test_config_flow.py index 1febd9d8803..cc67d585022 100644 --- a/tests/components/cast/test_config_flow.py +++ b/tests/components/cast/test_config_flow.py @@ -34,7 +34,14 @@ async def test_creating_entry_sets_up_media_player(hass): assert len(mock_setup.mock_calls) == 1 -@pytest.mark.parametrize("source", ["import", "user", "zeroconf"]) +@pytest.mark.parametrize( + "source", + [ + config_entries.SOURCE_IMPORT, + config_entries.SOURCE_USER, + config_entries.SOURCE_ZEROCONF, + ], +) async def test_single_instance(hass, source): """Test we only allow a single config flow.""" MockConfigEntry(domain="cast").add_to_hass(hass) @@ -50,7 +57,7 @@ async def test_single_instance(hass, source): async def test_user_setup(hass): """Test we can finish a config flow.""" result = await hass.config_entries.flow.async_init( - "cast", context={"source": "user"} + "cast", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -70,7 +77,7 @@ async def test_user_setup(hass): async def test_user_setup_options(hass): """Test we can finish a config flow.""" result = await hass.config_entries.flow.async_init( - "cast", context={"source": "user"} + "cast", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -92,7 +99,7 @@ async def test_user_setup_options(hass): async def test_zeroconf_setup(hass): """Test we can finish a config flow through zeroconf.""" result = await hass.config_entries.flow.async_init( - "cast", context={"source": "zeroconf"} + "cast", context={"source": config_entries.SOURCE_ZEROCONF} ) assert result["type"] == "form" @@ -169,7 +176,7 @@ async def test_option_flow(hass, parameter_data): orig_data = dict(config_entry.data) # Reconfigure ignore_cec, known_hosts, uuid - context = {"source": "user", "show_advanced_options": True} + context = {"source": config_entries.SOURCE_USER, "show_advanced_options": True} result = await hass.config_entries.options.async_init( config_entry.entry_id, context=context ) @@ -213,7 +220,7 @@ async def test_option_flow(hass, parameter_data): async def test_known_hosts(hass, castbrowser_mock, castbrowser_constructor_mock): """Test known hosts is passed to pychromecasts.""" result = await hass.config_entries.flow.async_init( - "cast", context={"source": "user"} + "cast", context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( result["flow_id"], {"known_hosts": "192.168.0.1, 192.168.0.2"} diff --git a/tests/components/cert_expiry/test_config_flow.py b/tests/components/cert_expiry/test_config_flow.py index ed51ebf70a4..a1cd1367e5f 100644 --- a/tests/components/cert_expiry/test_config_flow.py +++ b/tests/components/cert_expiry/test_config_flow.py @@ -3,7 +3,7 @@ import socket import ssl from unittest.mock import patch -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.cert_expiry.const import DEFAULT_PORT, DOMAIN from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT @@ -16,7 +16,7 @@ from tests.common import MockConfigEntry async def test_user(hass): """Test user config.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -40,7 +40,7 @@ async def test_user(hass): async def test_user_with_bad_cert(hass): """Test user config with bad certificate.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -72,7 +72,9 @@ async def test_import_host_only(hass): return_value=future_timestamp(1), ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data={CONF_HOST: HOST} + DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data={CONF_HOST: HOST}, ) await hass.async_block_till_done() @@ -93,7 +95,7 @@ async def test_import_host_and_port(hass): ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={CONF_HOST: HOST, CONF_PORT: PORT}, ) await hass.async_block_till_done() @@ -114,7 +116,9 @@ async def test_import_non_default_port(hass): return_value=future_timestamp(1), ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data={CONF_HOST: HOST, CONF_PORT: 888} + DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data={CONF_HOST: HOST, CONF_PORT: 888}, ) await hass.async_block_till_done() @@ -135,7 +139,7 @@ async def test_import_with_name(hass): ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={CONF_NAME: "legacy", CONF_HOST: HOST, CONF_PORT: PORT}, ) await hass.async_block_till_done() @@ -154,7 +158,9 @@ async def test_bad_import(hass): side_effect=ConnectionRefusedError(), ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data={CONF_HOST: HOST} + DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data={CONF_HOST: HOST}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT @@ -170,13 +176,17 @@ async def test_abort_if_already_setup(hass): ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data={CONF_HOST: HOST, CONF_PORT: PORT} + DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data={CONF_HOST: HOST, CONF_PORT: PORT}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data={CONF_HOST: HOST, CONF_PORT: PORT} + DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data={CONF_HOST: HOST, CONF_PORT: PORT}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" @@ -185,7 +195,7 @@ async def test_abort_if_already_setup(hass): async def test_abort_on_socket_failed(hass): """Test we abort of we have errors during socket creation.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) with patch( diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index abad057b64c..2f7815c99bf 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -330,7 +330,7 @@ async def test_create_account(hass, client): "disabled_by": None, "domain": "test", "entry_id": entries[0].entry_id, - "source": "user", + "source": core_ce.SOURCE_USER, "state": "loaded", "supports_options": False, "supports_unload": False, @@ -401,7 +401,7 @@ async def test_two_step_flow(hass, client): "disabled_by": None, "domain": "test", "entry_id": entries[0].entry_id, - "source": "user", + "source": core_ce.SOURCE_USER, "state": "loaded", "supports_options": False, "supports_unload": False, @@ -476,7 +476,7 @@ async def test_get_progress_index(hass, hass_ws_client): with patch.dict(HANDLERS, {"test": TestFlow}): form = await hass.config_entries.flow.async_init( - "test", context={"source": "hassio"} + "test", context={"source": core_ce.SOURCE_HASSIO} ) await ws_client.send_json({"id": 5, "type": "config_entries/flow/progress"}) @@ -488,7 +488,7 @@ async def test_get_progress_index(hass, hass_ws_client): "flow_id": form["flow_id"], "handler": "test", "step_id": "account", - "context": {"source": "hassio"}, + "context": {"source": core_ce.SOURCE_HASSIO}, } ] @@ -886,7 +886,7 @@ async def test_ignore_flow(hass, hass_ws_client): with patch.dict(HANDLERS, {"test": TestFlow}): result = await hass.config_entries.flow.async_init( - "test", context={"source": "user"} + "test", context={"source": core_ce.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM diff --git a/tests/components/deconz/test_gateway.py b/tests/components/deconz/test_gateway.py index afd4e55499d..1712faaf080 100644 --- a/tests/components/deconz/test_gateway.py +++ b/tests/components/deconz/test_gateway.py @@ -32,7 +32,7 @@ from homeassistant.components.ssdp import ( ATTR_UPNP_UDN, ) from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN -from homeassistant.config_entries import CONN_CLASS_LOCAL_PUSH, SOURCE_SSDP +from homeassistant.config_entries import CONN_CLASS_LOCAL_PUSH, SOURCE_SSDP, SOURCE_USER from homeassistant.const import ( CONF_API_KEY, CONF_HOST, @@ -109,7 +109,7 @@ async def setup_deconz_integration( get_state_response=DECONZ_WEB_REQUEST, entry_id="1", unique_id=BRIDGEID, - source="user", + source=SOURCE_USER, ): """Create the deCONZ gateway.""" config_entry = MockConfigEntry( diff --git a/tests/components/devolo_home_control/test_config_flow.py b/tests/components/devolo_home_control/test_config_flow.py index 7765e7335e4..94435545cc6 100644 --- a/tests/components/devolo_home_control/test_config_flow.py +++ b/tests/components/devolo_home_control/test_config_flow.py @@ -67,7 +67,8 @@ async def test_form_already_configured(hass): async def test_form_advanced_options(hass): """Test if we get the advanced options if user has enabled it.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user", "show_advanced_options": True} + DOMAIN, + context={"source": config_entries.SOURCE_USER, "show_advanced_options": True}, ) assert result["type"] == "form" assert result["errors"] == {} diff --git a/tests/components/dhcp/test_init.py b/tests/components/dhcp/test_init.py index 25fbbea459a..122e81786c2 100644 --- a/tests/components/dhcp/test_init.py +++ b/tests/components/dhcp/test_init.py @@ -7,6 +7,7 @@ from scapy.error import Scapy_Exception from scapy.layers.dhcp import DHCP from scapy.layers.l2 import Ether +from homeassistant import config_entries from homeassistant.components import dhcp from homeassistant.components.device_tracker.const import ( ATTR_HOST_NAME, @@ -98,7 +99,9 @@ async def test_dhcp_match_hostname_and_macaddress(hass): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[0][2]["data"] == { dhcp.IP_ADDRESS: "192.168.210.56", dhcp.HOSTNAME: "connect", @@ -123,7 +126,9 @@ async def test_dhcp_renewal_match_hostname_and_macaddress(hass): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[0][2]["data"] == { dhcp.IP_ADDRESS: "192.168.1.120", dhcp.HOSTNAME: "irobot-ae9ec12dd3b04885bcbfa36afb01e1cc", @@ -144,7 +149,9 @@ async def test_dhcp_match_hostname(hass): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[0][2]["data"] == { dhcp.IP_ADDRESS: "192.168.210.56", dhcp.HOSTNAME: "connect", @@ -165,7 +172,9 @@ async def test_dhcp_match_macaddress(hass): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[0][2]["data"] == { dhcp.IP_ADDRESS: "192.168.210.56", dhcp.HOSTNAME: "connect", @@ -435,7 +444,9 @@ async def test_device_tracker_hostname_and_macaddress_exists_before_start(hass): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[0][2]["data"] == { dhcp.IP_ADDRESS: "192.168.210.56", dhcp.HOSTNAME: "connect", @@ -470,7 +481,9 @@ async def test_device_tracker_hostname_and_macaddress_after_start(hass): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[0][2]["data"] == { dhcp.IP_ADDRESS: "192.168.210.56", dhcp.HOSTNAME: "connect", @@ -614,7 +627,9 @@ async def test_aiodiscover_finds_new_hosts(hass): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[0][2]["data"] == { dhcp.IP_ADDRESS: "192.168.210.56", dhcp.HOSTNAME: "connect", @@ -667,14 +682,18 @@ async def test_aiodiscover_does_not_call_again_on_shorter_hostname(hass): assert len(mock_init.mock_calls) == 2 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[0][2]["data"] == { dhcp.IP_ADDRESS: "192.168.210.56", dhcp.HOSTNAME: "irobot-abc", dhcp.MAC_ADDRESS: "b8b7f16db533", } assert mock_init.mock_calls[1][1][0] == "mock-domain" - assert mock_init.mock_calls[1][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[1][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[1][2]["data"] == { dhcp.IP_ADDRESS: "192.168.210.56", dhcp.HOSTNAME: "irobot-abcdef", @@ -715,7 +734,9 @@ async def test_aiodiscover_finds_new_hosts_after_interval(hass): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "dhcp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_DHCP + } assert mock_init.mock_calls[0][2]["data"] == { dhcp.IP_ADDRESS: "192.168.210.56", dhcp.HOSTNAME: "connect", diff --git a/tests/components/dialogflow/test_init.py b/tests/components/dialogflow/test_init.py index 2213e52bef7..c2d0316245a 100644 --- a/tests/components/dialogflow/test_init.py +++ b/tests/components/dialogflow/test_init.py @@ -4,7 +4,7 @@ import json import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import dialogflow, intent_script from homeassistant.config import async_process_ha_core_config from homeassistant.core import callback @@ -84,7 +84,7 @@ async def fixture(hass, aiohttp_client): ) result = await hass.config_entries.flow.async_init( - "dialogflow", context={"source": "user"} + "dialogflow", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result diff --git a/tests/components/eafm/test_config_flow.py b/tests/components/eafm/test_config_flow.py index 8a1e2bd89fc..403ea4f028a 100644 --- a/tests/components/eafm/test_config_flow.py +++ b/tests/components/eafm/test_config_flow.py @@ -4,6 +4,7 @@ from unittest.mock import patch import pytest from voluptuous.error import MultipleInvalid +from homeassistant import config_entries from homeassistant.components.eafm import const @@ -11,7 +12,7 @@ async def test_flow_no_discovered_stations(hass, mock_get_stations): """Test config flow discovers no station.""" mock_get_stations.return_value = [] result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "abort" assert result["reason"] == "no_stations" @@ -24,7 +25,7 @@ async def test_flow_invalid_station(hass, mock_get_stations): ] result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -44,7 +45,7 @@ async def test_flow_works(hass, mock_get_stations, mock_get_station): ] result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" diff --git a/tests/components/emonitor/test_config_flow.py b/tests/components/emonitor/test_config_flow.py index 1d71275409a..ab2f62578b4 100644 --- a/tests/components/emonitor/test_config_flow.py +++ b/tests/components/emonitor/test_config_flow.py @@ -102,7 +102,7 @@ async def test_dhcp_can_confirm(hass): ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "emonitor", IP_ADDRESS: "1.2.3.4", @@ -146,7 +146,7 @@ async def test_dhcp_fails_to_connect(hass): ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "emonitor", IP_ADDRESS: "1.2.3.4", @@ -175,7 +175,7 @@ async def test_dhcp_already_exists(hass): ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "emonitor", IP_ADDRESS: "1.2.3.4", diff --git a/tests/components/enocean/test_config_flow.py b/tests/components/enocean/test_config_flow.py index 60a20af5eae..d12b9a580c7 100644 --- a/tests/components/enocean/test_config_flow.py +++ b/tests/components/enocean/test_config_flow.py @@ -1,7 +1,7 @@ """Tests for EnOcean config flow.""" from unittest.mock import Mock, patch -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.enocean.config_flow import EnOceanFlowHandler from homeassistant.components.enocean.const import DOMAIN from homeassistant.const import CONF_DEVICE @@ -21,7 +21,7 @@ async def test_user_flow_cannot_create_multiple_instances(hass): with patch(DONGLE_VALIDATE_PATH_METHOD, Mock(return_value=True)): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT @@ -34,7 +34,7 @@ async def test_user_flow_with_detected_dongle(hass): with patch(DONGLE_DETECT_METHOD, Mock(return_value=[FAKE_DONGLE_PATH])): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -48,7 +48,7 @@ async def test_user_flow_with_no_detected_dongle(hass): """Test the user flow with a detected ENOcean dongle.""" with patch(DONGLE_DETECT_METHOD, Mock(return_value=[])): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -141,7 +141,9 @@ async def test_import_flow_with_valid_path(hass): with patch(DONGLE_VALIDATE_PATH_METHOD, Mock(return_value=True)): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=DATA_TO_IMPORT + DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data=DATA_TO_IMPORT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY @@ -157,7 +159,9 @@ async def test_import_flow_with_invalid_path(hass): Mock(return_value=False), ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=DATA_TO_IMPORT + DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data=DATA_TO_IMPORT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT diff --git a/tests/components/enphase_envoy/test_config_flow.py b/tests/components/enphase_envoy/test_config_flow.py index 0f48067ec6d..45aeecf912a 100644 --- a/tests/components/enphase_envoy/test_config_flow.py +++ b/tests/components/enphase_envoy/test_config_flow.py @@ -130,7 +130,7 @@ async def test_import(hass: HomeAssistant) -> None: ) as mock_setup_entry: result2 = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={ "ip_address": "1.1.1.1", "name": "Pool Envoy", @@ -156,7 +156,7 @@ async def test_zeroconf(hass: HomeAssistant) -> None: await setup.async_setup_component(hass, "persistent_notification", {}) result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "zeroconf"}, + context={"source": config_entries.SOURCE_ZEROCONF}, data={ "properties": {"serialnum": "1234"}, "host": "1.1.1.1", @@ -253,7 +253,7 @@ async def test_zeroconf_serial_already_exists(hass: HomeAssistant) -> None: result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "zeroconf"}, + context={"source": config_entries.SOURCE_ZEROCONF}, data={ "properties": {"serialnum": "1234"}, "host": "1.1.1.1", @@ -288,7 +288,7 @@ async def test_zeroconf_host_already_exists(hass: HomeAssistant) -> None: ) as mock_setup_entry: result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "zeroconf"}, + context={"source": config_entries.SOURCE_ZEROCONF}, data={ "properties": {"serialnum": "1234"}, "host": "1.1.1.1", diff --git a/tests/components/esphome/test_config_flow.py b/tests/components/esphome/test_config_flow.py index 233255c1a89..d5968e7f731 100644 --- a/tests/components/esphome/test_config_flow.py +++ b/tests/components/esphome/test_config_flow.py @@ -4,6 +4,7 @@ from unittest.mock import AsyncMock, MagicMock, patch import pytest +from homeassistant import config_entries from homeassistant.components.esphome import DOMAIN from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT from homeassistant.data_entry_flow import ( @@ -51,7 +52,7 @@ async def test_user_connection_works(hass, mock_client): """Test we can finish a config flow.""" result = await hass.config_entries.flow.async_init( "esphome", - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data=None, ) @@ -62,7 +63,7 @@ async def test_user_connection_works(hass, mock_client): result = await hass.config_entries.flow.async_init( "esphome", - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data={CONF_HOST: "127.0.0.1", CONF_PORT: 80}, ) @@ -95,7 +96,7 @@ async def test_user_resolve_error(hass, mock_api_connection_error, mock_client): mock_client.device_info.side_effect = exc result = await hass.config_entries.flow.async_init( "esphome", - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053}, ) @@ -114,7 +115,7 @@ async def test_user_connection_error(hass, mock_api_connection_error, mock_clien result = await hass.config_entries.flow.async_init( "esphome", - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053}, ) @@ -133,7 +134,7 @@ async def test_user_with_password(hass, mock_client): result = await hass.config_entries.flow.async_init( "esphome", - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053}, ) @@ -159,7 +160,7 @@ async def test_user_invalid_password(hass, mock_api_connection_error, mock_clien result = await hass.config_entries.flow.async_init( "esphome", - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053}, ) @@ -188,7 +189,7 @@ async def test_discovery_initiation(hass, mock_client): "properties": {}, } flow = await hass.config_entries.flow.async_init( - "esphome", context={"source": "zeroconf"}, data=service_info + "esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info ) result = await hass.config_entries.flow.async_configure( @@ -220,7 +221,7 @@ async def test_discovery_already_configured_hostname(hass, mock_client): "properties": {}, } result = await hass.config_entries.flow.async_init( - "esphome", context={"source": "zeroconf"}, data=service_info + "esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info ) assert result["type"] == RESULT_TYPE_ABORT @@ -245,7 +246,7 @@ async def test_discovery_already_configured_ip(hass, mock_client): "properties": {"address": "192.168.43.183"}, } result = await hass.config_entries.flow.async_init( - "esphome", context={"source": "zeroconf"}, data=service_info + "esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info ) assert result["type"] == RESULT_TYPE_ABORT @@ -273,7 +274,7 @@ async def test_discovery_already_configured_name(hass, mock_client): "properties": {"address": "test8266.local"}, } result = await hass.config_entries.flow.async_init( - "esphome", context={"source": "zeroconf"}, data=service_info + "esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info ) assert result["type"] == RESULT_TYPE_ABORT @@ -295,13 +296,13 @@ async def test_discovery_duplicate_data(hass, mock_client): mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test8266")) result = await hass.config_entries.flow.async_init( - "esphome", data=service_info, context={"source": "zeroconf"} + "esphome", data=service_info, context={"source": config_entries.SOURCE_ZEROCONF} ) assert result["type"] == RESULT_TYPE_FORM assert result["step_id"] == "discovery_confirm" result = await hass.config_entries.flow.async_init( - "esphome", data=service_info, context={"source": "zeroconf"} + "esphome", data=service_info, context={"source": config_entries.SOURCE_ZEROCONF} ) assert result["type"] == RESULT_TYPE_ABORT assert result["reason"] == "already_in_progress" @@ -323,7 +324,7 @@ async def test_discovery_updates_unique_id(hass, mock_client): "properties": {"address": "test8266.local"}, } result = await hass.config_entries.flow.async_init( - "esphome", context={"source": "zeroconf"}, data=service_info + "esphome", context={"source": config_entries.SOURCE_ZEROCONF}, data=service_info ) assert result["type"] == RESULT_TYPE_ABORT diff --git a/tests/components/fireservicerota/test_config_flow.py b/tests/components/fireservicerota/test_config_flow.py index 6f4fd21a534..0553574ae77 100644 --- a/tests/components/fireservicerota/test_config_flow.py +++ b/tests/components/fireservicerota/test_config_flow.py @@ -3,7 +3,7 @@ from unittest.mock import patch from pyfireservicerota import InvalidAuthError -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.fireservicerota.const import DOMAIN from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME @@ -40,7 +40,7 @@ MOCK_TOKEN_INFO = { async def test_show_form(hass): """Test that the form is served with no input.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -53,7 +53,7 @@ async def test_abort_if_already_setup(hass): ) entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_CONF + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" @@ -67,7 +67,7 @@ async def test_invalid_credentials(hass): side_effect=InvalidAuthError, ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_CONF + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF ) assert result["errors"] == {"base": "invalid_auth"} @@ -86,7 +86,7 @@ async def test_step_user(hass): mock_fireservicerota.request_tokens.return_value = MOCK_TOKEN_INFO result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_CONF + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF ) await hass.async_block_till_done() @@ -123,7 +123,10 @@ async def test_reauth(hass): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "unique_id": entry.unique_id}, + context={ + "source": config_entries.SOURCE_REAUTH, + "unique_id": entry.unique_id, + }, data=MOCK_CONF, ) diff --git a/tests/components/fritzbox/test_config_flow.py b/tests/components/fritzbox/test_config_flow.py index 2ffa14003f0..64e8c691638 100644 --- a/tests/components/fritzbox/test_config_flow.py +++ b/tests/components/fritzbox/test_config_flow.py @@ -12,7 +12,12 @@ from homeassistant.components.ssdp import ( ATTR_UPNP_FRIENDLY_NAME, ATTR_UPNP_UDN, ) -from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_SSDP, SOURCE_USER +from homeassistant.config_entries import ( + SOURCE_IMPORT, + SOURCE_REAUTH, + SOURCE_SSDP, + SOURCE_USER, +) from homeassistant.const import CONF_DEVICES, CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import ( @@ -182,7 +187,7 @@ async def test_reauth_not_successful(hass: HomeAssistant, fritz: Mock): async def test_import(hass: HomeAssistant, fritz: Mock): """Test starting a flow by import.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=MOCK_USER_DATA + DOMAIN, context={"source": SOURCE_IMPORT}, data=MOCK_USER_DATA ) assert result["type"] == RESULT_TYPE_CREATE_ENTRY assert result["title"] == "fake_host" diff --git a/tests/components/garmin_connect/test_config_flow.py b/tests/components/garmin_connect/test_config_flow.py index eed9d8dceae..f3784d5e2e2 100644 --- a/tests/components/garmin_connect/test_config_flow.py +++ b/tests/components/garmin_connect/test_config_flow.py @@ -8,7 +8,7 @@ from garminconnect import ( ) import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.garmin_connect.const import DOMAIN from homeassistant.const import CONF_ID, CONF_PASSWORD, CONF_USERNAME @@ -34,7 +34,7 @@ def mock_garmin(): async def test_show_form(hass): """Test that the form is served with no input.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -47,7 +47,7 @@ async def test_step_user(hass, mock_garmin_connect): "homeassistant.components.garmin_connect.async_setup_entry", return_value=True ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_CONF + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["data"] == MOCK_CONF @@ -57,7 +57,7 @@ async def test_connection_error(hass, mock_garmin_connect): """Test for connection error.""" mock_garmin_connect.login.side_effect = GarminConnectConnectionError("errormsg") result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_CONF + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"] == {"base": "cannot_connect"} @@ -67,7 +67,7 @@ async def test_authentication_error(hass, mock_garmin_connect): """Test for authentication error.""" mock_garmin_connect.login.side_effect = GarminConnectAuthenticationError("errormsg") result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_CONF + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"] == {"base": "invalid_auth"} @@ -79,7 +79,7 @@ async def test_toomanyrequest_error(hass, mock_garmin_connect): "errormsg" ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_CONF + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"] == {"base": "too_many_requests"} @@ -89,7 +89,7 @@ async def test_unknown_error(hass, mock_garmin_connect): """Test for unknown error.""" mock_garmin_connect.login.side_effect = Exception result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_CONF + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"] == {"base": "unknown"} @@ -100,7 +100,7 @@ async def test_abort_if_already_setup(hass, mock_garmin_connect): entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONF, unique_id=MOCK_CONF[CONF_ID]) entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_CONF + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_CONF ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" diff --git a/tests/components/gdacs/test_config_flow.py b/tests/components/gdacs/test_config_flow.py index e2ecd3902d5..8496f0ca5a2 100644 --- a/tests/components/gdacs/test_config_flow.py +++ b/tests/components/gdacs/test_config_flow.py @@ -4,7 +4,7 @@ from unittest.mock import patch import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.gdacs import CONF_CATEGORIES, DOMAIN from homeassistant.const import ( CONF_LATITUDE, @@ -27,7 +27,7 @@ async def test_duplicate_error(hass, config_entry): config_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=conf + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=conf ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" @@ -36,7 +36,7 @@ async def test_duplicate_error(hass, config_entry): async def test_show_form(hass): """Test that the form is served with no input.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -53,7 +53,7 @@ async def test_step_import(hass): } result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=conf + DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=conf ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "-41.2, 174.7" @@ -73,7 +73,7 @@ async def test_step_user(hass): conf = {CONF_RADIUS: 25} result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=conf + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=conf ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "-41.2, 174.7" diff --git a/tests/components/geofency/test_init.py b/tests/components/geofency/test_init.py index b84b6b681ae..169cfebae17 100644 --- a/tests/components/geofency/test_init.py +++ b/tests/components/geofency/test_init.py @@ -4,7 +4,7 @@ from unittest.mock import patch import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import zone from homeassistant.components.geofency import CONF_MOBILE_BEACONS, DOMAIN from homeassistant.config import async_process_ha_core_config @@ -157,7 +157,7 @@ async def webhook_id(hass, geofency_client): {"internal_url": "http://example.local:8123"}, ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result diff --git a/tests/components/geonetnz_quakes/test_config_flow.py b/tests/components/geonetnz_quakes/test_config_flow.py index d362e9cdf0f..9b471051656 100644 --- a/tests/components/geonetnz_quakes/test_config_flow.py +++ b/tests/components/geonetnz_quakes/test_config_flow.py @@ -2,7 +2,7 @@ from datetime import timedelta from unittest.mock import patch -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.geonetnz_quakes import ( CONF_MINIMUM_MAGNITUDE, CONF_MMI, @@ -23,7 +23,7 @@ async def test_duplicate_error(hass, config_entry): config_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=conf + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=conf ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "already_configured" @@ -32,7 +32,7 @@ async def test_duplicate_error(hass, config_entry): async def test_show_form(hass): """Test that the form is served with no input.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -54,7 +54,7 @@ async def test_step_import(hass): "homeassistant.components.geonetnz_quakes.async_setup_entry", return_value=True ), patch("homeassistant.components.geonetnz_quakes.async_setup", return_value=True): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=conf + DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=conf ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "-41.2, 174.7" @@ -79,7 +79,7 @@ async def test_step_user(hass): "homeassistant.components.geonetnz_quakes.async_setup_entry", return_value=True ), patch("homeassistant.components.geonetnz_quakes.async_setup", return_value=True): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=conf + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=conf ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["title"] == "-41.2, 174.7" diff --git a/tests/components/glances/test_config_flow.py b/tests/components/glances/test_config_flow.py index 8734ca0e60d..c9a2c333b8b 100644 --- a/tests/components/glances/test_config_flow.py +++ b/tests/components/glances/test_config_flow.py @@ -3,7 +3,7 @@ from unittest.mock import patch from glances_api import Glances -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import glances from homeassistant.const import CONF_SCAN_INTERVAL @@ -33,7 +33,7 @@ async def test_form(hass): """Test config entry configured successfully.""" result = await hass.config_entries.flow.async_init( - glances.DOMAIN, context={"source": "user"} + glances.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -56,7 +56,7 @@ async def test_form_cannot_connect(hass): with patch("glances_api.Glances"): result = await hass.config_entries.flow.async_init( - glances.DOMAIN, context={"source": "user"} + glances.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=DEMO_USER_INPUT @@ -72,7 +72,7 @@ async def test_form_wrong_version(hass): user_input = DEMO_USER_INPUT.copy() user_input.update(version=1) result = await hass.config_entries.flow.async_init( - glances.DOMAIN, context={"source": "user"} + glances.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=user_input @@ -90,7 +90,7 @@ async def test_form_already_configured(hass): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - glances.DOMAIN, context={"source": "user"} + glances.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=DEMO_USER_INPUT diff --git a/tests/components/gpslogger/test_init.py b/tests/components/gpslogger/test_init.py index 1dad262a285..61e5862d3b1 100644 --- a/tests/components/gpslogger/test_init.py +++ b/tests/components/gpslogger/test_init.py @@ -3,7 +3,7 @@ from unittest.mock import patch import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import gpslogger, zone from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN from homeassistant.components.gpslogger import DOMAIN, TRACKER_UPDATE @@ -69,7 +69,7 @@ async def webhook_id(hass, gpslogger_client): {"internal_url": "http://example.local:8123"}, ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result diff --git a/tests/components/heos/test_config_flow.py b/tests/components/heos/test_config_flow.py index e62578e5108..76ff06e2a96 100644 --- a/tests/components/heos/test_config_flow.py +++ b/tests/components/heos/test_config_flow.py @@ -8,7 +8,7 @@ from homeassistant import data_entry_flow from homeassistant.components import heos, ssdp from homeassistant.components.heos.config_flow import HeosFlowHandler from homeassistant.components.heos.const import DATA_DISCOVERED_HOSTS, DOMAIN -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_SSDP +from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_SSDP, SOURCE_USER from homeassistant.const import CONF_HOST @@ -36,7 +36,7 @@ async def test_cannot_connect_shows_error_form(hass, controller): """Test form is shown with error when cannot connect.""" controller.connect.side_effect = HeosError() result = await hass.config_entries.flow.async_init( - heos.DOMAIN, context={"source": "user"}, data={CONF_HOST: "127.0.0.1"} + heos.DOMAIN, context={"source": SOURCE_USER}, data={CONF_HOST: "127.0.0.1"} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -52,7 +52,7 @@ async def test_create_entry_when_host_valid(hass, controller): data = {CONF_HOST: "127.0.0.1"} with patch("homeassistant.components.heos.async_setup_entry", return_value=True): result = await hass.config_entries.flow.async_init( - heos.DOMAIN, context={"source": "user"}, data=data + heos.DOMAIN, context={"source": SOURCE_USER}, data=data ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["result"].unique_id == DOMAIN @@ -68,7 +68,7 @@ async def test_create_entry_when_friendly_name_valid(hass, controller): data = {CONF_HOST: "Office (127.0.0.1)"} with patch("homeassistant.components.heos.async_setup_entry", return_value=True): result = await hass.config_entries.flow.async_init( - heos.DOMAIN, context={"source": "user"}, data=data + heos.DOMAIN, context={"source": SOURCE_USER}, data=data ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["result"].unique_id == DOMAIN @@ -83,7 +83,7 @@ async def test_discovery_shows_create_form(hass, controller, discovery_data): """Test discovery shows form to confirm setup and subsequent abort.""" await hass.config_entries.flow.async_init( - heos.DOMAIN, context={"source": "ssdp"}, data=discovery_data + heos.DOMAIN, context={"source": SOURCE_SSDP}, data=discovery_data ) await hass.async_block_till_done() flows_in_progress = hass.config_entries.flow.async_progress() @@ -96,7 +96,7 @@ async def test_discovery_shows_create_form(hass, controller, discovery_data): discovery_data[ssdp.ATTR_UPNP_FRIENDLY_NAME] = "Bedroom" await hass.config_entries.flow.async_init( - heos.DOMAIN, context={"source": "ssdp"}, data=discovery_data + heos.DOMAIN, context={"source": SOURCE_SSDP}, data=discovery_data ) await hass.async_block_till_done() flows_in_progress = hass.config_entries.flow.async_progress() diff --git a/tests/components/homekit_controller/test_config_flow.py b/tests/components/homekit_controller/test_config_flow.py index 42903a53062..12381614a83 100644 --- a/tests/components/homekit_controller/test_config_flow.py +++ b/tests/components/homekit_controller/test_config_flow.py @@ -9,6 +9,7 @@ from aiohomekit.model.characteristics import CharacteristicsTypes from aiohomekit.model.services import ServicesTypes import pytest +from homeassistant import config_entries from homeassistant.components.homekit_controller import config_flow from homeassistant.helpers import device_registry @@ -177,13 +178,15 @@ async def test_discovery_works(hass, controller, upper_case_props, missing_cshar # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert result["type"] == "form" assert result["step_id"] == "pair" assert get_flow_context(hass, result) == { "hkid": "00:00:00:00:00:00", - "source": "zeroconf", + "source": config_entries.SOURCE_ZEROCONF, "title_placeholders": {"name": "TestDevice"}, "unique_id": "00:00:00:00:00:00", } @@ -209,13 +212,17 @@ async def test_abort_duplicate_flow(hass, controller): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert result["type"] == "form" assert result["step_id"] == "pair" result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert result["type"] == "abort" assert result["reason"] == "already_in_progress" @@ -231,7 +238,9 @@ async def test_pair_already_paired_1(hass, controller): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert result["type"] == "abort" assert result["reason"] == "already_paired" @@ -247,7 +256,9 @@ async def test_id_missing(hass, controller): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert result["type"] == "abort" assert result["reason"] == "invalid_properties" @@ -262,7 +273,9 @@ async def test_discovery_ignored_model(hass, controller): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert result["type"] == "abort" assert result["reason"] == "ignored_model" @@ -287,7 +300,9 @@ async def test_discovery_ignored_hk_bridge(hass, controller): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert result["type"] == "abort" assert result["reason"] == "ignored_model" @@ -312,7 +327,9 @@ async def test_discovery_does_not_ignore_non_homekit(hass, controller): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert result["type"] == "form" @@ -333,7 +350,9 @@ async def test_discovery_invalid_config_entry(hass, controller): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) # Discovery of a HKID that is in a pairable state but for which there is @@ -362,7 +381,9 @@ async def test_discovery_already_configured(hass, controller): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert result["type"] == "abort" assert result["reason"] == "already_configured" @@ -377,7 +398,9 @@ async def test_pair_abort_errors_on_start(hass, controller, exception, expected) # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) # User initiates pairing - device refuses to enter pairing mode @@ -397,7 +420,9 @@ async def test_pair_try_later_errors_on_start(hass, controller, exception, expec # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) # User initiates pairing - device refuses to enter pairing mode but may be successful after entering pairing mode or rebooting @@ -432,14 +457,16 @@ async def test_pair_form_errors_on_start(hass, controller, exception, expected): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert get_flow_context(hass, result) == { "hkid": "00:00:00:00:00:00", "title_placeholders": {"name": "TestDevice"}, "unique_id": "00:00:00:00:00:00", - "source": "zeroconf", + "source": config_entries.SOURCE_ZEROCONF, } # User initiates pairing - device refuses to enter pairing mode @@ -455,7 +482,7 @@ async def test_pair_form_errors_on_start(hass, controller, exception, expected): "hkid": "00:00:00:00:00:00", "title_placeholders": {"name": "TestDevice"}, "unique_id": "00:00:00:00:00:00", - "source": "zeroconf", + "source": config_entries.SOURCE_ZEROCONF, } # User gets back the form @@ -480,14 +507,16 @@ async def test_pair_abort_errors_on_finish(hass, controller, exception, expected # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert get_flow_context(hass, result) == { "hkid": "00:00:00:00:00:00", "title_placeholders": {"name": "TestDevice"}, "unique_id": "00:00:00:00:00:00", - "source": "zeroconf", + "source": config_entries.SOURCE_ZEROCONF, } # User initiates pairing - this triggers the device to show a pairing code @@ -501,7 +530,7 @@ async def test_pair_abort_errors_on_finish(hass, controller, exception, expected "hkid": "00:00:00:00:00:00", "title_placeholders": {"name": "TestDevice"}, "unique_id": "00:00:00:00:00:00", - "source": "zeroconf", + "source": config_entries.SOURCE_ZEROCONF, } # User enters pairing code @@ -520,14 +549,16 @@ async def test_pair_form_errors_on_finish(hass, controller, exception, expected) # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "zeroconf"}, data=discovery_info + "homekit_controller", + context={"source": config_entries.SOURCE_ZEROCONF}, + data=discovery_info, ) assert get_flow_context(hass, result) == { "hkid": "00:00:00:00:00:00", "title_placeholders": {"name": "TestDevice"}, "unique_id": "00:00:00:00:00:00", - "source": "zeroconf", + "source": config_entries.SOURCE_ZEROCONF, } # User initiates pairing - this triggers the device to show a pairing code @@ -541,7 +572,7 @@ async def test_pair_form_errors_on_finish(hass, controller, exception, expected) "hkid": "00:00:00:00:00:00", "title_placeholders": {"name": "TestDevice"}, "unique_id": "00:00:00:00:00:00", - "source": "zeroconf", + "source": config_entries.SOURCE_ZEROCONF, } # User enters pairing code @@ -555,7 +586,7 @@ async def test_pair_form_errors_on_finish(hass, controller, exception, expected) "hkid": "00:00:00:00:00:00", "title_placeholders": {"name": "TestDevice"}, "unique_id": "00:00:00:00:00:00", - "source": "zeroconf", + "source": config_entries.SOURCE_ZEROCONF, } @@ -565,13 +596,13 @@ async def test_user_works(hass, controller): # Device is discovered result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "user"} + "homekit_controller", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" assert get_flow_context(hass, result) == { - "source": "user", + "source": config_entries.SOURCE_USER, } result = await hass.config_entries.flow.async_configure( @@ -581,7 +612,7 @@ async def test_user_works(hass, controller): assert result["step_id"] == "pair" assert get_flow_context(hass, result) == { - "source": "user", + "source": config_entries.SOURCE_USER, "unique_id": "00:00:00:00:00:00", "title_placeholders": {"name": "TestDevice"}, } @@ -596,7 +627,7 @@ async def test_user_works(hass, controller): async def test_user_no_devices(hass, controller): """Test user initiated pairing where no devices discovered.""" result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "user"} + "homekit_controller", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "abort" assert result["reason"] == "no_devices" @@ -612,7 +643,7 @@ async def test_user_no_unpaired_devices(hass, controller): # Device discovery is requested result = await hass.config_entries.flow.async_init( - "homekit_controller", context={"source": "user"} + "homekit_controller", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "abort" @@ -626,7 +657,7 @@ async def test_unignore_works(hass, controller): # Device is unignored result = await hass.config_entries.flow.async_init( "homekit_controller", - context={"source": "unignore"}, + context={"source": config_entries.SOURCE_UNIGNORE}, data={"unique_id": device.device_id}, ) assert result["type"] == "form" @@ -635,7 +666,7 @@ async def test_unignore_works(hass, controller): "hkid": "00:00:00:00:00:00", "title_placeholders": {"name": "TestDevice"}, "unique_id": "00:00:00:00:00:00", - "source": "unignore", + "source": config_entries.SOURCE_UNIGNORE, } # User initiates pairing by clicking on 'configure' - device enters pairing mode and displays code @@ -658,7 +689,7 @@ async def test_unignore_ignores_missing_devices(hass, controller): # Device is unignored result = await hass.config_entries.flow.async_init( "homekit_controller", - context={"source": "unignore"}, + context={"source": config_entries.SOURCE_UNIGNORE}, data={"unique_id": "00:00:00:00:00:01"}, ) diff --git a/tests/components/homematicip_cloud/test_config_flow.py b/tests/components/homematicip_cloud/test_config_flow.py index 0b573e66b1d..002a5540fe5 100644 --- a/tests/components/homematicip_cloud/test_config_flow.py +++ b/tests/components/homematicip_cloud/test_config_flow.py @@ -1,6 +1,7 @@ """Tests for HomematicIP Cloud config flow.""" from unittest.mock import patch +from homeassistant import config_entries from homeassistant.components.homematicip_cloud.const import ( DOMAIN as HMIPC_DOMAIN, HMIPC_AUTHTOKEN, @@ -27,7 +28,9 @@ async def test_flow_works(hass, simple_mock_home): return_value=True, ): result = await hass.config_entries.flow.async_init( - HMIPC_DOMAIN, context={"source": "user"}, data=DEFAULT_CONFIG + HMIPC_DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=DEFAULT_CONFIG, ) assert result["type"] == "form" @@ -70,7 +73,9 @@ async def test_flow_init_connection_error(hass): return_value=False, ): result = await hass.config_entries.flow.async_init( - HMIPC_DOMAIN, context={"source": "user"}, data=DEFAULT_CONFIG + HMIPC_DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=DEFAULT_CONFIG, ) assert result["type"] == "form" @@ -90,7 +95,9 @@ async def test_flow_link_connection_error(hass): return_value=False, ): result = await hass.config_entries.flow.async_init( - HMIPC_DOMAIN, context={"source": "user"}, data=DEFAULT_CONFIG + HMIPC_DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=DEFAULT_CONFIG, ) assert result["type"] == "abort" @@ -107,7 +114,9 @@ async def test_flow_link_press_button(hass): return_value=True, ): result = await hass.config_entries.flow.async_init( - HMIPC_DOMAIN, context={"source": "user"}, data=DEFAULT_CONFIG + HMIPC_DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=DEFAULT_CONFIG, ) assert result["type"] == "form" @@ -119,7 +128,7 @@ async def test_init_flow_show_form(hass): """Test config flow shows up with a form.""" result = await hass.config_entries.flow.async_init( - HMIPC_DOMAIN, context={"source": "user"} + HMIPC_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "init" @@ -133,7 +142,9 @@ async def test_init_already_configured(hass): return_value=True, ): result = await hass.config_entries.flow.async_init( - HMIPC_DOMAIN, context={"source": "user"}, data=DEFAULT_CONFIG + HMIPC_DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=DEFAULT_CONFIG, ) assert result["type"] == "abort" @@ -155,7 +166,9 @@ async def test_import_config(hass, simple_mock_home): "homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect", ): result = await hass.config_entries.flow.async_init( - HMIPC_DOMAIN, context={"source": "import"}, data=IMPORT_CONFIG + HMIPC_DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data=IMPORT_CONFIG, ) assert result["type"] == "create_entry" @@ -178,7 +191,9 @@ async def test_import_existing_config(hass): return_value=True, ): result = await hass.config_entries.flow.async_init( - HMIPC_DOMAIN, context={"source": "import"}, data=IMPORT_CONFIG + HMIPC_DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data=IMPORT_CONFIG, ) assert result["type"] == "abort" diff --git a/tests/components/hue/test_config_flow.py b/tests/components/hue/test_config_flow.py index 12a360cdf94..3deec0988fa 100644 --- a/tests/components/hue/test_config_flow.py +++ b/tests/components/hue/test_config_flow.py @@ -54,7 +54,7 @@ async def test_flow_works(hass): return_value=[mock_bridge], ): result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -101,7 +101,7 @@ async def test_manual_flow_works(hass, aioclient_mock): return_value=[mock_bridge], ): result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -157,7 +157,7 @@ async def test_manual_flow_bridge_exist(hass, aioclient_mock): return_value=[], ): result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -184,7 +184,7 @@ async def test_manual_flow_no_discovered_bridges(hass, aioclient_mock): aioclient_mock.get(URL_NUPNP, json=[]) result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "manual" @@ -198,7 +198,7 @@ async def test_flow_all_discovered_bridges_exist(hass, aioclient_mock): ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -221,7 +221,7 @@ async def test_flow_bridges_discovered(hass, aioclient_mock): ) result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "init" @@ -248,7 +248,7 @@ async def test_flow_two_bridges_discovered_one_new(hass, aioclient_mock): ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -266,7 +266,7 @@ async def test_flow_timeout_discovery(hass): side_effect=asyncio.TimeoutError, ): result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "abort" @@ -283,7 +283,7 @@ async def test_flow_link_timeout(hass): return_value=[mock_bridge], ): result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( @@ -308,7 +308,7 @@ async def test_flow_link_unknown_error(hass): return_value=[mock_bridge], ): result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( @@ -334,7 +334,7 @@ async def test_flow_link_button_not_pressed(hass): return_value=[mock_bridge], ): result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( @@ -360,7 +360,7 @@ async def test_flow_link_unknown_host(hass): return_value=[mock_bridge], ): result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "user"} + const.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( @@ -380,7 +380,7 @@ async def test_bridge_ssdp(hass, mf_url): """Test a bridge being discovered.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ ssdp.ATTR_SSDP_LOCATION: "http://0.0.0.0/", ssdp.ATTR_UPNP_MANUFACTURER_URL: mf_url, @@ -396,7 +396,7 @@ async def test_bridge_ssdp_discover_other_bridge(hass): """Test that discovery ignores other bridges.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ssdp.ATTR_UPNP_MANUFACTURER_URL: "http://www.notphilips.com"}, ) @@ -408,7 +408,7 @@ async def test_bridge_ssdp_emulated_hue(hass): """Test if discovery info is from an emulated hue instance.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ ssdp.ATTR_SSDP_LOCATION: "http://0.0.0.0/", ssdp.ATTR_UPNP_FRIENDLY_NAME: "Home Assistant Bridge", @@ -425,7 +425,7 @@ async def test_bridge_ssdp_missing_location(hass): """Test if discovery info is missing a location attribute.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.HUE_MANUFACTURERURL[0], ssdp.ATTR_UPNP_SERIAL: "1234", @@ -440,7 +440,7 @@ async def test_bridge_ssdp_missing_serial(hass): """Test if discovery info is a serial attribute.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ ssdp.ATTR_SSDP_LOCATION: "http://0.0.0.0/", ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.HUE_MANUFACTURERURL[0], @@ -455,7 +455,7 @@ async def test_bridge_ssdp_espalexa(hass): """Test if discovery info is from an Espalexa based device.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ ssdp.ATTR_SSDP_LOCATION: "http://0.0.0.0/", ssdp.ATTR_UPNP_FRIENDLY_NAME: "Espalexa (0.0.0.0)", @@ -476,7 +476,7 @@ async def test_bridge_ssdp_already_configured(hass): result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ ssdp.ATTR_SSDP_LOCATION: "http://0.0.0.0/", ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.HUE_MANUFACTURERURL[0], @@ -492,7 +492,7 @@ async def test_import_with_no_config(hass): """Test importing a host without an existing config file.""" result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={"host": "0.0.0.0"}, ) @@ -531,7 +531,9 @@ async def test_creating_entry_removes_entries_for_same_host_or_bridge(hass): return_value=bridge, ): result = await hass.config_entries.flow.async_init( - "hue", data={"host": "2.2.2.2"}, context={"source": "import"} + "hue", + data={"host": "2.2.2.2"}, + context={"source": config_entries.SOURCE_IMPORT}, ) assert result["type"] == "form" @@ -561,7 +563,7 @@ async def test_bridge_homekit(hass, aioclient_mock): result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={ "host": "0.0.0.0", "serial": "1234", @@ -589,7 +591,7 @@ async def test_bridge_import_already_configured(hass): result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={"host": "0.0.0.0", "properties": {"id": "aa:bb:cc:dd:ee:ff"}}, ) @@ -605,7 +607,7 @@ async def test_bridge_homekit_already_configured(hass): result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"host": "0.0.0.0", "properties": {"id": "aa:bb:cc:dd:ee:ff"}}, ) @@ -622,7 +624,7 @@ async def test_ssdp_discovery_update_configuration(hass): result = await hass.config_entries.flow.async_init( const.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ ssdp.ATTR_SSDP_LOCATION: "http://1.1.1.1/", ssdp.ATTR_UPNP_MANUFACTURER_URL: config_flow.HUE_MANUFACTURERURL[0], diff --git a/tests/components/hunterdouglas_powerview/test_config_flow.py b/tests/components/hunterdouglas_powerview/test_config_flow.py index 442cd42f0bc..f88e65ff854 100644 --- a/tests/components/hunterdouglas_powerview/test_config_flow.py +++ b/tests/components/hunterdouglas_powerview/test_config_flow.py @@ -69,7 +69,9 @@ async def test_form_homekit(hass): """Test we get the form with homekit source.""" await setup.async_setup_component(hass, "persistent_notification", {}) - ignored_config_entry = MockConfigEntry(domain=DOMAIN, data={}, source="ignore") + ignored_config_entry = MockConfigEntry( + domain=DOMAIN, data={}, source=config_entries.SOURCE_IGNORE + ) ignored_config_entry.add_to_hass(hass) mock_powerview_userdata = _get_mock_powerview_userdata() @@ -79,7 +81,7 @@ async def test_form_homekit(hass): ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={ "host": "1.2.3.4", "properties": {"id": "AA::BB::CC::DD::EE::FF"}, @@ -114,7 +116,7 @@ async def test_form_homekit(hass): result3 = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={ "host": "1.2.3.4", "properties": {"id": "AA::BB::CC::DD::EE::FF"}, diff --git a/tests/components/hvv_departures/test_config_flow.py b/tests/components/hvv_departures/test_config_flow.py index 3773dbb5967..2042c6b95d1 100644 --- a/tests/components/hvv_departures/test_config_flow.py +++ b/tests/components/hvv_departures/test_config_flow.py @@ -255,7 +255,7 @@ async def test_options_flow(hass): domain=DOMAIN, title="Wartenau", data=FIXTURE_CONFIG_ENTRY, - source="user", + source=SOURCE_USER, connection_class=CONN_CLASS_CLOUD_POLL, system_options={"disable_new_entities": False}, options=FIXTURE_OPTIONS, @@ -306,7 +306,7 @@ async def test_options_flow_invalid_auth(hass): domain=DOMAIN, title="Wartenau", data=FIXTURE_CONFIG_ENTRY, - source="user", + source=SOURCE_USER, connection_class=CONN_CLASS_CLOUD_POLL, system_options={"disable_new_entities": False}, options=FIXTURE_OPTIONS, @@ -347,7 +347,7 @@ async def test_options_flow_cannot_connect(hass): domain=DOMAIN, title="Wartenau", data=FIXTURE_CONFIG_ENTRY, - source="user", + source=SOURCE_USER, connection_class=CONN_CLASS_CLOUD_POLL, system_options={"disable_new_entities": False}, options=FIXTURE_OPTIONS, diff --git a/tests/components/ifttt/test_init.py b/tests/components/ifttt/test_init.py index 41885f0cd26..077fb6d7470 100644 --- a/tests/components/ifttt/test_init.py +++ b/tests/components/ifttt/test_init.py @@ -1,5 +1,5 @@ """Test the init file of IFTTT.""" -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import ifttt from homeassistant.config import async_process_ha_core_config from homeassistant.core import callback @@ -13,7 +13,7 @@ async def test_config_flow_registers_webhook(hass, aiohttp_client): ) result = await hass.config_entries.flow.async_init( - "ifttt", context={"source": "user"} + "ifttt", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result diff --git a/tests/components/islamic_prayer_times/test_config_flow.py b/tests/components/islamic_prayer_times/test_config_flow.py index b7a942e4f14..842a877e292 100644 --- a/tests/components/islamic_prayer_times/test_config_flow.py +++ b/tests/components/islamic_prayer_times/test_config_flow.py @@ -3,7 +3,7 @@ from unittest.mock import patch import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import islamic_prayer_times from homeassistant.components.islamic_prayer_times.const import CONF_CALC_METHOD, DOMAIN @@ -23,7 +23,7 @@ def mock_setup(): async def test_flow_works(hass): """Test user config.""" result = await hass.config_entries.flow.async_init( - islamic_prayer_times.DOMAIN, context={"source": "user"} + islamic_prayer_times.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -62,7 +62,7 @@ async def test_import(hass): """Test import step.""" result = await hass.config_entries.flow.async_init( islamic_prayer_times.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={CONF_CALC_METHOD: "makkah"}, ) @@ -80,7 +80,7 @@ async def test_integration_already_configured(hass): ) entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - islamic_prayer_times.DOMAIN, context={"source": "user"} + islamic_prayer_times.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT diff --git a/tests/components/keenetic_ndms2/test_config_flow.py b/tests/components/keenetic_ndms2/test_config_flow.py index b96448101cf..7561fb03839 100644 --- a/tests/components/keenetic_ndms2/test_config_flow.py +++ b/tests/components/keenetic_ndms2/test_config_flow.py @@ -136,7 +136,7 @@ async def test_host_already_configured(hass, connect): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - keenetic.DOMAIN, context={"source": "user"} + keenetic.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result2 = await hass.config_entries.flow.async_configure( @@ -151,7 +151,7 @@ async def test_connection_error(hass, connect_error): """Test error when connection is unsuccessful.""" result = await hass.config_entries.flow.async_init( - keenetic.DOMAIN, context={"source": "user"} + keenetic.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=MOCK_DATA diff --git a/tests/components/kodi/test_config_flow.py b/tests/components/kodi/test_config_flow.py index 8b8bcf7e88a..5ffa231239b 100644 --- a/tests/components/kodi/test_config_flow.py +++ b/tests/components/kodi/test_config_flow.py @@ -411,7 +411,9 @@ async def test_discovery(hass): return_value=MockConnection(), ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=TEST_DISCOVERY, ) assert result["type"] == "form" @@ -450,7 +452,9 @@ async def test_discovery_cannot_connect_http(hass): return_value=MockConnection(), ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=TEST_DISCOVERY, ) assert result["type"] == "abort" @@ -471,7 +475,9 @@ async def test_discovery_cannot_connect_ws(hass): new=get_kodi_connection, ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=TEST_DISCOVERY, ) assert result["type"] == "form" @@ -489,7 +495,9 @@ async def test_discovery_exception_http(hass, user_flow): return_value=MockConnection(), ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=TEST_DISCOVERY, ) assert result["type"] == "abort" @@ -506,7 +514,9 @@ async def test_discovery_invalid_auth(hass): return_value=MockConnection(), ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=TEST_DISCOVERY, ) assert result["type"] == "form" @@ -524,14 +534,16 @@ async def test_discovery_duplicate_data(hass): return_value=MockConnection(), ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=TEST_DISCOVERY, ) assert result["type"] == "form" assert result["step_id"] == "discovery_confirm" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, data=TEST_DISCOVERY ) assert result["type"] == "abort" @@ -549,7 +561,7 @@ async def test_discovery_updates_unique_id(hass): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, data=TEST_DISCOVERY ) assert result["type"] == "abort" @@ -563,7 +575,9 @@ async def test_discovery_updates_unique_id(hass): async def test_discovery_without_unique_id(hass): """Test a discovery flow with no unique id aborts.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY_WO_UUID + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=TEST_DISCOVERY_WO_UUID, ) assert result["type"] == "abort" diff --git a/tests/components/konnected/test_config_flow.py b/tests/components/konnected/test_config_flow.py index 4b5cc602f99..36f582fcb57 100644 --- a/tests/components/konnected/test_config_flow.py +++ b/tests/components/konnected/test_config_flow.py @@ -3,6 +3,7 @@ from unittest.mock import patch import pytest +from homeassistant import config_entries from homeassistant.components import konnected from homeassistant.components.konnected import config_flow @@ -28,7 +29,7 @@ async def mock_panel_fixture(): async def test_flow_works(hass, mock_panel): """Test config flow .""" result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user"} + config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -65,7 +66,7 @@ async def test_flow_works(hass, mock_panel): async def test_pro_flow_works(hass, mock_panel): """Test config flow .""" result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user"} + config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -110,7 +111,7 @@ async def test_ssdp(hass, mock_panel): result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ "ssdp_location": "http://1.2.3.4:1234/Device.xml", "manufacturer": config_flow.KONN_MANUFACTURER, @@ -137,7 +138,7 @@ async def test_import_no_host_user_finish(hass, mock_panel): result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={ "default_options": { "blink": True, @@ -204,7 +205,7 @@ async def test_import_ssdp_host_user_finish(hass, mock_panel): result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={ "default_options": { "blink": True, @@ -238,7 +239,7 @@ async def test_import_ssdp_host_user_finish(hass, mock_panel): # discover the panel via ssdp ssdp_result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ "ssdp_location": "http://0.0.0.0:1234/Device.xml", "manufacturer": config_flow.KONN_MANUFACTURER, @@ -281,7 +282,7 @@ async def test_ssdp_already_configured(hass, mock_panel): result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ "ssdp_location": "http://0.0.0.0:1234/Device.xml", "manufacturer": config_flow.KONN_MANUFACTURER, @@ -357,7 +358,7 @@ async def test_ssdp_host_update(hass, mock_panel): result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "ssdp"}, + context={"source": config_entries.SOURCE_SSDP}, data={ "ssdp_location": "http://1.1.1.1:1234/Device.xml", "manufacturer": config_flow.KONN_MANUFACTURER, @@ -382,7 +383,7 @@ async def test_import_existing_config(hass, mock_panel): result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data=konnected.DEVICE_SCHEMA_YAML( { "host": "1.2.3.4", @@ -515,7 +516,7 @@ async def test_import_existing_config_entry(hass, mock_panel): hass.data[config_flow.DOMAIN] = {"access_token": "SUPERSECRETTOKEN"} result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={ "host": "1.2.3.4", "port": 1234, @@ -573,7 +574,7 @@ async def test_import_pin_config(hass, mock_panel): result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data=konnected.DEVICE_SCHEMA_YAML( { "host": "1.2.3.4", diff --git a/tests/components/litejet/test_config_flow.py b/tests/components/litejet/test_config_flow.py index 015ba1c6494..1d72324f484 100644 --- a/tests/components/litejet/test_config_flow.py +++ b/tests/components/litejet/test_config_flow.py @@ -3,6 +3,7 @@ from unittest.mock import patch from serial import SerialException +from homeassistant import config_entries from homeassistant.components.litejet.const import DOMAIN from homeassistant.const import CONF_PORT @@ -12,7 +13,7 @@ from tests.common import MockConfigEntry async def test_show_config_form(hass): """Test show configuration form.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -24,7 +25,7 @@ async def test_create_entry(hass, mock_litejet): test_data = {CONF_PORT: "/dev/test"} result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "create_entry" @@ -43,7 +44,7 @@ async def test_flow_entry_already_exists(hass): test_data = {CONF_PORT: "/dev/test"} result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "abort" @@ -58,7 +59,7 @@ async def test_flow_open_failed(hass): mock_pylitejet.side_effect = SerialException result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "form" @@ -69,7 +70,7 @@ async def test_import_step(hass): """Test initializing via import step.""" test_data = {CONF_PORT: "/dev/imported"} result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=test_data ) assert result["type"] == "create_entry" diff --git a/tests/components/locative/test_init.py b/tests/components/locative/test_init.py index d183cb9814a..bd39ec42978 100644 --- a/tests/components/locative/test_init.py +++ b/tests/components/locative/test_init.py @@ -3,7 +3,7 @@ from unittest.mock import patch import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import locative from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN from homeassistant.components.locative import DOMAIN, TRACKER_UPDATE @@ -39,7 +39,7 @@ async def webhook_id(hass, locative_client): {"internal_url": "http://example.local:8123"}, ) result = await hass.config_entries.flow.async_init( - "locative", context={"source": "user"} + "locative", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result diff --git a/tests/components/lutron_caseta/test_config_flow.py b/tests/components/lutron_caseta/test_config_flow.py index e65eb9d5f47..14adefc37db 100644 --- a/tests/components/lutron_caseta/test_config_flow.py +++ b/tests/components/lutron_caseta/test_config_flow.py @@ -197,7 +197,9 @@ async def test_already_configured_with_ignored(hass): """Test ignored entries do not break checking for existing entries.""" await setup.async_setup_component(hass, "persistent_notification", {}) - config_entry = MockConfigEntry(domain=DOMAIN, data={}, source="ignore") + config_entry = MockConfigEntry( + domain=DOMAIN, data={}, source=config_entries.SOURCE_IGNORE + ) config_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( diff --git a/tests/components/lyric/test_config_flow.py b/tests/components/lyric/test_config_flow.py index 71fb473127d..f5f41da08fd 100644 --- a/tests/components/lyric/test_config_flow.py +++ b/tests/components/lyric/test_config_flow.py @@ -160,7 +160,7 @@ async def test_reauthentication_flow( old_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=old_entry.data + DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=old_entry.data ) flows = hass.config_entries.flow.async_progress() diff --git a/tests/components/mailgun/test_init.py b/tests/components/mailgun/test_init.py index fd244d87a8f..bf0df205c93 100644 --- a/tests/components/mailgun/test_init.py +++ b/tests/components/mailgun/test_init.py @@ -4,7 +4,7 @@ import hmac import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import mailgun, webhook from homeassistant.config import async_process_ha_core_config from homeassistant.const import CONF_API_KEY, CONF_DOMAIN @@ -35,7 +35,7 @@ async def webhook_id_with_api_key(hass): {"internal_url": "http://example.local:8123"}, ) result = await hass.config_entries.flow.async_init( - "mailgun", context={"source": "user"} + "mailgun", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result @@ -55,7 +55,7 @@ async def webhook_id_without_api_key(hass): {"internal_url": "http://example.local:8123"}, ) result = await hass.config_entries.flow.async_init( - "mailgun", context={"source": "user"} + "mailgun", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result diff --git a/tests/components/mazda/test_config_flow.py b/tests/components/mazda/test_config_flow.py index 06cb0e15d09..f6ea8c73a9b 100644 --- a/tests/components/mazda/test_config_flow.py +++ b/tests/components/mazda/test_config_flow.py @@ -199,7 +199,10 @@ async def test_reauth_flow(hass: HomeAssistant) -> None: result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "entry_id": mock_config.entry_id}, + context={ + "source": config_entries.SOURCE_REAUTH, + "entry_id": mock_config.entry_id, + }, data=FIXTURE_USER_INPUT, ) @@ -239,7 +242,10 @@ async def test_reauth_authorization_error(hass: HomeAssistant) -> None: ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "entry_id": mock_config.entry_id}, + context={ + "source": config_entries.SOURCE_REAUTH, + "entry_id": mock_config.entry_id, + }, data=FIXTURE_USER_INPUT, ) @@ -275,7 +281,10 @@ async def test_reauth_account_locked(hass: HomeAssistant) -> None: ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "entry_id": mock_config.entry_id}, + context={ + "source": config_entries.SOURCE_REAUTH, + "entry_id": mock_config.entry_id, + }, data=FIXTURE_USER_INPUT, ) @@ -311,7 +320,10 @@ async def test_reauth_connection_error(hass: HomeAssistant) -> None: ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "entry_id": mock_config.entry_id}, + context={ + "source": config_entries.SOURCE_REAUTH, + "entry_id": mock_config.entry_id, + }, data=FIXTURE_USER_INPUT, ) @@ -347,7 +359,10 @@ async def test_reauth_unknown_error(hass: HomeAssistant) -> None: ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "entry_id": mock_config.entry_id}, + context={ + "source": config_entries.SOURCE_REAUTH, + "entry_id": mock_config.entry_id, + }, data=FIXTURE_USER_INPUT, ) @@ -383,7 +398,10 @@ async def test_reauth_user_has_new_email_address(hass: HomeAssistant) -> None: ): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "entry_id": mock_config.entry_id}, + context={ + "source": config_entries.SOURCE_REAUTH, + "entry_id": mock_config.entry_id, + }, data=FIXTURE_USER_INPUT, ) diff --git a/tests/components/met/test_config_flow.py b/tests/components/met/test_config_flow.py index 25e123f67e8..ff5deb18194 100644 --- a/tests/components/met/test_config_flow.py +++ b/tests/components/met/test_config_flow.py @@ -3,6 +3,7 @@ from unittest.mock import patch import pytest +from homeassistant import config_entries from homeassistant.components.met.const import DOMAIN, HOME_LOCATION_NAME from homeassistant.config import async_process_ha_core_config from homeassistant.const import CONF_ELEVATION, CONF_LATITUDE, CONF_LONGITUDE @@ -20,7 +21,7 @@ def met_setup_fixture(): async def test_show_config_form(hass): """Test show configuration form.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -38,7 +39,7 @@ async def test_flow_with_home_location(hass): hass.config.elevation = 3 result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -61,7 +62,7 @@ async def test_create_entry(hass): } result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "create_entry" @@ -89,7 +90,7 @@ async def test_flow_entry_already_exists(hass): } result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "form" @@ -136,7 +137,7 @@ async def test_import_step(hass): "track_home": True, } result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=test_data ) assert result["type"] == "create_entry" diff --git a/tests/components/met/test_weather.py b/tests/components/met/test_weather.py index 32f36d09630..8ffa4076b8a 100644 --- a/tests/components/met/test_weather.py +++ b/tests/components/met/test_weather.py @@ -1,5 +1,6 @@ """Test Met weather entity.""" +from homeassistant import config_entries from homeassistant.components.met import DOMAIN from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN from homeassistant.helpers import entity_registry as er @@ -55,7 +56,7 @@ async def test_not_tracking_home(hass, mock_weather): await hass.config_entries.flow.async_init( "met", - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data={"name": "Somewhere", "latitude": 10, "longitude": 20, "elevation": 0}, ) await hass.async_block_till_done() diff --git a/tests/components/mikrotik/test_config_flow.py b/tests/components/mikrotik/test_config_flow.py index c884315f400..411408e8c98 100644 --- a/tests/components/mikrotik/test_config_flow.py +++ b/tests/components/mikrotik/test_config_flow.py @@ -5,7 +5,7 @@ from unittest.mock import patch import librouteros import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import mikrotik from homeassistant.const import ( CONF_HOST, @@ -81,7 +81,9 @@ def mock_api_connection_error(): async def test_import(hass, api): """Test import step.""" result = await hass.config_entries.flow.async_init( - mikrotik.DOMAIN, context={"source": "import"}, data=DEMO_CONFIG + mikrotik.DOMAIN, + context={"source": config_entries.SOURCE_IMPORT}, + data=DEMO_CONFIG, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY @@ -98,7 +100,7 @@ async def test_flow_works(hass, api): """Test config flow.""" result = await hass.config_entries.flow.async_init( - mikrotik.DOMAIN, context={"source": "user"} + mikrotik.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -150,7 +152,7 @@ async def test_host_already_configured(hass, auth_error): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - mikrotik.DOMAIN, context={"source": "user"} + mikrotik.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=DEMO_USER_INPUT @@ -168,7 +170,7 @@ async def test_name_exists(hass, api): user_input[CONF_HOST] = "0.0.0.1" result = await hass.config_entries.flow.async_init( - mikrotik.DOMAIN, context={"source": "user"} + mikrotik.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=user_input @@ -182,7 +184,7 @@ async def test_connection_error(hass, conn_error): """Test error when connection is unsuccessful.""" result = await hass.config_entries.flow.async_init( - mikrotik.DOMAIN, context={"source": "user"} + mikrotik.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=DEMO_USER_INPUT @@ -195,7 +197,7 @@ async def test_wrong_credentials(hass, auth_error): """Test error when credentials are wrong.""" result = await hass.config_entries.flow.async_init( - mikrotik.DOMAIN, context={"source": "user"} + mikrotik.DOMAIN, context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input=DEMO_USER_INPUT diff --git a/tests/components/mill/test_config_flow.py b/tests/components/mill/test_config_flow.py index ee565d32211..ce35b3d9708 100644 --- a/tests/components/mill/test_config_flow.py +++ b/tests/components/mill/test_config_flow.py @@ -3,6 +3,7 @@ from unittest.mock import patch import pytest +from homeassistant import config_entries from homeassistant.components.mill.const import DOMAIN from homeassistant.const import CONF_PASSWORD, CONF_USERNAME @@ -19,7 +20,7 @@ def mill_setup_fixture(): async def test_show_config_form(hass): """Test show configuration form.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -35,7 +36,7 @@ async def test_create_entry(hass): with patch("mill.Mill.connect", return_value=True): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "create_entry" @@ -60,7 +61,7 @@ async def test_flow_entry_already_exists(hass): with patch("mill.Mill.connect", return_value=True): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "abort" @@ -84,7 +85,7 @@ async def test_connection_error(hass): with patch("mill.Mill.connect", return_value=False): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "form" diff --git a/tests/components/mqtt/test_config_flow.py b/tests/components/mqtt/test_config_flow.py index b41a446a8c0..55bacb0ef91 100644 --- a/tests/components/mqtt/test_config_flow.py +++ b/tests/components/mqtt/test_config_flow.py @@ -5,7 +5,7 @@ from unittest.mock import patch import pytest import voluptuous as vol -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import mqtt from homeassistant.setup import async_setup_component @@ -33,7 +33,7 @@ async def test_user_connection_works(hass, mock_try_connection, mock_finish_setu mock_try_connection.return_value = True result = await hass.config_entries.flow.async_init( - "mqtt", context={"source": "user"} + "mqtt", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -58,7 +58,7 @@ async def test_user_connection_fails(hass, mock_try_connection, mock_finish_setu mock_try_connection.return_value = False result = await hass.config_entries.flow.async_init( - "mqtt", context={"source": "user"} + "mqtt", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -84,7 +84,7 @@ async def test_manual_config_set(hass, mock_try_connection, mock_finish_setup): mock_try_connection.return_value = True result = await hass.config_entries.flow.async_init( - "mqtt", context={"source": "user"} + "mqtt", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "abort" @@ -94,7 +94,7 @@ async def test_user_single_instance(hass): MockConfigEntry(domain="mqtt").add_to_hass(hass) result = await hass.config_entries.flow.async_init( - "mqtt", context={"source": "user"} + "mqtt", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "abort" assert result["reason"] == "single_instance_allowed" @@ -105,7 +105,7 @@ async def test_hassio_single_instance(hass): MockConfigEntry(domain="mqtt").add_to_hass(hass) result = await hass.config_entries.flow.async_init( - "mqtt", context={"source": "hassio"} + "mqtt", context={"source": config_entries.SOURCE_HASSIO} ) assert result["type"] == "abort" assert result["reason"] == "single_instance_allowed" @@ -125,7 +125,7 @@ async def test_hassio_confirm(hass, mock_try_connection, mock_finish_setup): "password": "mock-pass", "protocol": "3.1.1", }, - context={"source": "hassio"}, + context={"source": config_entries.SOURCE_HASSIO}, ) assert result["type"] == "form" assert result["step_id"] == "hassio_confirm" diff --git a/tests/components/myq/test_config_flow.py b/tests/components/myq/test_config_flow.py index bbfa090b01c..683b6beab8a 100644 --- a/tests/components/myq/test_config_flow.py +++ b/tests/components/myq/test_config_flow.py @@ -88,7 +88,7 @@ async def test_form_homekit(hass): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, ) assert result["type"] == "form" @@ -107,7 +107,7 @@ async def test_form_homekit(hass): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, ) assert result["type"] == "abort" diff --git a/tests/components/netatmo/test_config_flow.py b/tests/components/netatmo/test_config_flow.py index 03c751aae96..6bd8086c820 100644 --- a/tests/components/netatmo/test_config_flow.py +++ b/tests/components/netatmo/test_config_flow.py @@ -36,7 +36,7 @@ async def test_abort_if_existing_entry(hass): result = await hass.config_entries.flow.async_init( "netatmo", - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"host": "0.0.0.0", "properties": {"id": "aa:bb:cc:dd:ee:ff"}}, ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT diff --git a/tests/components/onewire/__init__.py b/tests/components/onewire/__init__.py index fdc0c7fe12c..088c6a3ad11 100644 --- a/tests/components/onewire/__init__.py +++ b/tests/components/onewire/__init__.py @@ -14,7 +14,7 @@ from homeassistant.components.onewire.const import ( DEFAULT_SYSBUS_MOUNT_DIR, DOMAIN, ) -from homeassistant.config_entries import CONN_CLASS_LOCAL_POLL +from homeassistant.config_entries import CONN_CLASS_LOCAL_POLL, SOURCE_USER from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE from .const import MOCK_OWPROXY_DEVICES, MOCK_SYSBUS_DEVICES @@ -26,7 +26,7 @@ async def setup_onewire_sysbus_integration(hass): """Create the 1-Wire integration.""" config_entry = MockConfigEntry( domain=DOMAIN, - source="user", + source=SOURCE_USER, data={ CONF_TYPE: CONF_TYPE_SYSBUS, CONF_MOUNT_DIR: DEFAULT_SYSBUS_MOUNT_DIR, @@ -51,7 +51,7 @@ async def setup_onewire_owserver_integration(hass): """Create the 1-Wire integration.""" config_entry = MockConfigEntry( domain=DOMAIN, - source="user", + source=SOURCE_USER, data={ CONF_TYPE: CONF_TYPE_OWSERVER, CONF_HOST: "1.2.3.4", @@ -76,7 +76,7 @@ async def setup_onewire_patched_owserver_integration(hass): """Create the 1-Wire integration.""" config_entry = MockConfigEntry( domain=DOMAIN, - source="user", + source=SOURCE_USER, data={ CONF_TYPE: CONF_TYPE_OWSERVER, CONF_HOST: "1.2.3.4", diff --git a/tests/components/onewire/test_init.py b/tests/components/onewire/test_init.py index 5783b241a2f..21e512a2229 100644 --- a/tests/components/onewire/test_init.py +++ b/tests/components/onewire/test_init.py @@ -10,6 +10,7 @@ from homeassistant.config_entries import ( ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED, ENTRY_STATE_SETUP_RETRY, + SOURCE_USER, ) from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TYPE from homeassistant.helpers import device_registry as dr, entity_registry as er @@ -29,7 +30,7 @@ async def test_owserver_connect_failure(hass): """Test connection failure raises ConfigEntryNotReady.""" config_entry_owserver = MockConfigEntry( domain=DOMAIN, - source="user", + source=SOURCE_USER, data={ CONF_TYPE: CONF_TYPE_OWSERVER, CONF_HOST: "1.2.3.4", @@ -58,7 +59,7 @@ async def test_failed_owserver_listing(hass): """Create the 1-Wire integration.""" config_entry_owserver = MockConfigEntry( domain=DOMAIN, - source="user", + source=SOURCE_USER, data={ CONF_TYPE: CONF_TYPE_OWSERVER, CONF_HOST: "1.2.3.4", diff --git a/tests/components/onvif/test_config_flow.py b/tests/components/onvif/test_config_flow.py index 1802d211348..a8827247689 100644 --- a/tests/components/onvif/test_config_flow.py +++ b/tests/components/onvif/test_config_flow.py @@ -137,7 +137,7 @@ async def setup_onvif_integration( options=None, unique_id=MAC, entry_id="1", - source="user", + source=config_entries.SOURCE_USER, ): """Create an ONVIF config entry.""" if not config: @@ -180,7 +180,7 @@ async def test_flow_discovered_devices(hass): """Test that config flow works for discovered devices.""" result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user"} + config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -245,7 +245,7 @@ async def test_flow_discovered_devices_ignore_configured_manual_input(hass): await setup_onvif_integration(hass) result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user"} + config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -296,7 +296,7 @@ async def test_flow_discovery_ignore_existing_and_abort(hass): ) result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user"} + config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -348,7 +348,7 @@ async def test_flow_discovery_ignore_existing_and_abort(hass): async def test_flow_manual_entry(hass): """Test that config flow works for discovered devices.""" result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user"} + config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM diff --git a/tests/components/ovo_energy/test_config_flow.py b/tests/components/ovo_energy/test_config_flow.py index d5ee8c6d3d9..a8f0c098aba 100644 --- a/tests/components/ovo_energy/test_config_flow.py +++ b/tests/components/ovo_energy/test_config_flow.py @@ -105,7 +105,9 @@ async def test_reauth_authorization_error(hass: HomeAssistant) -> None: return_value=False, ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=FIXTURE_USER_INPUT + DOMAIN, + context={"source": config_entries.SOURCE_REAUTH}, + data=FIXTURE_USER_INPUT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -129,7 +131,9 @@ async def test_reauth_connection_error(hass: HomeAssistant) -> None: side_effect=aiohttp.ClientError, ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=FIXTURE_USER_INPUT + DOMAIN, + context={"source": config_entries.SOURCE_REAUTH}, + data=FIXTURE_USER_INPUT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -158,7 +162,9 @@ async def test_reauth_flow(hass: HomeAssistant) -> None: mock_config.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=FIXTURE_USER_INPUT + DOMAIN, + context={"source": config_entries.SOURCE_REAUTH}, + data=FIXTURE_USER_INPUT, ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM diff --git a/tests/components/owntracks/test_config_flow.py b/tests/components/owntracks/test_config_flow.py index d6ac059ce26..93d4bf5385b 100644 --- a/tests/components/owntracks/test_config_flow.py +++ b/tests/components/owntracks/test_config_flow.py @@ -3,7 +3,7 @@ from unittest.mock import patch import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.owntracks import config_flow from homeassistant.components.owntracks.config_flow import CONF_CLOUDHOOK, CONF_SECRET from homeassistant.components.owntracks.const import DOMAIN @@ -143,7 +143,7 @@ async def test_unload(hass): "homeassistant.config_entries.ConfigEntries.async_forward_entry_setup" ) as mock_forward: result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data={} + DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data={} ) assert len(mock_forward.mock_calls) == 1 @@ -175,7 +175,7 @@ async def test_with_cloud_sub(hass): return_value="https://hooks.nabu.casa/ABCD", ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data={} + DOMAIN, context={"source": config_entries.SOURCE_USER}, data={} ) entry = result["result"] diff --git a/tests/components/plex/test_config_flow.py b/tests/components/plex/test_config_flow.py index e0555bab0e8..d5209201d94 100644 --- a/tests/components/plex/test_config_flow.py +++ b/tests/components/plex/test_config_flow.py @@ -26,6 +26,7 @@ from homeassistant.config_entries import ( ENTRY_STATE_LOADED, SOURCE_INTEGRATION_DISCOVERY, SOURCE_REAUTH, + SOURCE_USER, ) from homeassistant.const import ( CONF_HOST, @@ -52,7 +53,7 @@ async def test_bad_credentials(hass): ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -85,7 +86,7 @@ async def test_bad_hostname(hass, mock_plex_calls): ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -119,7 +120,7 @@ async def test_unknown_exception(hass): ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -150,7 +151,7 @@ async def test_no_servers_found(hass, mock_plex_calls, requests_mock, empty_payl ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -181,7 +182,7 @@ async def test_single_available_server(hass, mock_plex_calls): ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -226,7 +227,7 @@ async def test_multiple_servers_with_selection( ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -290,7 +291,7 @@ async def test_adding_last_unconfigured_server( ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -350,7 +351,7 @@ async def test_all_available_servers_configured( ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -478,7 +479,7 @@ async def test_external_timed_out(hass): ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -508,7 +509,7 @@ async def test_callback_view(hass, aiohttp_client): ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -545,7 +546,7 @@ async def test_manual_config(hass, mock_plex_calls): # Basic mode result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user"} + config_flow.DOMAIN, context={"source": SOURCE_USER} ) assert result["type"] == "form" @@ -555,7 +556,8 @@ async def test_manual_config(hass, mock_plex_calls): # Advanced automatic result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user", "show_advanced_options": True} + config_flow.DOMAIN, + context={"source": SOURCE_USER, "show_advanced_options": True}, ) assert result["data_schema"] is not None @@ -572,7 +574,8 @@ async def test_manual_config(hass, mock_plex_calls): # Advanced manual result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user", "show_advanced_options": True} + config_flow.DOMAIN, + context={"source": SOURCE_USER, "show_advanced_options": True}, ) assert result["data_schema"] is not None @@ -668,7 +671,8 @@ async def test_manual_config_with_token(hass, mock_plex_calls): """Test creating via manual configuration with only token.""" result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user", "show_advanced_options": True} + config_flow.DOMAIN, + context={"source": SOURCE_USER, "show_advanced_options": True}, ) assert result["type"] == "form" diff --git a/tests/components/powerwall/test_config_flow.py b/tests/components/powerwall/test_config_flow.py index 407a63bac23..61230f59e52 100644 --- a/tests/components/powerwall/test_config_flow.py +++ b/tests/components/powerwall/test_config_flow.py @@ -159,7 +159,9 @@ async def test_already_configured_with_ignored(hass): """Test ignored entries do not break checking for existing entries.""" await setup.async_setup_component(hass, "persistent_notification", {}) - config_entry = MockConfigEntry(domain=DOMAIN, data={}, source="ignore") + config_entry = MockConfigEntry( + domain=DOMAIN, data={}, source=config_entries.SOURCE_IGNORE + ) config_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( @@ -220,7 +222,7 @@ async def test_form_reauth(hass): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=entry.data + DOMAIN, context={"source": config_entries.SOURCE_REAUTH}, data=entry.data ) assert result["type"] == "form" assert result["errors"] == {} diff --git a/tests/components/ps4/test_config_flow.py b/tests/components/ps4/test_config_flow.py index bcae74c19fb..f8c28d236be 100644 --- a/tests/components/ps4/test_config_flow.py +++ b/tests/components/ps4/test_config_flow.py @@ -4,7 +4,7 @@ from unittest.mock import patch from pyps4_2ndscreen.errors import CredentialTimeout import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import ps4 from homeassistant.components.ps4.config_flow import LOCAL_UDP_PORT from homeassistant.components.ps4.const import ( @@ -101,7 +101,7 @@ async def test_full_flow_implementation(hass): # User Step Started, results in Step Creds with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -142,7 +142,7 @@ async def test_multiple_flow_implementation(hass): # User Step Started, results in Step Creds with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -194,7 +194,7 @@ async def test_multiple_flow_implementation(hass): return_value=[{"host-ip": MOCK_HOST}, {"host-ip": MOCK_HOST_ADDITIONAL}], ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -247,7 +247,7 @@ async def test_port_bind_abort(hass): with patch("pyps4_2ndscreen.Helper.port_bind", return_value=MOCK_UDP_PORT): reason = "port_987_bind_error" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == reason @@ -255,7 +255,7 @@ async def test_port_bind_abort(hass): with patch("pyps4_2ndscreen.Helper.port_bind", return_value=MOCK_TCP_PORT): reason = "port_997_bind_error" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == reason @@ -267,7 +267,7 @@ async def test_duplicate_abort(hass): with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -297,7 +297,7 @@ async def test_additional_device(hass): with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -370,7 +370,7 @@ async def test_no_devices_found_abort(hass): """Test that failure to find devices aborts flow.""" with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -395,7 +395,7 @@ async def test_manual_mode(hass): """Test host specified in manual mode is passed to Step Link.""" with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -423,7 +423,7 @@ async def test_credential_abort(hass): """Test that failure to get credentials aborts flow.""" with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -441,7 +441,7 @@ async def test_credential_timeout(hass): """Test that Credential Timeout shows error.""" with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -460,7 +460,7 @@ async def test_wrong_pin_error(hass): """Test that incorrect pin throws an error.""" with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -492,7 +492,7 @@ async def test_device_connection_error(hass): """Test that device not connected or on throws an error.""" with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" @@ -524,7 +524,7 @@ async def test_manual_mode_no_ip_error(hass): """Test no IP specified in manual mode throws an error.""" with patch("pyps4_2ndscreen.Helper.port_bind", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "creds" diff --git a/tests/components/pvpc_hourly_pricing/test_config_flow.py b/tests/components/pvpc_hourly_pricing/test_config_flow.py index 038b106f6c8..31a7005c4cc 100644 --- a/tests/components/pvpc_hourly_pricing/test_config_flow.py +++ b/tests/components/pvpc_hourly_pricing/test_config_flow.py @@ -4,7 +4,7 @@ from unittest.mock import patch from pytz import timezone -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.pvpc_hourly_pricing import ATTR_TARIFF, DOMAIN from homeassistant.const import CONF_NAME from homeassistant.helpers import entity_registry as er @@ -34,7 +34,7 @@ async def test_config_flow( with patch("homeassistant.util.dt.utcnow", new=mock_now): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -50,7 +50,7 @@ async def test_config_flow( # Check abort when configuring another with same tariff result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM result = await hass.config_entries.flow.async_configure( @@ -66,7 +66,7 @@ async def test_config_flow( # and add it again with UI result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM diff --git a/tests/components/rachio/test_config_flow.py b/tests/components/rachio/test_config_flow.py index ddf403343cf..324cfd0fbf1 100644 --- a/tests/components/rachio/test_config_flow.py +++ b/tests/components/rachio/test_config_flow.py @@ -111,7 +111,7 @@ async def test_form_homekit(hass): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, ) assert result["type"] == "form" @@ -128,7 +128,7 @@ async def test_form_homekit(hass): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, ) assert result["type"] == "abort" diff --git a/tests/components/roomba/test_config_flow.py b/tests/components/roomba/test_config_flow.py index 32b3c1d95b3..bebf1724761 100644 --- a/tests/components/roomba/test_config_flow.py +++ b/tests/components/roomba/test_config_flow.py @@ -820,7 +820,9 @@ async def test_dhcp_discovery_with_ignored(hass): """Test ignored entries do not break checking for existing entries.""" await setup.async_setup_component(hass, "persistent_notification", {}) - config_entry = MockConfigEntry(domain=DOMAIN, data={}, source="ignore") + config_entry = MockConfigEntry( + domain=DOMAIN, data={}, source=config_entries.SOURCE_IGNORE + ) config_entry.add_to_hass(hass) with patch( diff --git a/tests/components/samsungtv/test_config_flow.py b/tests/components/samsungtv/test_config_flow.py index ea78ecacb3e..fb1b2a2bc67 100644 --- a/tests/components/samsungtv/test_config_flow.py +++ b/tests/components/samsungtv/test_config_flow.py @@ -6,6 +6,7 @@ from samsungctl.exceptions import AccessDenied, UnhandledResponse from samsungtvws.exceptions import ConnectionFailure from websocket import WebSocketProtocolException +from homeassistant import config_entries from homeassistant.components.samsungtv.const import ( CONF_MANUFACTURER, CONF_MODEL, @@ -102,7 +103,7 @@ async def test_user_legacy(hass, remote): """Test starting a flow by user.""" # show form result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -129,7 +130,7 @@ async def test_user_websocket(hass, remotews): ): # show form result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "user" @@ -157,7 +158,7 @@ async def test_user_legacy_missing_auth(hass): ), patch("homeassistant.components.samsungtv.config_flow.socket"): # legacy device missing authentication result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "abort" assert result["reason"] == "auth_missing" @@ -171,7 +172,7 @@ async def test_user_legacy_not_supported(hass): ), patch("homeassistant.components.samsungtv.config_flow.socket"): # legacy device not supported result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "abort" assert result["reason"] == "not_supported" @@ -190,7 +191,7 @@ async def test_user_websocket_not_supported(hass): ): # websocket device not supported result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "abort" assert result["reason"] == "not_supported" @@ -208,7 +209,7 @@ async def test_user_not_successful(hass): "homeassistant.components.samsungtv.config_flow.socket" ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "abort" assert result["reason"] == "cannot_connect" @@ -226,7 +227,7 @@ async def test_user_not_successful_2(hass): "homeassistant.components.samsungtv.config_flow.socket" ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "abort" assert result["reason"] == "cannot_connect" @@ -237,13 +238,13 @@ async def test_user_already_configured(hass, remote): # entry was added result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "create_entry" # failed as already configured result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "abort" assert result["reason"] == "already_configured" @@ -254,7 +255,7 @@ async def test_ssdp(hass, remote): # confirm to add the entry result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA + DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result["type"] == "form" assert result["step_id"] == "confirm" @@ -277,7 +278,9 @@ async def test_ssdp_noprefix(hass, remote): # confirm to add the entry result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA_NOPREFIX + DOMAIN, + context={"source": config_entries.SOURCE_SSDP}, + data=MOCK_SSDP_DATA_NOPREFIX, ) assert result["type"] == "form" assert result["step_id"] == "confirm" @@ -304,7 +307,7 @@ async def test_ssdp_legacy_missing_auth(hass): # confirm to add the entry result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA + DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result["type"] == "form" assert result["step_id"] == "confirm" @@ -326,7 +329,7 @@ async def test_ssdp_legacy_not_supported(hass): # confirm to add the entry result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA + DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result["type"] == "form" assert result["step_id"] == "confirm" @@ -352,7 +355,7 @@ async def test_ssdp_websocket_not_supported(hass): ): # confirm to add the entry result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA + DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result["type"] == "form" assert result["step_id"] == "confirm" @@ -379,7 +382,7 @@ async def test_ssdp_not_successful(hass): # confirm to add the entry result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA + DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result["type"] == "form" assert result["step_id"] == "confirm" @@ -406,7 +409,7 @@ async def test_ssdp_not_successful_2(hass): # confirm to add the entry result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA + DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result["type"] == "form" assert result["step_id"] == "confirm" @@ -424,14 +427,14 @@ async def test_ssdp_already_in_progress(hass, remote): # confirm to add the entry result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA + DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result["type"] == "form" assert result["step_id"] == "confirm" # failed as already in progress result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA + DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result["type"] == "abort" assert result["reason"] == "already_in_progress" @@ -442,7 +445,7 @@ async def test_ssdp_already_configured(hass, remote): # entry was added result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "create_entry" entry = result["result"] @@ -452,7 +455,7 @@ async def test_ssdp_already_configured(hass, remote): # failed as already configured result2 = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "ssdp"}, data=MOCK_SSDP_DATA + DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA ) assert result2["type"] == "abort" assert result2["reason"] == "already_configured" @@ -477,7 +480,7 @@ async def test_autodetect_websocket(hass, remote, remotews): remotews.return_value = remote result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "create_entry" assert result["data"][CONF_METHOD] == "websocket" @@ -503,7 +506,7 @@ async def test_autodetect_websocket_ssl(hass, remote, remotews): remotews.return_value = remote result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "create_entry" assert result["data"][CONF_METHOD] == "websocket" @@ -522,7 +525,7 @@ async def test_autodetect_auth_missing(hass, remote): side_effect=[AccessDenied("Boom")], ) as remote: result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "abort" assert result["reason"] == "auth_missing" @@ -537,7 +540,7 @@ async def test_autodetect_not_supported(hass, remote): side_effect=[UnhandledResponse("Boom")], ) as remote: result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "abort" assert result["reason"] == "not_supported" @@ -549,7 +552,7 @@ async def test_autodetect_legacy(hass, remote): """Test for send key with autodetection of protocol.""" with patch("homeassistant.components.samsungtv.bridge.Remote") as remote: result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "create_entry" assert result["data"][CONF_METHOD] == "legacy" @@ -567,7 +570,7 @@ async def test_autodetect_none(hass, remote, remotews): side_effect=OSError("Boom"), ) as remotews: result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=MOCK_USER_DATA + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA ) assert result["type"] == "abort" assert result["reason"] == "cannot_connect" diff --git a/tests/components/screenlogic/test_config_flow.py b/tests/components/screenlogic/test_config_flow.py index 71dc4935001..f64e35a28b6 100644 --- a/tests/components/screenlogic/test_config_flow.py +++ b/tests/components/screenlogic/test_config_flow.py @@ -137,7 +137,7 @@ async def test_dhcp(hass): await setup.async_setup_component(hass, "persistent_notification", {}) result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "dhcp"}, + context={"source": config_entries.SOURCE_DHCP}, data={ HOSTNAME: "Pentair: 01-01-01", IP_ADDRESS: "1.1.1.1", diff --git a/tests/components/sharkiq/test_config_flow.py b/tests/components/sharkiq/test_config_flow.py index d291d9f1bd1..dc631f48a46 100644 --- a/tests/components/sharkiq/test_config_flow.py +++ b/tests/components/sharkiq/test_config_flow.py @@ -73,7 +73,9 @@ async def test_reauth_success(hass: HomeAssistant): mock_config.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth", "unique_id": UNIQUE_ID}, data=CONFIG + DOMAIN, + context={"source": config_entries.SOURCE_REAUTH, "unique_id": UNIQUE_ID}, + data=CONFIG, ) assert result["type"] == "abort" @@ -99,7 +101,7 @@ async def test_reauth( with patch("sharkiqpy.AylaApi.async_sign_in", side_effect=side_effect): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth", "unique_id": UNIQUE_ID}, + context={"source": config_entries.SOURCE_REAUTH, "unique_id": UNIQUE_ID}, data=CONFIG, ) diff --git a/tests/components/simplisafe/test_config_flow.py b/tests/components/simplisafe/test_config_flow.py index 8f9d3a9897c..a048e4b0745 100644 --- a/tests/components/simplisafe/test_config_flow.py +++ b/tests/components/simplisafe/test_config_flow.py @@ -9,7 +9,7 @@ from simplipy.errors import ( from homeassistant import data_entry_flow from homeassistant.components.simplisafe import DOMAIN -from homeassistant.config_entries import SOURCE_USER +from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER from homeassistant.const import CONF_CODE, CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME from tests.common import MockConfigEntry @@ -107,7 +107,7 @@ async def test_step_reauth(hass): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "reauth"}, + context={"source": SOURCE_REAUTH}, data={CONF_CODE: "1234", CONF_USERNAME: "user@email.com"}, ) assert result["step_id"] == "reauth_confirm" diff --git a/tests/components/sma/conftest.py b/tests/components/sma/conftest.py index 7522aeedf1b..9ec9e1f5a11 100644 --- a/tests/components/sma/conftest.py +++ b/tests/components/sma/conftest.py @@ -3,6 +3,7 @@ from unittest.mock import patch import pytest +from homeassistant import config_entries from homeassistant.components.sma.const import DOMAIN from . import MOCK_CUSTOM_SETUP_DATA, MOCK_DEVICE @@ -18,7 +19,7 @@ def mock_config_entry(): title=MOCK_DEVICE["name"], unique_id=MOCK_DEVICE["serial"], data=MOCK_CUSTOM_SETUP_DATA, - source="import", + source=config_entries.SOURCE_IMPORT, ) diff --git a/tests/components/smartthings/test_config_flow.py b/tests/components/smartthings/test_config_flow.py index d8e0f6ed784..15e045338af 100644 --- a/tests/components/smartthings/test_config_flow.py +++ b/tests/components/smartthings/test_config_flow.py @@ -6,7 +6,7 @@ from aiohttp import ClientResponseError from pysmartthings import APIResponseError from pysmartthings.installedapp import format_install_url -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.smartthings import smartapp from homeassistant.components.smartthings.const import ( CONF_APP_ID, @@ -31,7 +31,7 @@ async def test_import_shows_user_step(hass): """Test import source shows the user form.""" # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"} + DOMAIN, context={"source": config_entries.SOURCE_IMPORT} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -56,7 +56,7 @@ async def test_entry_created(hass, app, app_oauth_client, location, smartthings_ # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -127,7 +127,7 @@ async def test_entry_created_from_update_event( # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -198,7 +198,7 @@ async def test_entry_created_existing_app_new_oauth_client( # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -282,7 +282,7 @@ async def test_entry_created_existing_app_copies_oauth_client( # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -372,7 +372,7 @@ async def test_entry_created_with_cloudhook( # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -434,7 +434,7 @@ async def test_invalid_webhook_aborts(hass): {"external_url": "http://example.local:8123"}, ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "invalid_webhook_url" @@ -450,7 +450,7 @@ async def test_invalid_token_shows_error(hass): # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -487,7 +487,7 @@ async def test_unauthorized_token_shows_error(hass, smartthings_mock): # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -524,7 +524,7 @@ async def test_forbidden_token_shows_error(hass, smartthings_mock): # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -564,7 +564,7 @@ async def test_webhook_problem_shows_error(hass, smartthings_mock): # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -603,7 +603,7 @@ async def test_api_error_shows_error(hass, smartthings_mock): # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -641,7 +641,7 @@ async def test_unknown_response_error_shows_error(hass, smartthings_mock): # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -675,7 +675,7 @@ async def test_unknown_error_shows_error(hass, smartthings_mock): # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -717,7 +717,7 @@ async def test_no_available_locations_aborts( # Webhook confirmation shown result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" diff --git a/tests/components/smartthings/test_init.py b/tests/components/smartthings/test_init.py index eed1d5d26b1..e38c123829c 100644 --- a/tests/components/smartthings/test_init.py +++ b/tests/components/smartthings/test_init.py @@ -6,6 +6,7 @@ from aiohttp import ClientConnectionError, ClientResponseError from pysmartthings import InstalledAppStatus, OAuthToken import pytest +from homeassistant import config_entries from homeassistant.components import cloud, smartthings from homeassistant.components.smartthings.const import ( CONF_CLOUDHOOK_URL, @@ -41,7 +42,7 @@ async def test_migration_creates_new_flow(hass, smartthings_mock, config_entry): flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 assert flows[0]["handler"] == "smartthings" - assert flows[0]["context"] == {"source": "import"} + assert flows[0]["context"] == {"source": config_entries.SOURCE_IMPORT} async def test_unrecoverable_api_errors_create_new_flow( @@ -71,7 +72,7 @@ async def test_unrecoverable_api_errors_create_new_flow( flows = hass.config_entries.flow.async_progress() assert len(flows) == 1 assert flows[0]["handler"] == "smartthings" - assert flows[0]["context"] == {"source": "import"} + assert flows[0]["context"] == {"source": config_entries.SOURCE_IMPORT} hass.config_entries.flow.async_abort(flows[0]["flow_id"]) diff --git a/tests/components/somfy_mylink/test_config_flow.py b/tests/components/somfy_mylink/test_config_flow.py index 980a01f318c..59f6bd37407 100644 --- a/tests/components/somfy_mylink/test_config_flow.py +++ b/tests/components/somfy_mylink/test_config_flow.py @@ -465,7 +465,9 @@ async def test_already_configured_with_ignored(hass): """Test ignored entries do not break checking for existing entries.""" await setup.async_setup_component(hass, "persistent_notification", {}) - config_entry = MockConfigEntry(domain=DOMAIN, data={}, source="ignore") + config_entry = MockConfigEntry( + domain=DOMAIN, data={}, source=config_entries.SOURCE_IGNORE + ) config_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( diff --git a/tests/components/speedtestdotnet/test_config_flow.py b/tests/components/speedtestdotnet/test_config_flow.py index dee271d94a3..a7a65511ee5 100644 --- a/tests/components/speedtestdotnet/test_config_flow.py +++ b/tests/components/speedtestdotnet/test_config_flow.py @@ -5,7 +5,7 @@ from unittest.mock import patch import pytest from speedtest import NoMatchedServers -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import speedtestdotnet from homeassistant.components.speedtestdotnet.const import ( CONF_MANUAL, @@ -34,7 +34,7 @@ def mock_setup(): async def test_flow_works(hass, mock_setup): """Test user config.""" result = await hass.config_entries.flow.async_init( - speedtestdotnet.DOMAIN, context={"source": "user"} + speedtestdotnet.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -53,7 +53,7 @@ async def test_import_fails(hass, mock_setup): mock_api.return_value.get_servers.side_effect = NoMatchedServers result = await hass.config_entries.flow.async_init( speedtestdotnet.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={ CONF_SERVER_ID: "223", CONF_MANUAL: True, @@ -71,7 +71,7 @@ async def test_import_success(hass, mock_setup): with patch("speedtest.Speedtest"): result = await hass.config_entries.flow.async_init( speedtestdotnet.DOMAIN, - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={ CONF_SERVER_ID: "1", CONF_MANUAL: True, @@ -132,7 +132,7 @@ async def test_integration_already_configured(hass): ) entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - speedtestdotnet.DOMAIN, context={"source": "user"} + speedtestdotnet.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "single_instance_allowed" diff --git a/tests/components/spotify/test_config_flow.py b/tests/components/spotify/test_config_flow.py index 37a33ef66b2..cd0be3f7cc8 100644 --- a/tests/components/spotify/test_config_flow.py +++ b/tests/components/spotify/test_config_flow.py @@ -5,7 +5,7 @@ from spotipy import SpotifyException from homeassistant import data_entry_flow, setup from homeassistant.components.spotify.const import DOMAIN -from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF +from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER, SOURCE_ZEROCONF from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET from homeassistant.helpers import config_entry_oauth2_flow @@ -181,7 +181,7 @@ async def test_reauthentication( old_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=old_entry.data + DOMAIN, context={"source": SOURCE_REAUTH}, data=old_entry.data ) flows = hass.config_entries.flow.async_progress() @@ -246,7 +246,7 @@ async def test_reauth_account_mismatch( old_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=old_entry.data + DOMAIN, context={"source": SOURCE_REAUTH}, data=old_entry.data ) flows = hass.config_entries.flow.async_progress() diff --git a/tests/components/srp_energy/__init__.py b/tests/components/srp_energy/__init__.py index 5e2a4695d0b..e14f9186f44 100644 --- a/tests/components/srp_energy/__init__.py +++ b/tests/components/srp_energy/__init__.py @@ -23,7 +23,7 @@ async def init_integration( config=None, options=None, entry_id="1", - source="user", + source=config_entries.SOURCE_USER, side_effect=None, usage=None, ): diff --git a/tests/components/srp_energy/test_config_flow.py b/tests/components/srp_energy/test_config_flow.py index 5295d8cdb13..c8d458dfb82 100644 --- a/tests/components/srp_energy/test_config_flow.py +++ b/tests/components/srp_energy/test_config_flow.py @@ -11,7 +11,7 @@ async def test_form(hass): """Test user config.""" # First get the form result = await hass.config_entries.flow.async_init( - SRP_ENERGY_DOMAIN, context={"source": "user"} + SRP_ENERGY_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -40,7 +40,7 @@ async def test_form(hass): async def test_form_invalid_auth(hass): """Test user config with invalid auth.""" result = await hass.config_entries.flow.async_init( - SRP_ENERGY_DOMAIN, context={"source": "user"} + SRP_ENERGY_DOMAIN, context={"source": config_entries.SOURCE_USER} ) with patch( @@ -58,7 +58,7 @@ async def test_form_invalid_auth(hass): async def test_form_value_error(hass): """Test user config that throws a value error.""" result = await hass.config_entries.flow.async_init( - SRP_ENERGY_DOMAIN, context={"source": "user"} + SRP_ENERGY_DOMAIN, context={"source": config_entries.SOURCE_USER} ) with patch( @@ -76,7 +76,7 @@ async def test_form_value_error(hass): async def test_form_unknown_exception(hass): """Test user config that throws an unknown exception.""" result = await hass.config_entries.flow.async_init( - SRP_ENERGY_DOMAIN, context={"source": "user"} + SRP_ENERGY_DOMAIN, context={"source": config_entries.SOURCE_USER} ) with patch( @@ -106,7 +106,7 @@ async def test_integration_already_configured(hass): """Test integration is already configured.""" await init_integration(hass) result = await hass.config_entries.flow.async_init( - SRP_ENERGY_DOMAIN, context={"source": "user"} + SRP_ENERGY_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["reason"] == "single_instance_allowed" diff --git a/tests/components/ssdp/test_init.py b/tests/components/ssdp/test_init.py index f0f4a94e562..78b0f9e05b6 100644 --- a/tests/components/ssdp/test_init.py +++ b/tests/components/ssdp/test_init.py @@ -6,6 +6,7 @@ from unittest.mock import patch import aiohttp import pytest +from homeassistant import config_entries from homeassistant.components import ssdp from homeassistant.const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP from homeassistant.setup import async_setup_component @@ -39,7 +40,9 @@ async def test_scan_match_st(hass, caplog): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "ssdp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_SSDP + } assert mock_init.mock_calls[0][2]["data"] == { ssdp.ATTR_SSDP_ST: "mock-st", ssdp.ATTR_SSDP_LOCATION: None, @@ -88,7 +91,9 @@ async def test_scan_match_upnp_devicedesc(hass, aioclient_mock, key): assert len(aioclient_mock.mock_calls) == 1 assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "ssdp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_SSDP + } async def test_scan_not_all_present(hass, aioclient_mock): @@ -266,7 +271,9 @@ async def test_invalid_characters(hass, aioclient_mock): assert len(mock_init.mock_calls) == 1 assert mock_init.mock_calls[0][1][0] == "mock-domain" - assert mock_init.mock_calls[0][2]["context"] == {"source": "ssdp"} + assert mock_init.mock_calls[0][2]["context"] == { + "source": config_entries.SOURCE_SSDP + } assert mock_init.mock_calls[0][2]["data"] == { "ssdp_location": "http://1.1.1.1", "ssdp_st": "mock-st", diff --git a/tests/components/starline/test_config_flow.py b/tests/components/starline/test_config_flow.py index 7050376dbfe..4cd222dbc91 100644 --- a/tests/components/starline/test_config_flow.py +++ b/tests/components/starline/test_config_flow.py @@ -1,6 +1,7 @@ """Tests for StarLine config flow.""" import requests_mock +from homeassistant import config_entries from homeassistant.components.starline import config_flow TEST_APP_ID = "666" @@ -42,7 +43,7 @@ async def test_flow_works(hass): ) result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user"} + config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["step_id"] == "auth_app" @@ -76,7 +77,7 @@ async def test_step_auth_app_code_falls(hass): ) result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data={ config_flow.CONF_APP_ID: TEST_APP_ID, config_flow.CONF_APP_SECRET: TEST_APP_SECRET, @@ -99,7 +100,7 @@ async def test_step_auth_app_token_falls(hass): ) result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data={ config_flow.CONF_APP_ID: TEST_APP_ID, config_flow.CONF_APP_SECRET: TEST_APP_SECRET, diff --git a/tests/components/tado/test_config_flow.py b/tests/components/tado/test_config_flow.py index 90b7e87504c..77656f1c81f 100644 --- a/tests/components/tado/test_config_flow.py +++ b/tests/components/tado/test_config_flow.py @@ -125,7 +125,7 @@ async def test_form_homekit(hass): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, ) assert result["type"] == "form" @@ -144,7 +144,7 @@ async def test_form_homekit(hass): result = await hass.config_entries.flow.async_init( DOMAIN, - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"properties": {"id": "AA:BB:CC:DD:EE:FF"}}, ) assert result["type"] == "abort" diff --git a/tests/components/tasmota/test_config_flow.py b/tests/components/tasmota/test_config_flow.py index 469e5e29812..9f199f0aa66 100644 --- a/tests/components/tasmota/test_config_flow.py +++ b/tests/components/tasmota/test_config_flow.py @@ -1,4 +1,5 @@ """Test config flow.""" +from homeassistant import config_entries from homeassistant.components.mqtt.models import Message from tests.common import MockConfigEntry @@ -9,7 +10,7 @@ async def test_mqtt_abort_if_existing_entry(hass, mqtt_mock): MockConfigEntry(domain="tasmota").add_to_hass(hass) result = await hass.config_entries.flow.async_init( - "tasmota", context={"source": "mqtt"} + "tasmota", context={"source": config_entries.SOURCE_MQTT} ) assert result["type"] == "abort" @@ -20,7 +21,7 @@ async def test_mqtt_abort_invalid_topic(hass, mqtt_mock): """Check MQTT flow aborts if discovery topic is invalid.""" discovery_info = Message("", "", 0, False, subscribed_topic="custom_prefix/##") result = await hass.config_entries.flow.async_init( - "tasmota", context={"source": "mqtt"}, data=discovery_info + "tasmota", context={"source": config_entries.SOURCE_MQTT}, data=discovery_info ) assert result["type"] == "abort" assert result["reason"] == "invalid_discovery_info" @@ -30,7 +31,7 @@ async def test_mqtt_setup(hass, mqtt_mock) -> None: """Test we can finish a config flow through MQTT with custom prefix.""" discovery_info = Message("", "", 0, False, subscribed_topic="custom_prefix/123/#") result = await hass.config_entries.flow.async_init( - "tasmota", context={"source": "mqtt"}, data=discovery_info + "tasmota", context={"source": config_entries.SOURCE_MQTT}, data=discovery_info ) assert result["type"] == "form" @@ -45,7 +46,7 @@ async def test_mqtt_setup(hass, mqtt_mock) -> None: async def test_user_setup(hass, mqtt_mock): """Test we can finish a config flow.""" result = await hass.config_entries.flow.async_init( - "tasmota", context={"source": "user"} + "tasmota", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -60,7 +61,8 @@ async def test_user_setup(hass, mqtt_mock): async def test_user_setup_advanced(hass, mqtt_mock): """Test we can finish a config flow.""" result = await hass.config_entries.flow.async_init( - "tasmota", context={"source": "user", "show_advanced_options": True} + "tasmota", + context={"source": config_entries.SOURCE_USER, "show_advanced_options": True}, ) assert result["type"] == "form" @@ -77,7 +79,8 @@ async def test_user_setup_advanced(hass, mqtt_mock): async def test_user_setup_advanced_strip_wildcard(hass, mqtt_mock): """Test we can finish a config flow.""" result = await hass.config_entries.flow.async_init( - "tasmota", context={"source": "user", "show_advanced_options": True} + "tasmota", + context={"source": config_entries.SOURCE_USER, "show_advanced_options": True}, ) assert result["type"] == "form" @@ -94,7 +97,8 @@ async def test_user_setup_advanced_strip_wildcard(hass, mqtt_mock): async def test_user_setup_invalid_topic_prefix(hass, mqtt_mock): """Test abort on invalid discovery topic.""" result = await hass.config_entries.flow.async_init( - "tasmota", context={"source": "user", "show_advanced_options": True} + "tasmota", + context={"source": config_entries.SOURCE_USER, "show_advanced_options": True}, ) assert result["type"] == "form" @@ -111,7 +115,7 @@ async def test_user_single_instance(hass, mqtt_mock): MockConfigEntry(domain="tasmota").add_to_hass(hass) result = await hass.config_entries.flow.async_init( - "tasmota", context={"source": "user"} + "tasmota", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "abort" assert result["reason"] == "single_instance_allowed" diff --git a/tests/components/tibber/test_config_flow.py b/tests/components/tibber/test_config_flow.py index 479f314123a..6eaa52ac103 100644 --- a/tests/components/tibber/test_config_flow.py +++ b/tests/components/tibber/test_config_flow.py @@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch import pytest +from homeassistant import config_entries from homeassistant.components.tibber.const import DOMAIN from homeassistant.const import CONF_ACCESS_TOKEN @@ -19,7 +20,7 @@ def tibber_setup_fixture(): async def test_show_config_form(hass): """Test show configuration form.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" @@ -42,7 +43,7 @@ async def test_create_entry(hass): with patch("tibber.Tibber", return_value=tibber_mock): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "create_entry" @@ -65,7 +66,7 @@ async def test_flow_entry_already_exists(hass): with patch("tibber.Tibber.update_info", return_value=None): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"}, data=test_data + DOMAIN, context={"source": config_entries.SOURCE_USER}, data=test_data ) assert result["type"] == "abort" diff --git a/tests/components/totalconnect/test_config_flow.py b/tests/components/totalconnect/test_config_flow.py index 5d1723a835e..2f89beab0e0 100644 --- a/tests/components/totalconnect/test_config_flow.py +++ b/tests/components/totalconnect/test_config_flow.py @@ -3,7 +3,7 @@ from unittest.mock import patch from homeassistant import data_entry_flow from homeassistant.components.totalconnect.const import CONF_LOCATION, DOMAIN -from homeassistant.config_entries import SOURCE_USER +from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER from homeassistant.const import CONF_PASSWORD from .common import ( @@ -133,7 +133,7 @@ async def test_reauth(hass): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "reauth"}, data=entry.data + DOMAIN, context={"source": SOURCE_REAUTH}, data=entry.data ) assert result["step_id"] == "reauth_confirm" diff --git a/tests/components/traccar/test_init.py b/tests/components/traccar/test_init.py index f372358ea1d..5e995e10e92 100644 --- a/tests/components/traccar/test_init.py +++ b/tests/components/traccar/test_init.py @@ -3,7 +3,7 @@ from unittest.mock import patch import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import traccar, zone from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN from homeassistant.components.traccar import DOMAIN, TRACKER_UPDATE @@ -66,7 +66,7 @@ async def webhook_id_fixture(hass, client): {"external_url": "http://example.com"}, ) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "user"} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result diff --git a/tests/components/tradfri/test_config_flow.py b/tests/components/tradfri/test_config_flow.py index a155e8b383c..ca6380a9310 100644 --- a/tests/components/tradfri/test_config_flow.py +++ b/tests/components/tradfri/test_config_flow.py @@ -3,7 +3,7 @@ from unittest.mock import patch import pytest -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components.tradfri import config_flow from tests.common import MockConfigEntry @@ -23,7 +23,7 @@ async def test_user_connection_successful(hass, mock_auth, mock_entry_setup): mock_auth.side_effect = lambda hass, host, code: {"host": host, "gateway_id": "bla"} flow = await hass.config_entries.flow.async_init( - "tradfri", context={"source": "user"} + "tradfri", context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( @@ -45,7 +45,7 @@ async def test_user_connection_timeout(hass, mock_auth, mock_entry_setup): mock_auth.side_effect = config_flow.AuthError("timeout") flow = await hass.config_entries.flow.async_init( - "tradfri", context={"source": "user"} + "tradfri", context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( @@ -63,7 +63,7 @@ async def test_user_connection_bad_key(hass, mock_auth, mock_entry_setup): mock_auth.side_effect = config_flow.AuthError("invalid_security_code") flow = await hass.config_entries.flow.async_init( - "tradfri", context={"source": "user"} + "tradfri", context={"source": config_entries.SOURCE_USER} ) result = await hass.config_entries.flow.async_configure( @@ -82,7 +82,7 @@ async def test_discovery_connection(hass, mock_auth, mock_entry_setup): flow = await hass.config_entries.flow.async_init( "tradfri", - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"host": "123.123.123.123", "properties": {"id": "homekit-id"}}, ) @@ -112,7 +112,7 @@ async def test_import_connection(hass, mock_auth, mock_entry_setup): flow = await hass.config_entries.flow.async_init( "tradfri", - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={"host": "123.123.123.123", "import_groups": True}, ) @@ -143,7 +143,7 @@ async def test_import_connection_no_groups(hass, mock_auth, mock_entry_setup): flow = await hass.config_entries.flow.async_init( "tradfri", - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={"host": "123.123.123.123", "import_groups": False}, ) @@ -174,7 +174,7 @@ async def test_import_connection_legacy(hass, mock_gateway_info, mock_entry_setu result = await hass.config_entries.flow.async_init( "tradfri", - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={"host": "123.123.123.123", "key": "mock-key", "import_groups": True}, ) @@ -204,7 +204,7 @@ async def test_import_connection_legacy_no_groups( result = await hass.config_entries.flow.async_init( "tradfri", - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={"host": "123.123.123.123", "key": "mock-key", "import_groups": False}, ) @@ -230,7 +230,7 @@ async def test_discovery_duplicate_aborted(hass): flow = await hass.config_entries.flow.async_init( "tradfri", - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"host": "new-host", "properties": {"id": "homekit-id"}}, ) @@ -245,7 +245,9 @@ async def test_import_duplicate_aborted(hass): MockConfigEntry(domain="tradfri", data={"host": "some-host"}).add_to_hass(hass) flow = await hass.config_entries.flow.async_init( - "tradfri", context={"source": "import"}, data={"host": "some-host"} + "tradfri", + context={"source": config_entries.SOURCE_IMPORT}, + data={"host": "some-host"}, ) assert flow["type"] == data_entry_flow.RESULT_TYPE_ABORT @@ -256,7 +258,7 @@ async def test_duplicate_discovery(hass, mock_auth, mock_entry_setup): """Test a duplicate discovery in progress is ignored.""" result = await hass.config_entries.flow.async_init( "tradfri", - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"host": "123.123.123.123", "properties": {"id": "homekit-id"}}, ) @@ -264,7 +266,7 @@ async def test_duplicate_discovery(hass, mock_auth, mock_entry_setup): result2 = await hass.config_entries.flow.async_init( "tradfri", - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"host": "123.123.123.123", "properties": {"id": "homekit-id"}}, ) @@ -281,7 +283,7 @@ async def test_discovery_updates_unique_id(hass): flow = await hass.config_entries.flow.async_init( "tradfri", - context={"source": "homekit"}, + context={"source": config_entries.SOURCE_HOMEKIT}, data={"host": "some-host", "properties": {"id": "homekit-id"}}, ) diff --git a/tests/components/tradfri/test_init.py b/tests/components/tradfri/test_init.py index da9ae9da146..8e11ab06f34 100644 --- a/tests/components/tradfri/test_init.py +++ b/tests/components/tradfri/test_init.py @@ -1,6 +1,7 @@ """Tests for Tradfri setup.""" from unittest.mock import patch +from homeassistant import config_entries from homeassistant.components import tradfri from homeassistant.helpers import device_registry as dr from homeassistant.setup import async_setup_component @@ -34,7 +35,7 @@ async def test_config_yaml_host_imported(hass): progress = hass.config_entries.flow.async_progress() assert len(progress) == 1 assert progress[0]["handler"] == "tradfri" - assert progress[0]["context"] == {"source": "import"} + assert progress[0]["context"] == {"source": config_entries.SOURCE_IMPORT} async def test_config_json_host_not_imported(hass): @@ -71,7 +72,7 @@ async def test_config_json_host_imported( config_entry = mock_entry_setup.mock_calls[0][1][1] assert config_entry.domain == "tradfri" - assert config_entry.source == "import" + assert config_entry.source == config_entries.SOURCE_IMPORT assert config_entry.title == "mock-host" diff --git a/tests/components/transmission/test_config_flow.py b/tests/components/transmission/test_config_flow.py index 2982d363da9..79b341e4504 100644 --- a/tests/components/transmission/test_config_flow.py +++ b/tests/components/transmission/test_config_flow.py @@ -5,7 +5,7 @@ from unittest.mock import patch import pytest from transmissionrpc.error import TransmissionError -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import transmission from homeassistant.components.transmission import config_flow from homeassistant.components.transmission.const import ( @@ -96,7 +96,7 @@ def init_config_flow(hass): async def test_flow_user_config(hass, api): """Test user config.""" result = await hass.config_entries.flow.async_init( - transmission.DOMAIN, context={"source": "user"} + transmission.DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user" @@ -106,7 +106,7 @@ async def test_flow_required_fields(hass, api): """Test with required fields only.""" result = await hass.config_entries.flow.async_init( transmission.DOMAIN, - context={"source": "user"}, + context={"source": config_entries.SOURCE_USER}, data={CONF_NAME: NAME, CONF_HOST: HOST, CONF_PORT: PORT}, ) @@ -120,7 +120,9 @@ async def test_flow_required_fields(hass, api): async def test_flow_all_provided(hass, api): """Test with all provided.""" result = await hass.config_entries.flow.async_init( - transmission.DOMAIN, context={"source": "user"}, data=MOCK_ENTRY + transmission.DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=MOCK_ENTRY, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY @@ -208,7 +210,9 @@ async def test_host_already_configured(hass, api): mock_entry_unique_name = MOCK_ENTRY.copy() mock_entry_unique_name[CONF_NAME] = "Transmission 1" result = await hass.config_entries.flow.async_init( - transmission.DOMAIN, context={"source": "user"}, data=mock_entry_unique_name + transmission.DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=mock_entry_unique_name, ) assert result["type"] == "abort" assert result["reason"] == "already_configured" @@ -217,7 +221,9 @@ async def test_host_already_configured(hass, api): mock_entry_unique_port[CONF_PORT] = 9092 mock_entry_unique_port[CONF_NAME] = "Transmission 2" result = await hass.config_entries.flow.async_init( - transmission.DOMAIN, context={"source": "user"}, data=mock_entry_unique_port + transmission.DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=mock_entry_unique_port, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY @@ -225,7 +231,9 @@ async def test_host_already_configured(hass, api): mock_entry_unique_host[CONF_HOST] = "192.168.1.101" mock_entry_unique_host[CONF_NAME] = "Transmission 3" result = await hass.config_entries.flow.async_init( - transmission.DOMAIN, context={"source": "user"}, data=mock_entry_unique_host + transmission.DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=mock_entry_unique_host, ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY @@ -242,7 +250,9 @@ async def test_name_already_configured(hass, api): mock_entry = MOCK_ENTRY.copy() mock_entry[CONF_HOST] = "0.0.0.0" result = await hass.config_entries.flow.async_init( - transmission.DOMAIN, context={"source": "user"}, data=mock_entry + transmission.DOMAIN, + context={"source": config_entries.SOURCE_USER}, + data=mock_entry, ) assert result["type"] == "form" diff --git a/tests/components/twilio/test_init.py b/tests/components/twilio/test_init.py index 580e5f83ebf..3529159eae1 100644 --- a/tests/components/twilio/test_init.py +++ b/tests/components/twilio/test_init.py @@ -1,5 +1,5 @@ """Test the init file of Twilio.""" -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.components import twilio from homeassistant.config import async_process_ha_core_config from homeassistant.core import callback @@ -12,7 +12,7 @@ async def test_config_flow_registers_webhook(hass, aiohttp_client): {"internal_url": "http://example.local:8123"}, ) result = await hass.config_entries.flow.async_init( - "twilio", context={"source": "user"} + "twilio", context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result diff --git a/tests/components/unifi/test_config_flow.py b/tests/components/unifi/test_config_flow.py index 43d14981bbb..1967369e22b 100644 --- a/tests/components/unifi/test_config_flow.py +++ b/tests/components/unifi/test_config_flow.py @@ -91,7 +91,7 @@ async def test_flow_works(hass, aioclient_mock, mock_discovery): """Test config flow.""" mock_discovery.return_value = "1" result = await hass.config_entries.flow.async_init( - UNIFI_DOMAIN, context={"source": "user"} + UNIFI_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -157,7 +157,7 @@ async def test_flow_works(hass, aioclient_mock, mock_discovery): async def test_flow_works_negative_discovery(hass, aioclient_mock, mock_discovery): """Test config flow with a negative outcome of async_discovery_unifi.""" result = await hass.config_entries.flow.async_init( - UNIFI_DOMAIN, context={"source": "user"} + UNIFI_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -174,7 +174,7 @@ async def test_flow_works_negative_discovery(hass, aioclient_mock, mock_discover async def test_flow_multiple_sites(hass, aioclient_mock): """Test config flow works when finding multiple sites.""" result = await hass.config_entries.flow.async_init( - UNIFI_DOMAIN, context={"source": "user"} + UNIFI_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -222,7 +222,7 @@ async def test_flow_raise_already_configured(hass, aioclient_mock): await setup_unifi_integration(hass, aioclient_mock) result = await hass.config_entries.flow.async_init( - UNIFI_DOMAIN, context={"source": "user"} + UNIFI_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -277,7 +277,7 @@ async def test_flow_aborts_configuration_updated(hass, aioclient_mock): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - UNIFI_DOMAIN, context={"source": "user"} + UNIFI_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -321,7 +321,7 @@ async def test_flow_aborts_configuration_updated(hass, aioclient_mock): async def test_flow_fails_user_credentials_faulty(hass, aioclient_mock): """Test config flow.""" result = await hass.config_entries.flow.async_init( - UNIFI_DOMAIN, context={"source": "user"} + UNIFI_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -348,7 +348,7 @@ async def test_flow_fails_user_credentials_faulty(hass, aioclient_mock): async def test_flow_fails_controller_unavailable(hass, aioclient_mock): """Test config flow.""" result = await hass.config_entries.flow.async_init( - UNIFI_DOMAIN, context={"source": "user"} + UNIFI_DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM diff --git a/tests/components/volumio/test_config_flow.py b/tests/components/volumio/test_config_flow.py index a0d3fc85ee3..fed967f9ffc 100644 --- a/tests/components/volumio/test_config_flow.py +++ b/tests/components/volumio/test_config_flow.py @@ -170,7 +170,7 @@ async def test_discovery(hass): """Test discovery flow works.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, data=TEST_DISCOVERY ) with patch( @@ -200,7 +200,7 @@ async def test_discovery_cannot_connect(hass): """Test discovery aborts if cannot connect.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, data=TEST_DISCOVERY ) with patch( @@ -219,13 +219,13 @@ async def test_discovery_cannot_connect(hass): async def test_discovery_duplicate_data(hass): """Test discovery aborts if same mDNS packet arrives.""" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, data=TEST_DISCOVERY ) assert result["type"] == "form" assert result["step_id"] == "discovery_confirm" result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, context={"source": config_entries.SOURCE_ZEROCONF}, data=TEST_DISCOVERY ) assert result["type"] == "abort" assert result["reason"] == "already_in_progress" @@ -252,7 +252,9 @@ async def test_discovery_updates_unique_id(hass): return_value=True, ) as mock_setup_entry: result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "zeroconf"}, data=TEST_DISCOVERY + DOMAIN, + context={"source": config_entries.SOURCE_ZEROCONF}, + data=TEST_DISCOVERY, ) await hass.async_block_till_done() diff --git a/tests/components/withings/test_config_flow.py b/tests/components/withings/test_config_flow.py index 4cbada948f4..618dd19f80b 100644 --- a/tests/components/withings/test_config_flow.py +++ b/tests/components/withings/test_config_flow.py @@ -1,6 +1,7 @@ """Tests for config flow.""" from aiohttp.test_utils import TestClient +from homeassistant import config_entries from homeassistant.components.withings import const from homeassistant.config import async_process_ha_core_config from homeassistant.const import ( @@ -58,7 +59,8 @@ async def test_config_reauth_profile( config_entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - const.DOMAIN, context={"source": "reauth", "profile": "person0"} + const.DOMAIN, + context={"source": config_entries.SOURCE_REAUTH, "profile": "person0"}, ) assert result assert result["type"] == "form" diff --git a/tests/components/zha/test_config_flow.py b/tests/components/zha/test_config_flow.py index 127c5518a41..16747980b15 100644 --- a/tests/components/zha/test_config_flow.py +++ b/tests/components/zha/test_config_flow.py @@ -10,7 +10,7 @@ import zigpy.config from homeassistant import setup from homeassistant.components.zha import config_flow from homeassistant.components.zha.core.const import CONF_RADIO_TYPE, DOMAIN, RadioType -from homeassistant.config_entries import SOURCE_USER +from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF from homeassistant.const import CONF_SOURCE from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM @@ -39,7 +39,7 @@ async def test_discovery(detect_mock, hass): "properties": {"name": "tube_123456"}, } flow = await hass.config_entries.flow.async_init( - "zha", context={"source": "zeroconf"}, data=service_info + "zha", context={"source": SOURCE_ZEROCONF}, data=service_info ) result = await hass.config_entries.flow.async_configure( flow["flow_id"], user_input={} @@ -71,7 +71,7 @@ async def test_discovery_already_setup(detect_mock, hass): MockConfigEntry(domain=DOMAIN, data={"usb_path": "/dev/ttyUSB1"}).add_to_hass(hass) result = await hass.config_entries.flow.async_init( - "zha", context={"source": "zeroconf"}, data=service_info + "zha", context={"source": SOURCE_ZEROCONF}, data=service_info ) await hass.async_block_till_done() diff --git a/tests/components/zwave/test_websocket_api.py b/tests/components/zwave/test_websocket_api.py index 9727906709f..2e37ed47fce 100644 --- a/tests/components/zwave/test_websocket_api.py +++ b/tests/components/zwave/test_websocket_api.py @@ -1,6 +1,7 @@ """Test Z-Wave Websocket API.""" from unittest.mock import call, patch +from homeassistant import config_entries from homeassistant.bootstrap import async_setup_component from homeassistant.components.zwave.const import ( CONF_AUTOHEAL, @@ -83,6 +84,6 @@ async def test_zwave_ozw_migration_api(hass, mock_openzwave, hass_ws_client): assert result["flow_id"] == "mock_flow_id" assert async_init.call_args == call( "ozw", - context={"source": "import"}, + context={"source": config_entries.SOURCE_IMPORT}, data={"usb_path": "/dev/zwave", "network_key": NETWORK_KEY}, ) diff --git a/tests/helpers/test_config_entry_flow.py b/tests/helpers/test_config_entry_flow.py index b3233556957..edee75fe240 100644 --- a/tests/helpers/test_config_entry_flow.py +++ b/tests/helpers/test_config_entry_flow.py @@ -91,7 +91,16 @@ async def test_user_has_confirmation(hass, discovery_flow_conf): assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY -@pytest.mark.parametrize("source", ["discovery", "mqtt", "ssdp", "zeroconf", "dhcp"]) +@pytest.mark.parametrize( + "source", + [ + config_entries.SOURCE_DISCOVERY, + config_entries.SOURCE_MQTT, + config_entries.SOURCE_SSDP, + config_entries.SOURCE_ZEROCONF, + config_entries.SOURCE_DHCP, + ], +) async def test_discovery_single_instance(hass, discovery_flow_conf, source): """Test we not allow duplicates.""" flow = config_entries.HANDLERS["test"]() @@ -105,7 +114,16 @@ async def test_discovery_single_instance(hass, discovery_flow_conf, source): assert result["reason"] == "single_instance_allowed" -@pytest.mark.parametrize("source", ["discovery", "mqtt", "ssdp", "zeroconf", "dhcp"]) +@pytest.mark.parametrize( + "source", + [ + config_entries.SOURCE_DISCOVERY, + config_entries.SOURCE_MQTT, + config_entries.SOURCE_SSDP, + config_entries.SOURCE_ZEROCONF, + config_entries.SOURCE_DHCP, + ], +) async def test_discovery_confirmation(hass, discovery_flow_conf, source): """Test we ask for confirmation via discovery.""" flow = config_entries.HANDLERS["test"]() diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 4de62cc0cfc..741953f552b 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -2068,7 +2068,7 @@ async def test_unignore_create_entry(hass, manager): # But after a 'tick' the unignore step has run and we can see a config entry. await hass.async_block_till_done() entry = hass.config_entries.async_entries("comp")[0] - assert entry.source == "unignore" + assert entry.source == config_entries.SOURCE_UNIGNORE assert entry.unique_id == "mock-unique-id" assert entry.title == "yo" diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index 47b21793656..34b07a2a871 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -5,7 +5,7 @@ from unittest.mock import patch import pytest import voluptuous as vol -from homeassistant import data_entry_flow +from homeassistant import config_entries, data_entry_flow from homeassistant.util.decorator import Registry from tests.common import async_capture_events @@ -182,7 +182,9 @@ async def test_discovery_init_flow(manager): data = {"id": "hello", "token": "secret"} - await manager.async_init("test", context={"source": "discovery"}, data=data) + await manager.async_init( + "test", context={"source": config_entries.SOURCE_DISCOVERY}, data=data + ) assert len(manager.async_progress()) == 0 assert len(manager.mock_created_entries) == 1 @@ -191,7 +193,7 @@ async def test_discovery_init_flow(manager): assert entry["handler"] == "test" assert entry["title"] == "hello" assert entry["data"] == data - assert entry["source"] == "discovery" + assert entry["source"] == config_entries.SOURCE_DISCOVERY async def test_finish_callback_change_result_type(hass):