Remove YAML configuration from DuneHD (#71694)

This commit is contained in:
Franck Nijhof 2022-05-12 09:39:49 +02:00 committed by GitHub
parent 533257021c
commit 3ce19cd6f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 108 deletions

View file

@ -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 = {

View file

@ -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:

View file

@ -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(