From 031370358cb3a137a946116cdeebb8e0bf807627 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 9 Oct 2022 14:50:21 +0200 Subject: [PATCH] Remove yaml import openexchangerates (#79856) * Depr openexchangerates yaml * Remove setup_platform and issue * Remove schema * Remove not longer used constant --- .../openexchangerates/config_flow.py | 4 -- .../components/openexchangerates/sensor.py | 56 ++----------------- .../components/openexchangerates/strings.json | 4 +- .../openexchangerates/translations/en.json | 4 +- .../openexchangerates/test_config_flow.py | 29 ---------- 5 files changed, 8 insertions(+), 89 deletions(-) diff --git a/homeassistant/components/openexchangerates/config_flow.py b/homeassistant/components/openexchangerates/config_flow.py index 3c22f3e0fe0..13060e19718 100644 --- a/homeassistant/components/openexchangerates/config_flow.py +++ b/homeassistant/components/openexchangerates/config_flow.py @@ -126,7 +126,3 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): except asyncio.TimeoutError as err: raise AbortFlow("timeout_connect") from err return self.currencies - - async def async_step_import(self, import_config: dict[str, Any]) -> FlowResult: - """Handle import from yaml/configuration.""" - return await self.async_step_user(import_config) diff --git a/homeassistant/components/openexchangerates/sensor.py b/homeassistant/components/openexchangerates/sensor.py index 76573b351b3..f73f78cb4e8 100644 --- a/homeassistant/components/openexchangerates/sensor.py +++ b/homeassistant/components/openexchangerates/sensor.py @@ -1,68 +1,20 @@ """Support for openexchangerates.org exchange rates service.""" from __future__ import annotations -import voluptuous as vol - -from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import CONF_API_KEY, CONF_BASE, CONF_NAME, CONF_QUOTE +from homeassistant.components.sensor import SensorEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_NAME, CONF_QUOTE from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.update_coordinator import CoordinatorEntity -from .const import DEFAULT_BASE, DOMAIN, LOGGER +from .const import DOMAIN from .coordinator import OpenexchangeratesCoordinator ATTRIBUTION = "Data provided by openexchangerates.org" -DEFAULT_NAME = "Exchange Rate Sensor" - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_API_KEY): cv.string, - vol.Required(CONF_QUOTE): cv.string, - vol.Optional(CONF_BASE, default=DEFAULT_BASE): cv.string, - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - } -) - - -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Open Exchange Rates sensor.""" - async_create_issue( - hass, - DOMAIN, - "deprecated_yaml", - breaks_in_ha_version="2022.11.0", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_yaml", - ) - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data=config, - ) - ) - - LOGGER.warning( - "Configuration of Open Exchange Rates integration in YAML is deprecated and " - "will be removed in Home Assistant 2022.11.; Your existing configuration " - "has been imported into the UI automatically and can be safely removed from" - " your configuration.yaml file" - ) - async def async_setup_entry( hass: HomeAssistant, diff --git a/homeassistant/components/openexchangerates/strings.json b/homeassistant/components/openexchangerates/strings.json index 57180e367aa..5c4a833e0d6 100644 --- a/homeassistant/components/openexchangerates/strings.json +++ b/homeassistant/components/openexchangerates/strings.json @@ -26,8 +26,8 @@ }, "issues": { "deprecated_yaml": { - "title": "The Open Exchange Rates YAML configuration is being removed", - "description": "Configuring Open Exchange Rates using YAML is being removed.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove the Open Exchange Rates YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue." + "title": "The Open Exchange Rates YAML configuration has been removed", + "description": "Configuring Open Exchange Rates using YAML has been removed.\n\nRemove the Open Exchange Rates YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue." } } } diff --git a/homeassistant/components/openexchangerates/translations/en.json b/homeassistant/components/openexchangerates/translations/en.json index 011953904ff..f4827c4df4d 100644 --- a/homeassistant/components/openexchangerates/translations/en.json +++ b/homeassistant/components/openexchangerates/translations/en.json @@ -26,8 +26,8 @@ }, "issues": { "deprecated_yaml": { - "description": "Configuring Open Exchange Rates using YAML is being removed.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove the Open Exchange Rates YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue.", - "title": "The Open Exchange Rates YAML configuration is being removed" + "description": "Configuring Open Exchange Rates using YAML has been removed.\n\nRemove the Open Exchange Rates YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue.", + "title": "The Open Exchange Rates YAML configuration has been removed" } } } \ No newline at end of file diff --git a/tests/components/openexchangerates/test_config_flow.py b/tests/components/openexchangerates/test_config_flow.py index ee4ba57de2c..213badcab08 100644 --- a/tests/components/openexchangerates/test_config_flow.py +++ b/tests/components/openexchangerates/test_config_flow.py @@ -237,32 +237,3 @@ async def test_reauth( assert result["type"] == "abort" assert result["reason"] == "reauth_successful" assert len(mock_setup_entry.mock_calls) == 1 - - -async def test_import_create_entry( - hass: HomeAssistant, - mock_latest_rates_config_flow: AsyncMock, - mock_setup_entry: AsyncMock, -) -> None: - """Test we can import data from configuration.yaml.""" - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={ - "api_key": "test-api-key", - "base": "USD", - "quote": "EUR", - "name": "test", - }, - ) - await hass.async_block_till_done() - - assert result["type"] == FlowResultType.CREATE_ENTRY - assert result["title"] == "USD" - assert result["data"] == { - "api_key": "test-api-key", - "base": "USD", - "quote": "EUR", - "name": "test", - } - assert len(mock_setup_entry.mock_calls) == 1