diff --git a/homeassistant/components/switchbot/config_flow.py b/homeassistant/components/switchbot/config_flow.py index 2d4e61bada5..70e032414a7 100644 --- a/homeassistant/components/switchbot/config_flow.py +++ b/homeassistant/components/switchbot/config_flow.py @@ -131,19 +131,6 @@ class SwitchbotConfigFlow(ConfigFlow, domain=DOMAIN): step_id="user", data_schema=data_schema, errors=errors ) - async def async_step_import(self, import_config: dict[str, Any]) -> FlowResult: - """Handle config import from yaml.""" - _LOGGER.debug("import config: %s", import_config) - - import_config[CONF_MAC] = import_config[CONF_MAC].replace("-", ":").lower() - - await self.async_set_unique_id(import_config[CONF_MAC].replace(":", "")) - self._abort_if_unique_id_configured() - - return self.async_create_entry( - title=import_config[CONF_NAME], data=import_config - ) - class SwitchbotOptionsFlowHandler(OptionsFlow): """Handle Switchbot options.""" diff --git a/homeassistant/components/switchbot/switch.py b/homeassistant/components/switchbot/switch.py index de66a437dee..b5507594521 100644 --- a/homeassistant/components/switchbot/switch.py +++ b/homeassistant/components/switchbot/switch.py @@ -5,27 +5,15 @@ import logging from typing import Any from switchbot import Switchbot # pylint: disable=import-error -import voluptuous as vol -from homeassistant.components.switch import ( - PLATFORM_SCHEMA, - SwitchDeviceClass, - SwitchEntity, -) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import ( - CONF_MAC, - CONF_NAME, - CONF_PASSWORD, - CONF_SENSOR_TYPE, - STATE_ON, -) +from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD, STATE_ON from homeassistant.core import HomeAssistant -from homeassistant.helpers import config_validation as cv, entity_platform +from homeassistant.helpers import entity_platform from homeassistant.helpers.restore_state import RestoreEntity -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -from .const import ATTR_BOT, CONF_RETRY_COUNT, DATA_COORDINATOR, DEFAULT_NAME, DOMAIN +from .const import CONF_RETRY_COUNT, DATA_COORDINATOR, DOMAIN from .coordinator import SwitchbotDataUpdateCoordinator from .entity import SwitchbotEntity @@ -33,46 +21,6 @@ from .entity import SwitchbotEntity _LOGGER = logging.getLogger(__name__) PARALLEL_UPDATES = 1 -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_MAC): cv.string, - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_PASSWORD): cv.string, - } -) - - -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: entity_platform.AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Import yaml config and initiates config flow for Switchbot devices.""" - _LOGGER.warning( - "Configuration of the Switchbot switch platform in YAML is deprecated and " - "will be removed in Home Assistant 2022.4; Your existing configuration " - "has been imported into the UI automatically and can be safely removed " - "from your configuration.yaml file" - ) - - # Check if entry config exists and skips import if it does. - if hass.config_entries.async_entries(DOMAIN): - return - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={ - CONF_NAME: config[CONF_NAME], - CONF_PASSWORD: config.get(CONF_PASSWORD, None), - CONF_MAC: config[CONF_MAC].replace("-", ":").lower(), - CONF_SENSOR_TYPE: ATTR_BOT, - }, - ) - ) - async def async_setup_entry( hass: HomeAssistant, diff --git a/tests/components/switchbot/__init__.py b/tests/components/switchbot/__init__.py index 5d01a8d0d68..376406ac50c 100644 --- a/tests/components/switchbot/__init__.py +++ b/tests/components/switchbot/__init__.py @@ -1,7 +1,7 @@ """Tests for the switchbot integration.""" from unittest.mock import patch -from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD, CONF_SENSOR_TYPE +from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -38,15 +38,9 @@ USER_INPUT_INVALID = { CONF_MAC: "invalid-mac", } -YAML_CONFIG = { - CONF_NAME: "test-name", - CONF_PASSWORD: "test-password", - CONF_MAC: "e7:89:43:99:99:99", - CONF_SENSOR_TYPE: "bot", -} - -def _patch_async_setup_entry(return_value=True): +def patch_async_setup_entry(return_value=True): + """Patch async setup entry to return True.""" return patch( "homeassistant.components.switchbot.async_setup_entry", return_value=return_value, diff --git a/tests/components/switchbot/test_config_flow.py b/tests/components/switchbot/test_config_flow.py index edd35238034..59871681dfe 100644 --- a/tests/components/switchbot/test_config_flow.py +++ b/tests/components/switchbot/test_config_flow.py @@ -7,7 +7,7 @@ from homeassistant.components.switchbot.const import ( CONF_SCAN_TIMEOUT, CONF_TIME_BETWEEN_UPDATE_COMMAND, ) -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_USER from homeassistant.const import CONF_MAC, CONF_NAME, CONF_PASSWORD, CONF_SENSOR_TYPE from homeassistant.data_entry_flow import ( RESULT_TYPE_ABORT, @@ -15,13 +15,7 @@ from homeassistant.data_entry_flow import ( RESULT_TYPE_FORM, ) -from . import ( - USER_INPUT, - USER_INPUT_CURTAIN, - YAML_CONFIG, - _patch_async_setup_entry, - init_integration, -) +from . import USER_INPUT, USER_INPUT_CURTAIN, init_integration, patch_async_setup_entry DOMAIN = "switchbot" @@ -36,7 +30,7 @@ async def test_user_form_valid_mac(hass): assert result["step_id"] == "user" assert result["errors"] == {} - with _patch_async_setup_entry() as mock_setup_entry: + with patch_async_setup_entry() as mock_setup_entry: result = await hass.config_entries.flow.async_configure( result["flow_id"], USER_INPUT, @@ -63,7 +57,7 @@ async def test_user_form_valid_mac(hass): assert result["step_id"] == "user" assert result["errors"] == {} - with _patch_async_setup_entry() as mock_setup_entry: + with patch_async_setup_entry() as mock_setup_entry: result = await hass.config_entries.flow.async_configure( result["flow_id"], USER_INPUT_CURTAIN, @@ -90,24 +84,6 @@ async def test_user_form_valid_mac(hass): assert result["reason"] == "no_unconfigured_devices" -async def test_async_step_import(hass): - """Test the config import flow.""" - - with _patch_async_setup_entry() as mock_setup_entry: - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=YAML_CONFIG - ) - assert result["type"] == RESULT_TYPE_CREATE_ENTRY - assert result["data"] == { - CONF_MAC: "e7:89:43:99:99:99", - CONF_NAME: "test-name", - CONF_PASSWORD: "test-password", - CONF_SENSOR_TYPE: "bot", - } - - assert len(mock_setup_entry.mock_calls) == 1 - - async def test_user_form_exception(hass, switchbot_config_flow): """Test we handle exception on user form.""" @@ -132,7 +108,7 @@ async def test_user_form_exception(hass, switchbot_config_flow): async def test_options_flow(hass): """Test updating options.""" - with _patch_async_setup_entry() as mock_setup_entry: + with patch_async_setup_entry() as mock_setup_entry: entry = await init_integration(hass) result = await hass.config_entries.options.async_init(entry.entry_id) @@ -161,7 +137,7 @@ async def test_options_flow(hass): # Test changing of entry options. - with _patch_async_setup_entry() as mock_setup_entry: + with patch_async_setup_entry() as mock_setup_entry: entry = await init_integration(hass) result = await hass.config_entries.options.async_init(entry.entry_id)