diff --git a/homeassistant/components/doorbird/__init__.py b/homeassistant/components/doorbird/__init__.py index 9a21c1b3439..30c2613f0d5 100644 --- a/homeassistant/components/doorbird/__init__.py +++ b/homeassistant/components/doorbird/__init__.py @@ -7,10 +7,9 @@ import requests import voluptuous as vol from homeassistant.components.http import HomeAssistantView -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ATTR_ENTITY_ID, - CONF_DEVICES, CONF_HOST, CONF_NAME, CONF_PASSWORD, @@ -56,17 +55,7 @@ DEVICE_SCHEMA = vol.Schema( } ) -CONFIG_SCHEMA = vol.Schema( - vol.All( - cv.deprecated(DOMAIN), - { - DOMAIN: vol.Schema( - {vol.Required(CONF_DEVICES): vol.All(cv.ensure_list, [DEVICE_SCHEMA])} - ) - }, - ), - extra=vol.ALLOW_EXTRA, -) +CONFIG_SCHEMA = cv.deprecated(DOMAIN) async def async_setup(hass: HomeAssistant, config: dict): @@ -76,17 +65,6 @@ async def async_setup(hass: HomeAssistant, config: dict): # Provide an endpoint for the doorstations to call to trigger events hass.http.register_view(DoorBirdRequestView) - if DOMAIN in config and CONF_DEVICES in config[DOMAIN]: - for index, doorstation_config in enumerate(config[DOMAIN][CONF_DEVICES]): - if CONF_NAME not in doorstation_config: - doorstation_config[CONF_NAME] = f"DoorBird {index + 1}" - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=doorstation_config - ) - ) - def _reset_device_favorites_handler(event): """Handle clearing favorites on device.""" token = event.data.get("token") diff --git a/homeassistant/components/doorbird/config_flow.py b/homeassistant/components/doorbird/config_flow.py index 2558d1a3869..5d207fbbbce 100644 --- a/homeassistant/components/doorbird/config_flow.py +++ b/homeassistant/components/doorbird/config_flow.py @@ -124,18 +124,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): return await self.async_step_user() - async def async_step_import(self, user_input): - """Handle import.""" - if user_input: - info, errors = await self._async_validate_or_error(user_input) - if not errors: - await self.async_set_unique_id( - info["mac_addr"], raise_on_progress=False - ) - self._abort_if_unique_id_configured() - return self.async_create_entry(title=info["title"], data=user_input) - return await self.async_step_user(user_input) - async def _async_validate_or_error(self, user_input): """Validate doorbird or error.""" errors = {} diff --git a/tests/components/doorbird/test_config_flow.py b/tests/components/doorbird/test_config_flow.py index 9fa9752dc65..915955da652 100644 --- a/tests/components/doorbird/test_config_flow.py +++ b/tests/components/doorbird/test_config_flow.py @@ -5,7 +5,6 @@ import pytest import requests from homeassistant import config_entries, data_entry_flow, setup -from homeassistant.components.doorbird import CONF_CUSTOM_URL, CONF_TOKEN from homeassistant.components.doorbird.const import CONF_EVENTS, DOMAIN from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME @@ -76,124 +75,6 @@ async def test_user_form(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_form_import(hass): - """Test we get the form with import source.""" - await setup.async_setup_component(hass, "persistent_notification", {}) - - import_config = VALID_CONFIG.copy() - import_config[CONF_EVENTS] = ["event1", "event2", "event3"] - import_config[CONF_TOKEN] = "imported_token" - import_config[ - CONF_CUSTOM_URL - ] = "http://legacy.custom.url/should/only/come/in/from/yaml" - - doorbirdapi = _get_mock_doorbirdapi_return_values( - ready=[True], info={"WIFI_MAC_ADDR": "macaddr"} - ) - with patch( - "homeassistant.components.doorbird.config_flow.DoorBird", - return_value=doorbirdapi, - ), patch("homeassistant.components.logbook.async_setup", return_value=True), patch( - "homeassistant.components.doorbird.async_setup", return_value=True - ) as mock_setup, patch( - "homeassistant.components.doorbird.async_setup_entry", - return_value=True, - ) as mock_setup_entry: - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=import_config, - ) - await hass.async_block_till_done() - - assert result["type"] == "create_entry" - assert result["title"] == "1.2.3.4" - assert result["data"] == { - "host": "1.2.3.4", - "name": "mydoorbird", - "password": "password", - "username": "friend", - "events": ["event1", "event2", "event3"], - "token": "imported_token", - # This will go away once we convert to cloud hooks - "hass_url_override": "http://legacy.custom.url/should/only/come/in/from/yaml", - } - # It is not possible to import options at this time - # so they end up in the config entry data and are - # used a fallback when they are not in options - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 - - -async def test_form_import_with_zeroconf_already_discovered(hass): - """Test we get the form with import source.""" - await setup.async_setup_component(hass, "persistent_notification", {}) - - doorbirdapi = _get_mock_doorbirdapi_return_values( - ready=[True], info={"WIFI_MAC_ADDR": "1CCAE3DOORBIRD"} - ) - # Running the zeroconf init will make the unique id - # in progress - with patch( - "homeassistant.components.doorbird.config_flow.DoorBird", - return_value=doorbirdapi, - ): - zero_conf = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_ZEROCONF}, - data={ - "properties": {"macaddress": "1CCAE3DOORBIRD"}, - "name": "Doorstation - abc123._axis-video._tcp.local.", - "host": "192.168.1.5", - }, - ) - await hass.async_block_till_done() - assert zero_conf["type"] == data_entry_flow.RESULT_TYPE_FORM - assert zero_conf["step_id"] == "user" - assert zero_conf["errors"] == {} - - import_config = VALID_CONFIG.copy() - import_config[CONF_EVENTS] = ["event1", "event2", "event3"] - import_config[CONF_TOKEN] = "imported_token" - import_config[ - CONF_CUSTOM_URL - ] = "http://legacy.custom.url/should/only/come/in/from/yaml" - - with patch( - "homeassistant.components.doorbird.config_flow.DoorBird", - return_value=doorbirdapi, - ), patch("homeassistant.components.logbook.async_setup", return_value=True), patch( - "homeassistant.components.doorbird.async_setup", return_value=True - ) as mock_setup, patch( - "homeassistant.components.doorbird.async_setup_entry", - return_value=True, - ) as mock_setup_entry: - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=import_config, - ) - await hass.async_block_till_done() - - assert result["type"] == "create_entry" - assert result["title"] == "1.2.3.4" - assert result["data"] == { - "host": "1.2.3.4", - "name": "mydoorbird", - "password": "password", - "username": "friend", - "events": ["event1", "event2", "event3"], - "token": "imported_token", - # This will go away once we convert to cloud hooks - "hass_url_override": "http://legacy.custom.url/should/only/come/in/from/yaml", - } - # It is not possible to import options at this time - # so they end up in the config entry data and are - # used a fallback when they are not in options - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 - - async def test_form_zeroconf_wrong_oui(hass): """Test we abort when we get the wrong OUI via zeroconf.""" await setup.async_setup_component(hass, "persistent_notification", {})