mirror of
https://github.com/home-assistant/core
synced 2024-09-03 08:14:07 +02:00
Remove deprecated yaml config from Deluge (#71487)
This commit is contained in:
parent
08856cfab0
commit
4db289ad6e
@ -1,7 +1,6 @@
|
||||
"""Config flow for the Deluge integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import socket
|
||||
from ssl import SSLError
|
||||
from typing import Any
|
||||
@ -12,8 +11,6 @@ import voluptuous as vol
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MONITORED_VARIABLES,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_SOURCE,
|
||||
@ -30,8 +27,6 @@ from .const import (
|
||||
DOMAIN,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DelugeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Deluge."""
|
||||
@ -41,11 +36,8 @@ class DelugeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
) -> FlowResult:
|
||||
"""Handle a flow initiated by the user."""
|
||||
errors = {}
|
||||
title = None
|
||||
|
||||
if user_input is not None:
|
||||
if CONF_NAME in user_input:
|
||||
title = user_input.pop(CONF_NAME)
|
||||
if (error := await self.validate_input(user_input)) is None:
|
||||
for entry in self._async_current_entries():
|
||||
if (
|
||||
@ -60,7 +52,7 @@ class DelugeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
return self.async_abort(reason="already_configured")
|
||||
return self.async_create_entry(
|
||||
title=title or DEFAULT_NAME,
|
||||
title=DEFAULT_NAME,
|
||||
data=user_input,
|
||||
)
|
||||
errors["base"] = error
|
||||
@ -87,20 +79,6 @@ class DelugeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a reauthorization flow request."""
|
||||
return await self.async_step_user()
|
||||
|
||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
if CONF_MONITORED_VARIABLES in config:
|
||||
config.pop(CONF_MONITORED_VARIABLES)
|
||||
config[CONF_WEB_PORT] = DEFAULT_WEB_PORT
|
||||
|
||||
for entry in self._async_current_entries():
|
||||
if entry.data[CONF_HOST] == config[CONF_HOST]:
|
||||
_LOGGER.warning(
|
||||
"Deluge yaml config has been imported. Please remove it"
|
||||
)
|
||||
return self.async_abort(reason="already_configured")
|
||||
return await self.async_step_user(config)
|
||||
|
||||
async def validate_input(self, user_input: dict[str, Any]) -> str | None:
|
||||
"""Handle common flow input validation."""
|
||||
host = user_input[CONF_HOST]
|
||||
|
@ -1,33 +1,19 @@
|
||||
"""Support for monitoring the Deluge BitTorrent client API."""
|
||||
from __future__ import annotations
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MONITORED_VARIABLES,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
DATA_RATE_KILOBYTES_PER_SECOND,
|
||||
STATE_IDLE,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DATA_RATE_KILOBYTES_PER_SECOND, STATE_IDLE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_platform
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import DelugeEntity
|
||||
from .const import DEFAULT_NAME, DEFAULT_RPC_PORT, DOMAIN
|
||||
from .const import DOMAIN
|
||||
from .coordinator import DelugeDataUpdateCoordinator
|
||||
|
||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
@ -49,36 +35,6 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||
),
|
||||
)
|
||||
|
||||
SENSOR_KEYS: list[str] = [desc.key for desc in SENSOR_TYPES]
|
||||
|
||||
# Deprecated in Home Assistant 2022.3
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_RPC_PORT): cv.port,
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_MONITORED_VARIABLES, default=[]): vol.All(
|
||||
cv.ensure_list, [vol.In(SENSOR_KEYS)]
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: entity_platform.AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Deluge sensor component."""
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
@ -3,52 +3,16 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_platform
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DelugeEntity
|
||||
from .const import DEFAULT_RPC_PORT, DOMAIN
|
||||
from .const import DOMAIN
|
||||
from .coordinator import DelugeDataUpdateCoordinator
|
||||
|
||||
# Deprecated in Home Assistant 2022.3
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_RPC_PORT): cv.port,
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Optional(CONF_NAME, default="Deluge Switch"): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: entity_platform.AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Deluge sensor component."""
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
@ -5,14 +5,7 @@ from homeassistant.components.deluge.const import (
|
||||
DEFAULT_RPC_PORT,
|
||||
DEFAULT_WEB_PORT,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_MONITORED_VARIABLES,
|
||||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME
|
||||
|
||||
CONF_DATA = {
|
||||
CONF_HOST: "1.2.3.4",
|
||||
@ -21,12 +14,3 @@ CONF_DATA = {
|
||||
CONF_PORT: DEFAULT_RPC_PORT,
|
||||
CONF_WEB_PORT: DEFAULT_WEB_PORT,
|
||||
}
|
||||
|
||||
IMPORT_DATA = {
|
||||
CONF_HOST: "1.2.3.4",
|
||||
CONF_NAME: "Deluge Torrent",
|
||||
CONF_MONITORED_VARIABLES: ["current_status", "download_speed", "upload_speed"],
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "password",
|
||||
CONF_PORT: DEFAULT_RPC_PORT,
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.deluge.const import DEFAULT_NAME, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_SOURCE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import (
|
||||
@ -13,7 +13,7 @@ from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_FORM,
|
||||
)
|
||||
|
||||
from . import CONF_DATA, IMPORT_DATA
|
||||
from . import CONF_DATA
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@ -102,33 +102,6 @@ async def test_flow_user_unknown_error(hass: HomeAssistant, unknown_error):
|
||||
assert result["errors"] == {"base": "unknown"}
|
||||
|
||||
|
||||
async def test_flow_import(hass: HomeAssistant, api):
|
||||
"""Test import step."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=IMPORT_DATA
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "Deluge Torrent"
|
||||
assert result["data"] == CONF_DATA
|
||||
|
||||
|
||||
async def test_flow_import_already_configured(hass: HomeAssistant, api):
|
||||
"""Test import step already configured."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=CONF_DATA,
|
||||
)
|
||||
|
||||
entry.add_to_hass(hass)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=IMPORT_DATA
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_flow_reauth(hass: HomeAssistant, api):
|
||||
"""Test reauth step."""
|
||||
entry = MockConfigEntry(
|
||||
|
Loading…
Reference in New Issue
Block a user