From 3707b72a373f491c63eff887cbeed99c3e6ac119 Mon Sep 17 00:00:00 2001 From: Aaron Bach <bachya1208@gmail.com> Date: Mon, 9 Nov 2020 05:41:04 -0700 Subject: [PATCH] Deprecate YAML config for AirVisual (0.119 removal) (#42581) --- .../components/airvisual/__init__.py | 51 ++----------------- .../components/airvisual/config_flow.py | 4 -- .../components/airvisual/test_config_flow.py | 45 +++++++--------- 3 files changed, 21 insertions(+), 79 deletions(-) diff --git a/homeassistant/components/airvisual/__init__.py b/homeassistant/components/airvisual/__init__.py index 9b7fe5c2583..17a96629d60 100644 --- a/homeassistant/components/airvisual/__init__.py +++ b/homeassistant/components/airvisual/__init__.py @@ -10,9 +10,8 @@ from pyairvisual.errors import ( KeyExpiredError, NodeProError, ) -import voluptuous as vol -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH +from homeassistant.config_entries import SOURCE_REAUTH from homeassistant.const import ( ATTR_ATTRIBUTION, CONF_API_KEY, @@ -49,34 +48,8 @@ DATA_LISTENER = "listener" DEFAULT_ATTRIBUTION = "Data provided by AirVisual" DEFAULT_NODE_PRO_UPDATE_INTERVAL = timedelta(minutes=1) -DEFAULT_OPTIONS = {CONF_SHOW_ON_MAP: True} -GEOGRAPHY_COORDINATES_SCHEMA = vol.Schema( - { - vol.Required(CONF_LATITUDE): cv.latitude, - vol.Required(CONF_LONGITUDE): cv.longitude, - } -) - -GEOGRAPHY_PLACE_SCHEMA = vol.Schema( - { - vol.Required(CONF_CITY): cv.string, - vol.Required(CONF_STATE): cv.string, - vol.Required(CONF_COUNTRY): cv.string, - } -) - -CLOUD_API_SCHEMA = vol.Schema( - { - vol.Required(CONF_API_KEY): cv.string, - vol.Optional(CONF_GEOGRAPHIES, default=[]): vol.All( - cv.ensure_list, - [vol.Any(GEOGRAPHY_COORDINATES_SCHEMA, GEOGRAPHY_PLACE_SCHEMA)], - ), - } -) - -CONFIG_SCHEMA = vol.Schema({DOMAIN: CLOUD_API_SCHEMA}, extra=vol.ALLOW_EXTRA) +CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.119") @callback @@ -154,24 +127,6 @@ def async_sync_geo_coordinator_update_intervals(hass, api_key): async def async_setup(hass, config): """Set up the AirVisual component.""" hass.data[DOMAIN] = {DATA_COORDINATOR: {}, DATA_LISTENER: {}} - - if DOMAIN not in config: - return True - - conf = config[DOMAIN] - - for geography in conf.get( - CONF_GEOGRAPHIES, - [{CONF_LATITUDE: hass.config.latitude, CONF_LONGITUDE: hass.config.longitude}], - ): - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={CONF_API_KEY: conf[CONF_API_KEY], **geography}, - ) - ) - return True @@ -347,7 +302,7 @@ async def async_migrate_entry(hass, config_entry): hass.async_create_task( hass.config_entries.flow.async_init( DOMAIN, - context={"source": SOURCE_IMPORT}, + context={"source": "geography"}, data={CONF_API_KEY: config_entry.data[CONF_API_KEY], **geography}, ) ) diff --git a/homeassistant/components/airvisual/config_flow.py b/homeassistant/components/airvisual/config_flow.py index 7cf1262fa43..b086aeefc27 100644 --- a/homeassistant/components/airvisual/config_flow.py +++ b/homeassistant/components/airvisual/config_flow.py @@ -146,10 +146,6 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): data={**user_input, CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_GEOGRAPHY}, ) - async def async_step_import(self, import_config): - """Import a config entry from configuration.yaml.""" - return await self.async_step_geography(import_config) - async def async_step_node_pro(self, user_input=None): """Handle the initialization of the integration with a Node/Pro.""" if not user_input: diff --git a/tests/components/airvisual/test_config_flow.py b/tests/components/airvisual/test_config_flow.py index 100ac748e3e..3eb22360c5c 100644 --- a/tests/components/airvisual/test_config_flow.py +++ b/tests/components/airvisual/test_config_flow.py @@ -9,7 +9,7 @@ from homeassistant.components.airvisual import ( INTEGRATION_TYPE_GEOGRAPHY, INTEGRATION_TYPE_NODE_PRO, ) -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_USER from homeassistant.const import ( CONF_API_KEY, CONF_IP_ADDRESS, @@ -37,7 +37,10 @@ async def test_duplicate_error(hass): ).add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=geography_conf + DOMAIN, context={"source": SOURCE_USER}, data={"type": "Geographical Location"} + ) + result = await hass.config_entries.flow.async_configure( + result["flow_id"], user_input=geography_conf ) assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT @@ -73,8 +76,14 @@ async def test_invalid_identifier(hass): side_effect=InvalidKeyError, ): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=geography_conf + DOMAIN, + context={"source": SOURCE_USER}, + data={"type": "Geographical Location"}, + ) + result = await hass.config_entries.flow.async_configure( + result["flow_id"], user_input=geography_conf ) + assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["errors"] == {CONF_API_KEY: "invalid_api_key"} @@ -162,6 +171,7 @@ async def test_options_flow(hass): with patch( "homeassistant.components.airvisual.async_setup_entry", return_value=True ): + await hass.config_entries.async_setup(config_entry.entry_id) result = await hass.config_entries.options.async_init(config_entry.entry_id) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM @@ -187,31 +197,12 @@ async def test_step_geography(hass): "homeassistant.components.airvisual.async_setup_entry", return_value=True ), patch("pyairvisual.air_quality.AirQuality.nearest_city"): result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=conf + DOMAIN, + context={"source": SOURCE_USER}, + data={"type": "Geographical Location"}, ) - assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY - assert result["title"] == "Cloud API (51.528308, -0.3817765)" - assert result["data"] == { - CONF_API_KEY: "abcde12345", - CONF_LATITUDE: 51.528308, - CONF_LONGITUDE: -0.3817765, - CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_GEOGRAPHY, - } - - -async def test_step_import(hass): - """Test the import step for both types of configuration.""" - geography_conf = { - CONF_API_KEY: "abcde12345", - CONF_LATITUDE: 51.528308, - CONF_LONGITUDE: -0.3817765, - } - - with patch( - "homeassistant.components.airvisual.async_setup_entry", return_value=True - ), patch("pyairvisual.air_quality.AirQuality.nearest_city"): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=geography_conf + result = await hass.config_entries.flow.async_configure( + result["flow_id"], user_input=conf ) assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY -- GitLab