From c0bcf00bf8f7542b335405f02bb4375bbb0e90d9 Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Thu, 23 May 2024 22:12:19 +0300 Subject: [PATCH] Remove Switcher YAML import support (#117994) --- .../components/switcher_kis/__init__.py | 47 ++----------------- .../components/switcher_kis/config_flow.py | 9 ---- .../components/switcher_kis/const.py | 3 -- tests/components/switcher_kis/consts.py | 15 ------ .../switcher_kis/test_config_flow.py | 25 +--------- tests/components/switcher_kis/test_init.py | 14 +----- 6 files changed, 7 insertions(+), 106 deletions(-) diff --git a/homeassistant/components/switcher_kis/__init__.py b/homeassistant/components/switcher_kis/__init__.py index 50f75469b98..49ac63de87a 100644 --- a/homeassistant/components/switcher_kis/__init__.py +++ b/homeassistant/components/switcher_kis/__init__.py @@ -5,21 +5,12 @@ from __future__ import annotations import logging from aioswitcher.device import SwitcherBase -import voluptuous as vol -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import CONF_DEVICE_ID, EVENT_HOMEASSISTANT_STOP, Platform +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.core import Event, HomeAssistant, callback -from homeassistant.helpers import config_validation as cv -from homeassistant.helpers.typing import ConfigType -from .const import ( - CONF_DEVICE_PASSWORD, - CONF_PHONE_ID, - DATA_DEVICE, - DATA_DISCOVERY, - DOMAIN, -) +from .const import DATA_DEVICE, DATA_DISCOVERY, DOMAIN from .coordinator import SwitcherDataUpdateCoordinator from .utils import async_start_bridge, async_stop_bridge @@ -33,40 +24,10 @@ PLATFORMS = [ _LOGGER = logging.getLogger(__name__) -CONFIG_SCHEMA = vol.Schema( - vol.All( - cv.deprecated(DOMAIN), - { - DOMAIN: vol.Schema( - { - vol.Required(CONF_PHONE_ID): cv.string, - vol.Required(CONF_DEVICE_ID): cv.string, - vol.Required(CONF_DEVICE_PASSWORD): cv.string, - } - ) - }, - ), - extra=vol.ALLOW_EXTRA, -) - - -async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: - """Set up the switcher component.""" - hass.data.setdefault(DOMAIN, {}) - - if DOMAIN not in config: - return True - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data={} - ) - ) - return True - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Switcher from a config entry.""" + hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][DATA_DEVICE] = {} @callback diff --git a/homeassistant/components/switcher_kis/config_flow.py b/homeassistant/components/switcher_kis/config_flow.py index bd24481ce3f..be348916e4f 100644 --- a/homeassistant/components/switcher_kis/config_flow.py +++ b/homeassistant/components/switcher_kis/config_flow.py @@ -13,15 +13,6 @@ from .utils import async_discover_devices class SwitcherFlowHandler(ConfigFlow, domain=DOMAIN): """Handle Switcher config flow.""" - async def async_step_import( - self, import_config: dict[str, Any] - ) -> ConfigFlowResult: - """Handle a flow initiated by import.""" - if self._async_current_entries(True): - return self.async_abort(reason="single_instance_allowed") - - return self.async_create_entry(title="Switcher", data={}) - async def async_step_user( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: diff --git a/homeassistant/components/switcher_kis/const.py b/homeassistant/components/switcher_kis/const.py index 248b7afbc81..a7a7129b136 100644 --- a/homeassistant/components/switcher_kis/const.py +++ b/homeassistant/components/switcher_kis/const.py @@ -2,9 +2,6 @@ DOMAIN = "switcher_kis" -CONF_DEVICE_PASSWORD = "device_password" -CONF_PHONE_ID = "phone_id" - DATA_BRIDGE = "bridge" DATA_DEVICE = "device" DATA_DISCOVERY = "discovery" diff --git a/tests/components/switcher_kis/consts.py b/tests/components/switcher_kis/consts.py index aa0370bd347..3c5f3ff241e 100644 --- a/tests/components/switcher_kis/consts.py +++ b/tests/components/switcher_kis/consts.py @@ -13,13 +13,6 @@ from aioswitcher.device import ( ThermostatSwing, ) -from homeassistant.components.switcher_kis import ( - CONF_DEVICE_ID, - CONF_DEVICE_PASSWORD, - CONF_PHONE_ID, - DOMAIN, -) - DUMMY_AUTO_OFF_SET = "01:30:00" DUMMY_AUTO_SHUT_DOWN = "02:00:00" DUMMY_DEVICE_ID1 = "a123bc" @@ -59,14 +52,6 @@ DUMMY_REMOTE_ID = "ELEC7001" DUMMY_POSITION = 54 DUMMY_DIRECTION = ShutterDirection.SHUTTER_STOP -YAML_CONFIG = { - DOMAIN: { - CONF_PHONE_ID: DUMMY_PHONE_ID, - CONF_DEVICE_ID: DUMMY_DEVICE_ID1, - CONF_DEVICE_PASSWORD: DUMMY_DEVICE_PASSWORD, - } -} - DUMMY_PLUG_DEVICE = SwitcherPowerPlug( DeviceType.POWER_PLUG, DeviceState.ON, diff --git a/tests/components/switcher_kis/test_config_flow.py b/tests/components/switcher_kis/test_config_flow.py index 913424abae5..8d63818a6e0 100644 --- a/tests/components/switcher_kis/test_config_flow.py +++ b/tests/components/switcher_kis/test_config_flow.py @@ -14,20 +14,6 @@ from .consts import DUMMY_PLUG_DEVICE, DUMMY_WATER_HEATER_DEVICE from tests.common import MockConfigEntry -async def test_import(hass: HomeAssistant) -> None: - """Test import step.""" - with patch( - "homeassistant.components.switcher_kis.async_setup_entry", return_value=True - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_IMPORT} - ) - - assert result["type"] is FlowResultType.CREATE_ENTRY - assert result["title"] == "Switcher" - assert result["data"] == {} - - @pytest.mark.parametrize( "mock_bridge", [ @@ -88,20 +74,13 @@ async def test_user_setup_abort_no_devices_found( assert result2["reason"] == "no_devices_found" -@pytest.mark.parametrize( - "source", - [ - config_entries.SOURCE_IMPORT, - config_entries.SOURCE_USER, - ], -) -async def test_single_instance(hass: HomeAssistant, source) -> None: +async def test_single_instance(hass: HomeAssistant) -> None: """Test we only allow a single config flow.""" MockConfigEntry(domain=DOMAIN).add_to_hass(hass) await hass.async_block_till_done() result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": source} + DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] is FlowResultType.ABORT diff --git a/tests/components/switcher_kis/test_init.py b/tests/components/switcher_kis/test_init.py index f0484ca2f67..6105119d9a5 100644 --- a/tests/components/switcher_kis/test_init.py +++ b/tests/components/switcher_kis/test_init.py @@ -14,26 +14,14 @@ from homeassistant.components.switcher_kis.const import ( from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE from homeassistant.core import HomeAssistant -from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util, slugify from . import init_integration -from .consts import DUMMY_SWITCHER_DEVICES, YAML_CONFIG +from .consts import DUMMY_SWITCHER_DEVICES from tests.common import async_fire_time_changed -@pytest.mark.parametrize("mock_bridge", [DUMMY_SWITCHER_DEVICES], indirect=True) -async def test_async_setup_yaml_config(hass: HomeAssistant, mock_bridge) -> None: - """Test setup started by configuration from YAML.""" - assert await async_setup_component(hass, DOMAIN, YAML_CONFIG) - await hass.async_block_till_done() - - assert mock_bridge.is_running is True - assert len(hass.data[DOMAIN]) == 2 - assert len(hass.data[DOMAIN][DATA_DEVICE]) == 2 - - @pytest.mark.parametrize("mock_bridge", [DUMMY_SWITCHER_DEVICES], indirect=True) async def test_async_setup_user_config_flow(hass: HomeAssistant, mock_bridge) -> None: """Test setup started by user config flow."""