Remove deprecated yaml import from sabnzbd (#131052)

This commit is contained in:
Jan-Philipp Benecke 2024-11-20 18:36:20 +01:00 committed by GitHub
parent 94bf77606b
commit 771952d292
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 99 deletions

View File

@ -8,31 +8,18 @@ from typing import Any
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry, ConfigEntryState
from homeassistant.const import (
CONF_API_KEY,
CONF_HOST,
CONF_NAME,
CONF_PORT,
CONF_SENSORS,
CONF_SSL,
Platform,
)
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
from homeassistant.helpers import config_validation as cv, device_registry as dr
from homeassistant.helpers.entity_registry import RegistryEntry, async_migrate_entries
import homeassistant.helpers.issue_registry as ir
from homeassistant.helpers.typing import ConfigType
from .const import (
ATTR_API_KEY,
ATTR_SPEED,
DEFAULT_HOST,
DEFAULT_NAME,
DEFAULT_PORT,
DEFAULT_SPEED_LIMIT,
DEFAULT_SSL,
DOMAIN,
SERVICE_PAUSE,
SERVICE_RESUME,
@ -40,7 +27,6 @@ from .const import (
)
from .coordinator import SabnzbdUpdateCoordinator
from .sab import get_client
from .sensor import OLD_SENSOR_KEYS
PLATFORMS = [Platform.BUTTON, Platform.SENSOR]
_LOGGER = logging.getLogger(__name__)
@ -63,49 +49,6 @@ SERVICE_SPEED_SCHEMA = SERVICE_BASE_SCHEMA.extend(
}
)
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
vol.All(
cv.deprecated(CONF_HOST),
cv.deprecated(CONF_PORT),
cv.deprecated(CONF_SENSORS),
cv.deprecated(CONF_SSL),
{
vol.Required(CONF_API_KEY): str,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): str,
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_SENSORS): vol.All(
cv.ensure_list, [vol.In(OLD_SENSOR_KEYS)]
),
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
},
)
)
},
extra=vol.ALLOW_EXTRA,
)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the SABnzbd component."""
hass.data.setdefault(DOMAIN, {})
if hass.config_entries.async_entries(DOMAIN):
return True
if DOMAIN in config:
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data=config[DOMAIN],
)
)
return True
@callback
def async_get_entry_id_for_service_call(hass: HomeAssistant, call: ServiceCall) -> str:

View File

@ -7,15 +7,8 @@ import pytest
from homeassistant import config_entries
from homeassistant.components.sabnzbd import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.const import (
CONF_API_KEY,
CONF_HOST,
CONF_NAME,
CONF_PORT,
CONF_SSL,
CONF_URL,
)
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_API_KEY, CONF_NAME, CONF_URL
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -25,14 +18,6 @@ VALID_CONFIG = {
CONF_URL: "http://localhost:8080",
}
VALID_CONFIG_OLD = {
CONF_NAME: "Sabnzbd",
CONF_API_KEY: "edc3eee7330e4fdda04489e3fbc283d0",
CONF_HOST: "localhost",
CONF_PORT: 8080,
CONF_SSL: False,
}
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
@ -77,24 +62,3 @@ async def test_auth_error(hass: HomeAssistant) -> None:
)
assert result["errors"] == {"base": "cannot_connect"}
async def test_import_flow(hass: HomeAssistant) -> None:
"""Test the import configuration flow."""
with patch(
"homeassistant.components.sabnzbd.sab.SabnzbdApi.check_available",
return_value=True,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data=VALID_CONFIG_OLD,
)
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "edc3eee7330e"
assert result["data"][CONF_NAME] == "Sabnzbd"
assert result["data"][CONF_API_KEY] == "edc3eee7330e4fdda04489e3fbc283d0"
assert result["data"][CONF_HOST] == "localhost"
assert result["data"][CONF_PORT] == 8080
assert result["data"][CONF_SSL] is False

View File

@ -4,14 +4,14 @@ from unittest.mock import patch
import pytest
from homeassistant.components.sabnzbd import (
from homeassistant.components.sabnzbd.const import (
ATTR_API_KEY,
DEFAULT_NAME,
DOMAIN,
OLD_SENSOR_KEYS,
SERVICE_PAUSE,
SERVICE_RESUME,
)
from homeassistant.components.sabnzbd.sensor import OLD_SENSOR_KEYS
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import CONF_API_KEY, CONF_NAME, CONF_URL
from homeassistant.core import HomeAssistant