From b942569ce0e11e83c3ea788ef3b4339906f7fd25 Mon Sep 17 00:00:00 2001 From: Sid <27780930+autinerd@users.noreply.github.com> Date: Sat, 5 Oct 2024 10:00:23 +0200 Subject: [PATCH] Remove enigma2 yaml import (#127597) --- .../components/enigma2/config_flow.py | 51 +--------- .../components/enigma2/media_player.py | 73 +-------------- homeassistant/components/enigma2/strings.json | 14 --- tests/components/enigma2/conftest.py | 17 ---- tests/components/enigma2/test_config_flow.py | 93 +------------------ 5 files changed, 4 insertions(+), 244 deletions(-) diff --git a/homeassistant/components/enigma2/config_flow.py b/homeassistant/components/enigma2/config_flow.py index 55c0f6fc6ae..e9502a0f7cd 100644 --- a/homeassistant/components/enigma2/config_flow.py +++ b/homeassistant/components/enigma2/config_flow.py @@ -22,10 +22,9 @@ from homeassistant.const import ( CONF_USERNAME, CONF_VERIFY_SSL, ) -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, callback +from homeassistant.core import callback from homeassistant.helpers import selector from homeassistant.helpers.aiohttp_client import async_create_clientsession -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.schema_config_entry_flow import ( SchemaCommonFlowHandler, SchemaFlowFormStep, @@ -152,54 +151,6 @@ class Enigma2ConfigFlowHandler(ConfigFlow, domain=DOMAIN): ) return self.async_create_entry(data=user_input, title=user_input[CONF_HOST]) - async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult: - """Handle the import step.""" - if CONF_PORT not in import_data: - import_data[CONF_PORT] = DEFAULT_PORT - if CONF_SSL not in import_data: - import_data[CONF_SSL] = DEFAULT_SSL - import_data[CONF_VERIFY_SSL] = DEFAULT_VERIFY_SSL - - data = {key: import_data[key] for key in import_data if key in self.DATA_KEYS} - options = { - key: import_data[key] for key in import_data if key in self.OPTIONS_KEYS - } - - if errors := await self.validate_user_input(import_data): - async_create_issue( - self.hass, - DOMAIN, - f"deprecated_yaml_{DOMAIN}_import_issue_{errors["base"]}", - breaks_in_ha_version="2024.11.0", - is_fixable=False, - issue_domain=DOMAIN, - severity=IssueSeverity.WARNING, - translation_key=f"deprecated_yaml_import_issue_{errors["base"]}", - translation_placeholders={ - "url": "/config/integrations/dashboard/add?domain=enigma2" - }, - ) - return self.async_abort(reason=errors["base"]) - - async_create_issue( - self.hass, - HOMEASSISTANT_DOMAIN, - f"deprecated_yaml_{DOMAIN}", - breaks_in_ha_version="2024.11.0", - is_fixable=False, - is_persistent=False, - issue_domain=DOMAIN, - severity=IssueSeverity.WARNING, - translation_key="deprecated_yaml", - translation_placeholders={ - "domain": DOMAIN, - "integration_title": "Enigma2", - }, - ) - return self.async_create_entry( - data=data, title=data[CONF_HOST], options=options - ) - @staticmethod @callback def async_get_options_flow(config_entry: ConfigEntry) -> SchemaOptionsFlowHandler: diff --git a/homeassistant/components/enigma2/media_player.py b/homeassistant/components/enigma2/media_player.py index 927e35706ed..8287e055814 100644 --- a/homeassistant/components/enigma2/media_player.py +++ b/homeassistant/components/enigma2/media_player.py @@ -8,47 +8,19 @@ from typing import cast from aiohttp.client_exceptions import ServerDisconnectedError from openwebif.enums import PowerState, RemoteControlCodes, SetVolumeOption -import voluptuous as vol from homeassistant.components.media_player import ( - PLATFORM_SCHEMA as MEDIA_PLAYER_PLATFORM_SCHEMA, MediaPlayerEntity, MediaPlayerEntityFeature, MediaPlayerState, MediaType, ) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import ( - CONF_HOST, - CONF_NAME, - CONF_PASSWORD, - CONF_PORT, - CONF_SSL, - CONF_USERNAME, -) +from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import Enigma2ConfigEntry -from .const import ( - CONF_DEEP_STANDBY, - CONF_MAC_ADDRESS, - CONF_SOURCE_BOUQUET, - CONF_USE_CHANNEL_ICON, - DEFAULT_DEEP_STANDBY, - DEFAULT_MAC_ADDRESS, - DEFAULT_NAME, - DEFAULT_PASSWORD, - DEFAULT_PORT, - DEFAULT_SOURCE_BOUQUET, - DEFAULT_SSL, - DEFAULT_USE_CHANNEL_ICON, - DEFAULT_USERNAME, - DOMAIN, -) from .coordinator import Enigma2UpdateCoordinator ATTR_MEDIA_CURRENTLY_RECORDING = "media_currently_recording" @@ -58,49 +30,6 @@ ATTR_MEDIA_START_TIME = "media_start_time" _LOGGER = getLogger(__name__) -PLATFORM_SCHEMA = MEDIA_PLAYER_PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_HOST): cv.string, - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, - vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string, - vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string, - vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean, - vol.Optional( - CONF_USE_CHANNEL_ICON, default=DEFAULT_USE_CHANNEL_ICON - ): cv.boolean, - vol.Optional(CONF_DEEP_STANDBY, default=DEFAULT_DEEP_STANDBY): cv.boolean, - vol.Optional(CONF_MAC_ADDRESS, default=DEFAULT_MAC_ADDRESS): cv.string, - vol.Optional(CONF_SOURCE_BOUQUET, default=DEFAULT_SOURCE_BOUQUET): cv.string, - } -) - - -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up of an enigma2 media player.""" - - entry_data = { - CONF_HOST: config[CONF_HOST], - CONF_PORT: config[CONF_PORT], - CONF_USERNAME: config[CONF_USERNAME], - CONF_PASSWORD: config[CONF_PASSWORD], - CONF_SSL: config[CONF_SSL], - CONF_USE_CHANNEL_ICON: config[CONF_USE_CHANNEL_ICON], - CONF_DEEP_STANDBY: config[CONF_DEEP_STANDBY], - CONF_SOURCE_BOUQUET: config[CONF_SOURCE_BOUQUET], - } - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=entry_data - ) - ) - async def async_setup_entry( hass: HomeAssistant, diff --git a/homeassistant/components/enigma2/strings.json b/homeassistant/components/enigma2/strings.json index f74806b60a2..7a75136bdc2 100644 --- a/homeassistant/components/enigma2/strings.json +++ b/homeassistant/components/enigma2/strings.json @@ -39,19 +39,5 @@ } } } - }, - "issues": { - "deprecated_yaml_import_issue_unknown": { - "title": "The Enigma2 YAML configuration import failed", - "description": "Configuring Enigma2 using YAML is being removed but there was an error importing your YAML configuration.\n\nEnsure connection to the device works, the authentication details are correct and restart Home Assistant to try again or remove the Enigma2 YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually." - }, - "deprecated_yaml_import_issue_invalid_auth": { - "title": "The Enigma2 YAML configuration import failed", - "description": "Configuring Enigma2 using YAML is being removed but there was an error importing your YAML configuration.\n\nEnsure the authentication details are correct and restart Home Assistant to try again or remove the Enigma2 YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually." - }, - "deprecated_yaml_import_issue_cannot_connect": { - "title": "The Enigma2 YAML configuration import failed", - "description": "Configuring Enigma2 using YAML is being removed but there was an error importing your YAML configuration.\n\nEnsure connection to the device works and restart Home Assistant to try again or remove the Enigma2 YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually." - } } } diff --git a/tests/components/enigma2/conftest.py b/tests/components/enigma2/conftest.py index 6c024ebf66a..a53d1494e9a 100644 --- a/tests/components/enigma2/conftest.py +++ b/tests/components/enigma2/conftest.py @@ -4,7 +4,6 @@ from openwebif.api import OpenWebIfServiceEvent, OpenWebIfStatus from homeassistant.components.enigma2.const import ( CONF_DEEP_STANDBY, - CONF_MAC_ADDRESS, CONF_SOURCE_BOUQUET, CONF_USE_CHANNEL_ICON, DEFAULT_DEEP_STANDBY, @@ -14,7 +13,6 @@ from homeassistant.components.enigma2.const import ( ) from homeassistant.const import ( CONF_HOST, - CONF_NAME, CONF_PASSWORD, CONF_PORT, CONF_SSL, @@ -40,21 +38,6 @@ TEST_FULL = { CONF_VERIFY_SSL: DEFAULT_VERIFY_SSL, } -TEST_IMPORT_FULL = { - CONF_HOST: "1.1.1.1", - CONF_PORT: DEFAULT_PORT, - CONF_SSL: DEFAULT_SSL, - CONF_USERNAME: "root", - CONF_PASSWORD: "password", - CONF_NAME: "My Player", - CONF_DEEP_STANDBY: DEFAULT_DEEP_STANDBY, - CONF_SOURCE_BOUQUET: "Favourites", - CONF_MAC_ADDRESS: MAC_ADDRESS, - CONF_USE_CHANNEL_ICON: False, -} - -TEST_IMPORT_REQUIRED = {CONF_HOST: "1.1.1.1"} - EXPECTED_OPTIONS = { CONF_DEEP_STANDBY: DEFAULT_DEEP_STANDBY, CONF_SOURCE_BOUQUET: "Favourites", diff --git a/tests/components/enigma2/test_config_flow.py b/tests/components/enigma2/test_config_flow.py index 74721ce0993..8d32da42baf 100644 --- a/tests/components/enigma2/test_config_flow.py +++ b/tests/components/enigma2/test_config_flow.py @@ -10,18 +10,10 @@ import pytest from homeassistant import config_entries from homeassistant.components.enigma2.const import DOMAIN from homeassistant.const import CONF_HOST -from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant +from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType -from homeassistant.helpers import issue_registry as ir -from .conftest import ( - EXPECTED_OPTIONS, - TEST_FULL, - TEST_IMPORT_FULL, - TEST_IMPORT_REQUIRED, - TEST_REQUIRED, - MockDevice, -) +from .conftest import TEST_FULL, TEST_REQUIRED, MockDevice from tests.common import MockConfigEntry @@ -87,87 +79,6 @@ async def test_form_user_errors( assert result["errors"] == {"base": error_type} -@pytest.mark.parametrize( - ("test_config", "expected_data", "expected_options"), - [ - (TEST_IMPORT_FULL, TEST_FULL, EXPECTED_OPTIONS), - (TEST_IMPORT_REQUIRED, TEST_REQUIRED, {}), - ], -) -async def test_form_import( - hass: HomeAssistant, - test_config: dict[str, Any], - expected_data: dict[str, Any], - expected_options: dict[str, Any], - issue_registry: ir.IssueRegistry, -) -> None: - """Test we get the form with import source.""" - with ( - patch( - "homeassistant.components.enigma2.config_flow.OpenWebIfDevice.__new__", - return_value=MockDevice(), - ), - patch( - "homeassistant.components.enigma2.async_setup_entry", - return_value=True, - ) as mock_setup_entry, - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=test_config, - ) - await hass.async_block_till_done() - - issue = issue_registry.async_get_issue( - HOMEASSISTANT_DOMAIN, f"deprecated_yaml_{DOMAIN}" - ) - - assert issue - assert issue.issue_domain == DOMAIN - assert result["type"] == FlowResultType.CREATE_ENTRY - assert result["title"] == test_config[CONF_HOST] - assert result["data"] == expected_data - assert result["options"] == expected_options - - assert len(mock_setup_entry.mock_calls) == 1 - - -@pytest.mark.parametrize( - ("exception", "error_type"), - [ - (InvalidAuthError, "invalid_auth"), - (ClientError, "cannot_connect"), - (Exception, "unknown"), - ], -) -async def test_form_import_errors( - hass: HomeAssistant, - exception: Exception, - error_type: str, - issue_registry: ir.IssueRegistry, -) -> None: - """Test we handle errors on import.""" - with patch( - "homeassistant.components.enigma2.config_flow.OpenWebIfDevice.__new__", - side_effect=exception, - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data=TEST_IMPORT_FULL, - ) - - issue = issue_registry.async_get_issue( - DOMAIN, f"deprecated_yaml_{DOMAIN}_import_issue_{error_type}" - ) - - assert issue - assert issue.issue_domain == DOMAIN - assert result["type"] is FlowResultType.ABORT - assert result["reason"] == error_type - - async def test_options_flow(hass: HomeAssistant, user_flow: str) -> None: """Test the form options."""