diff --git a/homeassistant/components/vallox/__init__.py b/homeassistant/components/vallox/__init__.py index 579accc8090..6f8d00eb48c 100644 --- a/homeassistant/components/vallox/__init__.py +++ b/homeassistant/components/vallox/__init__.py @@ -17,12 +17,12 @@ from vallox_websocket_api.vallox import ( ) import voluptuous as vol -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry +from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_NAME, Platform from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity import DeviceInfo -from homeassistant.helpers.typing import ConfigType, StateType +from homeassistant.helpers.typing import StateType from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -159,22 +159,6 @@ class ValloxDataUpdateCoordinator(DataUpdateCoordinator[ValloxState]): """The DataUpdateCoordinator for Vallox.""" -async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the integration from configuration.yaml (DEPRECATED).""" - if DOMAIN not in config: - return True - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data=config[DOMAIN], - ) - ) - - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up the client and boot the platforms.""" host = entry.data[CONF_HOST] diff --git a/homeassistant/components/vallox/config_flow.py b/homeassistant/components/vallox/config_flow.py index b9d29b17689..cfc5993797d 100644 --- a/homeassistant/components/vallox/config_flow.py +++ b/homeassistant/components/vallox/config_flow.py @@ -40,38 +40,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): VERSION = 1 - async def async_step_import(self, data: dict[str, Any]) -> FlowResult: - """Handle import from YAML.""" - # We need to use the name from the YAML configuration to avoid - # breaking existing entity IDs. - name = data.get(CONF_NAME, DEFAULT_NAME) - host = data[CONF_HOST] - - self._async_abort_entries_match({CONF_HOST: host}) - - reason = None - try: - await validate_host(self.hass, host) - except InvalidHost: - _LOGGER.error("An invalid host is configured for Vallox: %s", host) - reason = "invalid_host" - except ValloxApiException: - _LOGGER.error("Cannot connect to Vallox host %s", host) - reason = "cannot_connect" - except Exception: # pylint: disable=broad-except - _LOGGER.exception("Unexpected exception") - reason = "unknown" - else: - return self.async_create_entry( - title=name, - data={ - **data, - CONF_NAME: name, - }, - ) - - return self.async_abort(reason=reason) - async def async_step_user( self, user_input: dict[str, Any] | None = None ) -> FlowResult: diff --git a/tests/components/vallox/test_config_flow.py b/tests/components/vallox/test_config_flow.py index 39de026bdbb..2bf29837d9d 100644 --- a/tests/components/vallox/test_config_flow.py +++ b/tests/components/vallox/test_config_flow.py @@ -4,7 +4,7 @@ from unittest.mock import patch from vallox_websocket_api import ValloxApiException, ValloxWebsocketException from homeassistant.components.vallox.const import DOMAIN -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_USER from homeassistant.const import CONF_HOST, CONF_NAME from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -150,145 +150,3 @@ async def test_form_already_configured(hass: HomeAssistant) -> None: assert result["type"] == FlowResultType.ABORT assert result["reason"] == "already_configured" - - -async def test_import_with_custom_name(hass: HomeAssistant) -> None: - """Test that import is handled.""" - name = "Vallox 90 MV" - - with patch( - "homeassistant.components.vallox.config_flow.Vallox.get_info", - return_value=None, - ), patch( - "homeassistant.components.vallox.async_setup_entry", - return_value=True, - ) as mock_setup_entry: - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={"host": "1.2.3.4", "name": name}, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.CREATE_ENTRY - assert result["title"] == name - assert result["data"] == {"host": "1.2.3.4", "name": "Vallox 90 MV"} - assert len(mock_setup_entry.mock_calls) == 1 - - -async def test_import_without_custom_name(hass: HomeAssistant) -> None: - """Test that import is handled.""" - with patch( - "homeassistant.components.vallox.config_flow.Vallox.get_info", - return_value=None, - ), patch( - "homeassistant.components.vallox.async_setup_entry", - return_value=True, - ) as mock_setup_entry: - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={"host": "1.2.3.4"}, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.CREATE_ENTRY - assert result["title"] == "Vallox" - assert result["data"] == {"host": "1.2.3.4", "name": "Vallox"} - assert len(mock_setup_entry.mock_calls) == 1 - - -async def test_import_invalid_ip(hass: HomeAssistant) -> None: - """Test that invalid IP error is handled during import.""" - name = "Vallox 90 MV" - - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={"host": "vallox90mv.host.name", "name": name}, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.ABORT - assert result["reason"] == "invalid_host" - - -async def test_import_already_configured(hass: HomeAssistant) -> None: - """Test that an already configured Vallox device is handled during import.""" - name = "Vallox 145 MV" - - mock_entry = MockConfigEntry( - domain=DOMAIN, - data={ - CONF_HOST: "40.10.20.30", - CONF_NAME: "Vallox 145 MV", - }, - ) - mock_entry.add_to_hass(hass) - - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={"host": "40.10.20.30", "name": name}, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.ABORT - assert result["reason"] == "already_configured" - - -async def test_import_cannot_connect_os_error(hass: HomeAssistant) -> None: - """Test that cannot connect error is handled.""" - name = "Vallox 90 MV" - - with patch( - "homeassistant.components.vallox.config_flow.Vallox.get_info", - side_effect=ValloxWebsocketException, - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={"host": "1.2.3.4", "name": name}, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.ABORT - assert result["reason"] == "cannot_connect" - - -async def test_import_cannot_connect_vallox_api_exception(hass: HomeAssistant) -> None: - """Test that cannot connect error is handled.""" - name = "Vallox 90 MV" - - with patch( - "homeassistant.components.vallox.config_flow.Vallox.get_info", - side_effect=ValloxApiException, - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={"host": "5.6.3.1", "name": name}, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.ABORT - assert result["reason"] == "cannot_connect" - - -async def test_import_unknown_exception(hass: HomeAssistant) -> None: - """Test that unknown exceptions are handled.""" - name = "Vallox 245 MV" - - with patch( - "homeassistant.components.vallox.config_flow.Vallox.get_info", - side_effect=Exception, - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={"host": "1.2.3.4", "name": name}, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.ABORT - assert result["reason"] == "unknown"