diff --git a/homeassistant/components/tado/config_flow.py b/homeassistant/components/tado/config_flow.py index e52b87796f7..d27a8c4b10b 100644 --- a/homeassistant/components/tado/config_flow.py +++ b/homeassistant/components/tado/config_flow.py @@ -23,7 +23,6 @@ from homeassistant.exceptions import HomeAssistantError from .const import ( CONF_FALLBACK, - CONF_HOME_ID, CONST_OVERLAY_TADO_DEFAULT, CONST_OVERLAY_TADO_OPTIONS, DOMAIN, @@ -117,49 +116,6 @@ class TadoConfigFlow(ConfigFlow, domain=DOMAIN): self._abort_if_unique_id_configured() return await self.async_step_user() - async def async_step_import( - self, import_config: dict[str, Any] - ) -> ConfigFlowResult: - """Import a config entry from configuration.yaml.""" - _LOGGER.debug("Importing Tado from configuration.yaml") - username = import_config[CONF_USERNAME] - password = import_config[CONF_PASSWORD] - imported_home_id = import_config[CONF_HOME_ID] - - self._async_abort_entries_match( - { - CONF_USERNAME: username, - CONF_PASSWORD: password, - CONF_HOME_ID: imported_home_id, - } - ) - - try: - validate_result = await validate_input( - self.hass, - { - CONF_USERNAME: username, - CONF_PASSWORD: password, - }, - ) - except HomeAssistantError: - return self.async_abort(reason="import_failed") - except PyTado.exceptions.TadoWrongCredentialsException: - return self.async_abort(reason="import_failed_invalid_auth") - - home_id = validate_result[UNIQUE_ID] - await self.async_set_unique_id(home_id) - self._abort_if_unique_id_configured() - - return self.async_create_entry( - title=import_config[CONF_USERNAME], - data={ - CONF_USERNAME: username, - CONF_PASSWORD: password, - CONF_HOME_ID: home_id, - }, - ) - async def async_step_reconfigure( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: diff --git a/homeassistant/components/tado/device_tracker.py b/homeassistant/components/tado/device_tracker.py index d3996db7faf..1caea1b3103 100644 --- a/homeassistant/components/tado/device_tracker.py +++ b/homeassistant/components/tado/device_tracker.py @@ -4,74 +4,23 @@ from __future__ import annotations import logging -import voluptuous as vol - from homeassistant.components.device_tracker import ( DOMAIN as DEVICE_TRACKER_DOMAIN, - PLATFORM_SCHEMA as BASE_PLATFORM_SCHEMA, - DeviceScanner, SourceType, TrackerEntity, ) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, STATE_HOME, STATE_NOT_HOME +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import STATE_HOME, STATE_NOT_HOME from homeassistant.core import HomeAssistant, callback -from homeassistant.data_entry_flow import FlowResultType from homeassistant.helpers import entity_registry as er -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue -from homeassistant.helpers.typing import ConfigType from . import TadoConnector -from .const import CONF_HOME_ID, DATA, DOMAIN, SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED +from .const import DATA, DOMAIN, SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED _LOGGER = logging.getLogger(__name__) -PLATFORM_SCHEMA = BASE_PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_USERNAME): cv.string, - vol.Required(CONF_PASSWORD): cv.string, - vol.Optional(CONF_HOME_ID): cv.string, - } -) - - -async def async_get_scanner( - hass: HomeAssistant, config: ConfigType -) -> DeviceScanner | None: - """Configure the Tado device scanner.""" - device_config = config["device_tracker"] - import_result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={ - CONF_USERNAME: device_config[CONF_USERNAME], - CONF_PASSWORD: device_config[CONF_PASSWORD], - CONF_HOME_ID: device_config.get(CONF_HOME_ID), - }, - ) - - translation_key = "deprecated_yaml_import_device_tracker" - if import_result.get("type") == FlowResultType.ABORT: - translation_key = "import_aborted" - if import_result.get("reason") == "import_failed": - translation_key = "import_failed" - if import_result.get("reason") == "import_failed_invalid_auth": - translation_key = "import_failed_invalid_auth" - - async_create_issue( - hass, - DOMAIN, - "deprecated_yaml_import_device_tracker", - breaks_in_ha_version="2024.7.0", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key=translation_key, - ) - return None - async def async_setup_entry( hass: HomeAssistant, diff --git a/homeassistant/components/tado/strings.json b/homeassistant/components/tado/strings.json index d992befe112..ab903dafb5b 100644 --- a/homeassistant/components/tado/strings.json +++ b/homeassistant/components/tado/strings.json @@ -150,22 +150,6 @@ } }, "issues": { - "deprecated_yaml_import_device_tracker": { - "title": "Tado YAML device tracker configuration imported", - "description": "Configuring the Tado Device Tracker using YAML is being removed.\nRemove the YAML device tracker configuration and restart Home Assistant." - }, - "import_aborted": { - "title": "Import aborted", - "description": "Configuring the Tado Device Tracker using YAML is being removed.\n The import was aborted, due to an existing config entry being the same as the data being imported in the YAML. Remove the YAML device tracker configuration and restart Home Assistant. Please use the UI to configure Tado." - }, - "import_failed": { - "title": "Failed to import", - "description": "Failed to import the configuration for the Tado Device Tracker. Please use the UI to configure Tado. Don't forget to delete the YAML configuration." - }, - "import_failed_invalid_auth": { - "title": "Failed to import, invalid credentials", - "description": "Failed to import the configuration for the Tado Device Tracker, due to invalid credentials. Please fix the YAML configuration and restart Home Assistant. Alternatively you can use the UI to configure Tado. Don't forget to delete the YAML configuration, once the import is successful." - }, "water_heater_fallback": { "title": "Tado Water Heater entities now support fallback options", "description": "Due to added support for water heaters entities, these entities may use different overlay. Please configure integration entity and tado app water heater zone overlay options." diff --git a/tests/components/tado/test_config_flow.py b/tests/components/tado/test_config_flow.py index a8883f47fe2..4f5f4180fb5 100644 --- a/tests/components/tado/test_config_flow.py +++ b/tests/components/tado/test_config_flow.py @@ -271,147 +271,6 @@ async def test_form_homekit(hass: HomeAssistant) -> None: assert result["type"] is FlowResultType.ABORT -async def test_import_step(hass: HomeAssistant) -> None: - """Test import step.""" - mock_tado_api = _get_mock_tado_api(getMe={"homes": [{"id": 1, "name": "myhome"}]}) - - with ( - patch( - "homeassistant.components.tado.config_flow.Tado", - return_value=mock_tado_api, - ), - patch( - "homeassistant.components.tado.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={ - "username": "test-username", - "password": "test-password", - "home_id": 1, - }, - ) - await hass.async_block_till_done() - - assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["data"] == { - "username": "test-username", - "password": "test-password", - "home_id": "1", - } - assert mock_setup_entry.call_count == 1 - - -async def test_import_step_existing_entry(hass: HomeAssistant) -> None: - """Test import step with existing entry.""" - entry = MockConfigEntry( - domain=DOMAIN, - data={ - "username": "test-username", - "password": "test-password", - "home_id": 1, - }, - ) - entry.add_to_hass(hass) - - with patch( - "homeassistant.components.tado.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={ - "username": "test-username", - "password": "test-password", - "home_id": 1, - }, - ) - await hass.async_block_till_done() - - assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "already_configured" - assert mock_setup_entry.call_count == 0 - - -async def test_import_step_validation_failed(hass: HomeAssistant) -> None: - """Test import step with validation failed.""" - with patch( - "homeassistant.components.tado.config_flow.Tado", - side_effect=RuntimeError, - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={ - "username": "test-username", - "password": "test-password", - "home_id": 1, - }, - ) - await hass.async_block_till_done() - - assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "import_failed" - - -async def test_import_step_device_authentication_failed(hass: HomeAssistant) -> None: - """Test import step with device tracker authentication failed.""" - with patch( - "homeassistant.components.tado.config_flow.Tado", - side_effect=PyTado.exceptions.TadoWrongCredentialsException, - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={ - "username": "test-username", - "password": "test-password", - "home_id": 1, - }, - ) - await hass.async_block_till_done() - - assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "import_failed_invalid_auth" - - -async def test_import_step_unique_id_configured(hass: HomeAssistant) -> None: - """Test import step with unique ID already configured.""" - entry = MockConfigEntry( - domain=DOMAIN, - data={ - "username": "test-username", - "password": "test-password", - "home_id": 1, - }, - unique_id="unique_id", - ) - entry.add_to_hass(hass) - - with patch( - "homeassistant.components.tado.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={ - "username": "test-username", - "password": "test-password", - "home_id": 1, - }, - ) - await hass.async_block_till_done() - - assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "already_configured" - assert mock_setup_entry.call_count == 0 - - @pytest.mark.parametrize( ("exception", "error"), [