From de4514475087ac7061e1ffdf7b6d8b89617a3eea Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 14 Dec 2021 09:21:12 +0100 Subject: [PATCH] Remove deprecated YAML configuration from Luftdaten (#61748) --- .../components/luftdaten/__init__.py | 68 +++---------------- .../components/luftdaten/config_flow.py | 4 -- .../components/luftdaten/test_config_flow.py | 21 ------ tests/components/luftdaten/test_init.py | 39 ----------- 4 files changed, 9 insertions(+), 123 deletions(-) delete mode 100644 tests/components/luftdaten/test_init.py diff --git a/homeassistant/components/luftdaten/__init__.py b/homeassistant/components/luftdaten/__init__.py index 9aef41434ed..f525bcb69bc 100644 --- a/homeassistant/components/luftdaten/__init__.py +++ b/homeassistant/components/luftdaten/__init__.py @@ -5,7 +5,6 @@ import logging from luftdaten import Luftdaten from luftdaten.exceptions import LuftdatenError -import voluptuous as vol from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription from homeassistant.config_entries import SOURCE_IMPORT @@ -14,7 +13,6 @@ from homeassistant.const import ( CONF_MONITORED_CONDITIONS, CONF_SCAN_INTERVAL, CONF_SENSORS, - CONF_SHOW_ON_MAP, PERCENTAGE, PRESSURE_PA, TEMP_CELSIUS, @@ -26,7 +24,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_track_time_interval -from .config_flow import configured_sensors, duplicate_stations +from .config_flow import duplicate_stations from .const import CONF_SENSOR_ID, DEFAULT_SCAN_INTERVAL, DOMAIN _LOGGER = logging.getLogger(__name__) @@ -90,32 +88,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( ) SENSOR_KEYS: list[str] = [desc.key for desc in SENSOR_TYPES] -SENSOR_SCHEMA = vol.Schema( - { - vol.Optional(CONF_MONITORED_CONDITIONS, default=SENSOR_KEYS): vol.All( - cv.ensure_list, [vol.In(SENSOR_KEYS)] - ) - } -) - -CONFIG_SCHEMA = vol.Schema( - vol.All( - cv.deprecated(DOMAIN), - { - DOMAIN: vol.Schema( - { - vol.Required(CONF_SENSOR_ID): cv.positive_int, - vol.Optional(CONF_SENSORS, default={}): SENSOR_SCHEMA, - vol.Optional(CONF_SHOW_ON_MAP, default=False): cv.boolean, - vol.Optional( - CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL - ): cv.time_period, - } - ) - }, - ), - extra=vol.ALLOW_EXTRA, -) +CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False) @callback @@ -125,38 +98,15 @@ def _async_fixup_sensor_id(hass, config_entry, sensor_id): ) -async def async_setup(hass, config): - """Set up the Luftdaten component.""" - hass.data[DOMAIN] = {} - hass.data[DOMAIN][DATA_LUFTDATEN_CLIENT] = {} - hass.data[DOMAIN][DATA_LUFTDATEN_LISTENER] = {} - - if DOMAIN not in config: - return True - - conf = config[DOMAIN] - station_id = conf[CONF_SENSOR_ID] - - if station_id not in configured_sensors(hass): - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={ - CONF_SENSORS: conf[CONF_SENSORS], - CONF_SENSOR_ID: conf[CONF_SENSOR_ID], - CONF_SHOW_ON_MAP: conf[CONF_SHOW_ON_MAP], - }, - ) - ) - - hass.data[DOMAIN][CONF_SCAN_INTERVAL] = conf[CONF_SCAN_INTERVAL] - - return True - - async def async_setup_entry(hass, config_entry): """Set up Luftdaten as config entry.""" + hass.data.setdefault( + DOMAIN, + { + DATA_LUFTDATEN_CLIENT: {}, + DATA_LUFTDATEN_LISTENER: {}, + }, + ) if not isinstance(config_entry.data[CONF_SENSOR_ID], int): _async_fixup_sensor_id(hass, config_entry, config_entry.data[CONF_SENSOR_ID]) diff --git a/homeassistant/components/luftdaten/config_flow.py b/homeassistant/components/luftdaten/config_flow.py index 56dee86e9fb..b7aae271815 100644 --- a/homeassistant/components/luftdaten/config_flow.py +++ b/homeassistant/components/luftdaten/config_flow.py @@ -53,10 +53,6 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): step_id="user", data_schema=vol.Schema(data_schema), errors=errors or {} ) - async def async_step_import(self, import_config): - """Import a config entry from configuration.yaml.""" - return await self.async_step_user(import_config) - async def async_step_user(self, user_input=None): """Handle the start of the config flow.""" diff --git a/tests/components/luftdaten/test_config_flow.py b/tests/components/luftdaten/test_config_flow.py index 4ea55e26aee..ac475a8ab38 100644 --- a/tests/components/luftdaten/test_config_flow.py +++ b/tests/components/luftdaten/test_config_flow.py @@ -59,27 +59,6 @@ async def test_show_form(hass): assert result["step_id"] == "user" -async def test_step_import(hass): - """Test that the import step works.""" - conf = {CONF_SENSOR_ID: "12345abcde", CONF_SHOW_ON_MAP: False} - - flow = config_flow.LuftDatenFlowHandler() - flow.hass = hass - - with patch("luftdaten.Luftdaten.get_data", return_value=True), patch( - "luftdaten.Luftdaten.validate_sensor", return_value=True - ): - result = await flow.async_step_import(import_config=conf) - - assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY - assert result["title"] == "12345abcde" - assert result["data"] == { - CONF_SENSOR_ID: "12345abcde", - CONF_SHOW_ON_MAP: False, - CONF_SCAN_INTERVAL: 600, - } - - async def test_step_user(hass): """Test that the user step works.""" conf = { diff --git a/tests/components/luftdaten/test_init.py b/tests/components/luftdaten/test_init.py deleted file mode 100644 index ebe5f73669e..00000000000 --- a/tests/components/luftdaten/test_init.py +++ /dev/null @@ -1,39 +0,0 @@ -"""Test the Luftdaten component setup.""" -from unittest.mock import patch - -from homeassistant.components import luftdaten -from homeassistant.components.luftdaten.const import CONF_SENSOR_ID, DOMAIN -from homeassistant.const import CONF_SCAN_INTERVAL, CONF_SHOW_ON_MAP -from homeassistant.setup import async_setup_component - - -async def test_config_with_sensor_passed_to_config_entry(hass): - """Test that configured options for a sensor are loaded.""" - conf = { - CONF_SENSOR_ID: "12345abcde", - CONF_SHOW_ON_MAP: False, - CONF_SCAN_INTERVAL: 600, - } - - with patch.object( - hass.config_entries.flow, "async_init" - ) as mock_config_entries, patch.object( - luftdaten, "configured_sensors", return_value=[] - ): - assert await async_setup_component(hass, DOMAIN, conf) is True - - assert len(mock_config_entries.flow.mock_calls) == 0 - - -async def test_config_already_registered_not_passed_to_config_entry(hass): - """Test that an already registered sensor does not initiate an import.""" - conf = {CONF_SENSOR_ID: "12345abcde"} - - with patch.object( - hass.config_entries.flow, "async_init" - ) as mock_config_entries, patch.object( - luftdaten, "configured_sensors", return_value=["12345abcde"] - ): - assert await async_setup_component(hass, DOMAIN, conf) is True - - assert len(mock_config_entries.flow.mock_calls) == 0