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
87 changes: 1 addition & 86 deletions homeassistant/components/dlna_dmr/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@

from homeassistant import config_entries
from homeassistant.components import ssdp
from homeassistant.const import (
CONF_DEVICE_ID,
CONF_HOST,
CONF_NAME,
CONF_TYPE,
CONF_URL,
)
from homeassistant.const import CONF_DEVICE_ID, CONF_HOST, CONF_TYPE, CONF_URL
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import IntegrationError
Expand Down Expand Up @@ -125,85 +119,6 @@ async def async_step_manual(self, user_input: FlowInput = None) -> FlowResult:
step_id="manual", data_schema=data_schema, errors=errors
)

async def async_step_import(self, import_data: FlowInput = None) -> FlowResult:
"""Import a new DLNA DMR device from a config entry.

This flow is triggered by `async_setup_platform`. If the device has not
been migrated, and can be connected to, automatically import it. If it
cannot be connected to, prompt the user to turn it on. If it has already
been migrated, do nothing.
"""
LOGGER.debug("async_step_import: import_data: %s", import_data)

if not import_data or CONF_URL not in import_data:
LOGGER.debug("Entry not imported: incomplete_config")
return self.async_abort(reason="incomplete_config")

self._location = import_data[CONF_URL]
self._async_abort_entries_match({CONF_URL: self._location})

# Use the location as this config flow's unique ID until UDN is known
await self.async_set_unique_id(self._location)

# Set options from the import_data, except listen_ip which is no longer used
self._options[CONF_LISTEN_PORT] = import_data.get(CONF_LISTEN_PORT)
self._options[CONF_CALLBACK_URL_OVERRIDE] = import_data.get(
CONF_CALLBACK_URL_OVERRIDE
)

# Override device name if it's set in the YAML
self._name = import_data.get(CONF_NAME)

discoveries = await self._async_get_discoveries()

# Find the device in the list of unconfigured devices
for discovery in discoveries:
if discovery.ssdp_location == self._location:
# Device found via SSDP, it shouldn't need polling
self._options[CONF_POLL_AVAILABILITY] = False
# Discovery info has everything required to create config entry
await self._async_set_info_from_discovery(discovery)
LOGGER.debug(
"Entry %s found via SSDP, with UDN %s",
self._location,
self._udn,
)
return self._create_entry()

# This device will need to be polled
self._options[CONF_POLL_AVAILABILITY] = True

# Device was not found via SSDP, connect directly for configuration
try:
await self._async_connect()
except ConnectError as err:
# This will require user action
LOGGER.debug("Entry %s not imported yet: %s", self._location, err.args[0])
return await self.async_step_import_turn_on()

LOGGER.debug("Entry %s ready for import", self._location)
return self._create_entry()

async def async_step_import_turn_on(
self, user_input: FlowInput = None
) -> FlowResult:
"""Request the user to turn on the device so that import can finish."""
LOGGER.debug("async_step_import_turn_on: %s", user_input)

self.context["title_placeholders"] = {"name": self._name or self._location}

errors = {}
if user_input is not None:
try:
await self._async_connect()
except ConnectError as err:
errors["base"] = err.args[0]
else:
return self._create_entry()

self._set_confirm_only()
return self.async_show_form(step_id="import_turn_on", errors=errors)

async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
"""Handle a flow initialized by SSDP discovery."""
LOGGER.debug("async_step_ssdp: discovery_info %s", pformat(discovery_info))
Expand Down
48 changes: 1 addition & 47 deletions homeassistant/components/dlna_dmr/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
from async_upnp_client.exceptions import UpnpError, UpnpResponseError
from async_upnp_client.profiles.dlna import DmrDevice, PlayMode, TransportState
from async_upnp_client.utils import async_get_local_ip
import voluptuous as vol

from homeassistant import config_entries
from homeassistant.components import ssdp
from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity
from homeassistant.components.media_player import MediaPlayerEntity
from homeassistant.components.media_player.const import (
ATTR_MEDIA_EXTRA,
REPEAT_MODE_ALL,
Expand All @@ -38,7 +37,6 @@
)
from homeassistant.const import (
CONF_DEVICE_ID,
CONF_NAME,
CONF_TYPE,
CONF_URL,
STATE_IDLE,
Expand All @@ -49,9 +47,7 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry, entity_registry
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from .const import (
CONF_CALLBACK_URL_OVERRIDE,
Expand All @@ -69,25 +65,6 @@

PARALLEL_UPDATES = 0

# Configuration via YAML is deprecated in favour of config flow
CONF_LISTEN_IP = "listen_ip"
PLATFORM_SCHEMA = vol.All(
cv.deprecated(CONF_URL),
cv.deprecated(CONF_LISTEN_IP),
cv.deprecated(CONF_LISTEN_PORT),
cv.deprecated(CONF_NAME),
cv.deprecated(CONF_CALLBACK_URL_OVERRIDE),
PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_URL): cv.string,
vol.Optional(CONF_LISTEN_IP): cv.string,
vol.Optional(CONF_LISTEN_PORT): cv.port,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_CALLBACK_URL_OVERRIDE): cv.url,
}
),
)

Func = TypeVar("Func", bound=Callable[..., Any])


Expand All @@ -111,29 +88,6 @@ async def wrapper(self: "DlnaDmrEntity", *args: Any, **kwargs: Any) -> Any:
return cast(Func, wrapper)


async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up DLNA media_player platform."""
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=config,
)
)

_LOGGER.warning(
"Configuring dlna_dmr via yaml is deprecated; the configuration for"
" %s will be migrated to a config entry and can be safely removed when"
"migration is complete",
config.get(CONF_URL),
)


async def async_setup_entry(
hass: HomeAssistant,
entry: config_entries.ConfigEntry,
Expand Down
Loading