From 3ce19cd6f870b91f162c69d027a52f2f795f899d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 12 May 2022 09:39:49 +0200 Subject: [PATCH] Remove YAML configuration from DuneHD (#71694) --- .../components/dunehd/config_flow.py | 28 +----------- .../components/dunehd/media_player.py | 39 +--------------- tests/components/dunehd/test_config_flow.py | 45 +------------------ 3 files changed, 4 insertions(+), 108 deletions(-) diff --git a/homeassistant/components/dunehd/config_flow.py b/homeassistant/components/dunehd/config_flow.py index 434bbc7bd84..b5a656716b0 100644 --- a/homeassistant/components/dunehd/config_flow.py +++ b/homeassistant/components/dunehd/config_flow.py @@ -2,9 +2,8 @@ from __future__ import annotations import ipaddress -import logging import re -from typing import Any, Final +from typing import Any from pdunehd import DuneHDPlayer import voluptuous as vol @@ -15,8 +14,6 @@ from homeassistant.data_entry_flow import FlowResult from .const import DOMAIN -_LOGGER: Final = logging.getLogger(__name__) - def host_valid(host: str) -> bool: """Return True if hostname or IP address is valid.""" @@ -72,29 +69,6 @@ class DuneHDConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): errors=errors, ) - async def async_step_import( - self, user_input: dict[str, str] | None = None - ) -> FlowResult: - """Handle configuration by yaml file.""" - _LOGGER.warning( - "Configuration of the Dune HD integration in YAML is deprecated and will be " - "removed in Home Assistant 2022.6; Your existing configuration " - "has been imported into the UI automatically and can be safely removed " - "from your configuration.yaml file" - ) - assert user_input is not None - host: str = user_input[CONF_HOST] - - self._async_abort_entries_match({CONF_HOST: host}) - - try: - await self.init_device(host) - except CannotConnect: - _LOGGER.error("Import aborted, cannot connect to %s", host) - return self.async_abort(reason="cannot_connect") - else: - return self.async_create_entry(title=host, data=user_input) - def host_already_configured(self, host: str) -> bool: """See if we already have a dunehd entry matching user input configured.""" existing_hosts = { diff --git a/homeassistant/components/dunehd/media_player.py b/homeassistant/components/dunehd/media_player.py index d39d148e5a5..f6d90b7b1d9 100644 --- a/homeassistant/components/dunehd/media_player.py +++ b/homeassistant/components/dunehd/media_player.py @@ -4,40 +4,21 @@ from __future__ import annotations from typing import Any, Final from pdunehd import DuneHDPlayer -import voluptuous as vol from homeassistant.components.media_player import ( - PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA, MediaPlayerEntity, MediaPlayerEntityFeature, ) -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import ( - CONF_HOST, - CONF_NAME, - STATE_OFF, - STATE_ON, - STATE_PAUSED, - STATE_PLAYING, -) +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import STATE_OFF, STATE_ON, STATE_PAUSED, STATE_PLAYING from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from .const import ATTR_MANUFACTURER, DEFAULT_NAME, DOMAIN CONF_SOURCES: Final = "sources" -PLATFORM_SCHEMA: Final = PARENT_PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_HOST): cv.string, - vol.Optional(CONF_SOURCES): vol.Schema({cv.string: cv.string}), - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - } -) - DUNEHD_PLAYER_SUPPORT: Final[int] = ( MediaPlayerEntityFeature.PAUSE | MediaPlayerEntityFeature.TURN_ON @@ -48,22 +29,6 @@ DUNEHD_PLAYER_SUPPORT: Final[int] = ( ) -async def async_setup_platform( - hass: HomeAssistant, - config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType | None = None, -) -> None: - """Set up the Dune HD media player platform.""" - host: str = config[CONF_HOST] - - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data={CONF_HOST: host} - ) - ) - - async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback ) -> None: diff --git a/tests/components/dunehd/test_config_flow.py b/tests/components/dunehd/test_config_flow.py index 73732236077..76585ac73a1 100644 --- a/tests/components/dunehd/test_config_flow.py +++ b/tests/components/dunehd/test_config_flow.py @@ -3,7 +3,7 @@ from unittest.mock import patch from homeassistant import data_entry_flow from homeassistant.components.dunehd.const import DOMAIN -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER +from homeassistant.config_entries import SOURCE_USER from homeassistant.const import CONF_HOST from tests.common import MockConfigEntry @@ -14,49 +14,6 @@ CONFIG_IP = {CONF_HOST: "10.10.10.12"} DUNEHD_STATE = {"protocol_version": "4", "player_state": "navigator"} -async def test_import(hass): - """Test that the import works.""" - with patch("homeassistant.components.dunehd.async_setup_entry"), patch( - "pdunehd.DuneHDPlayer.update_state", return_value=DUNEHD_STATE - ): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=CONFIG_HOSTNAME - ) - - assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY - assert result["title"] == "dunehd-host" - assert result["data"] == {CONF_HOST: "dunehd-host"} - - -async def test_import_cannot_connect(hass): - """Test that errors are shown when cannot connect to the host during import.""" - with patch("pdunehd.DuneHDPlayer.update_state", return_value={}): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=CONFIG_HOSTNAME - ) - - assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "cannot_connect" - - -async def test_import_duplicate_error(hass): - """Test that errors are shown when duplicates are added during import.""" - config_entry = MockConfigEntry( - domain=DOMAIN, - data={CONF_HOST: "dunehd-host"}, - title="dunehd-host", - ) - config_entry.add_to_hass(hass) - - with patch("pdunehd.DuneHDPlayer.update_state", return_value=DUNEHD_STATE): - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data=CONFIG_HOSTNAME - ) - - assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT - assert result["reason"] == "already_configured" - - async def test_user_invalid_host(hass): """Test that errors are shown when the host is invalid.""" result = await hass.config_entries.flow.async_init(