Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions homeassistant/components/dunehd/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,8 +14,6 @@

from .const import DOMAIN

_LOGGER: Final = logging.getLogger(__name__)


def host_valid(host: str) -> bool:
"""Return True if hostname or IP address is valid."""
Expand Down Expand Up @@ -72,29 +69,6 @@ async def async_step_user(
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 = {
Expand Down
39 changes: 2 additions & 37 deletions homeassistant/components/dunehd/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,21 @@
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
Expand All @@ -48,22 +29,6 @@
)


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:
Expand Down
45 changes: 1 addition & 44 deletions tests/components/dunehd/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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
Expand All @@ -14,49 +14,6 @@
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(
Expand Down