Remove deprecated YAML import for Tautulli (#74172)
This commit is contained in:
parent
21d28dd356
commit
29a546f4e8
4 changed files with 7 additions and 129 deletions
|
@ -4,36 +4,15 @@ from __future__ import annotations
|
|||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from pytautulli import (
|
||||
PyTautulli,
|
||||
PyTautulliException,
|
||||
PyTautulliHostConfiguration,
|
||||
exceptions,
|
||||
)
|
||||
from pytautulli import PyTautulli, PyTautulliException, exceptions
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import _LOGGER
|
||||
from homeassistant.config_entries import ConfigFlow
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_HOST,
|
||||
CONF_PATH,
|
||||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
CONF_URL,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL, CONF_VERIFY_SSL
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import (
|
||||
DEFAULT_NAME,
|
||||
DEFAULT_PATH,
|
||||
DEFAULT_PORT,
|
||||
DEFAULT_SSL,
|
||||
DEFAULT_VERIFY_SSL,
|
||||
DOMAIN,
|
||||
)
|
||||
from .const import DEFAULT_NAME, DOMAIN
|
||||
|
||||
|
||||
class TautulliConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
@ -95,33 +74,6 @@ class TautulliConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
_LOGGER.warning(
|
||||
"Configuration of the Tautulli platform in YAML is deprecated and will be "
|
||||
"removed in Home Assistant 2022.6; Your existing configuration for host %s"
|
||||
"has been imported into the UI automatically and can be safely removed "
|
||||
"from your configuration.yaml file",
|
||||
config[CONF_HOST],
|
||||
)
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason="single_instance_allowed")
|
||||
host_configuration = PyTautulliHostConfiguration(
|
||||
config[CONF_API_KEY],
|
||||
ipaddress=config[CONF_HOST],
|
||||
port=config.get(CONF_PORT, DEFAULT_PORT),
|
||||
ssl=config.get(CONF_SSL, DEFAULT_SSL),
|
||||
verify_ssl=config.get(CONF_VERIFY_SSL, DEFAULT_VERIFY_SSL),
|
||||
base_api_path=config.get(CONF_PATH, DEFAULT_PATH),
|
||||
)
|
||||
return await self.async_step_user(
|
||||
{
|
||||
CONF_API_KEY: host_configuration.api_token,
|
||||
CONF_URL: host_configuration.base_url,
|
||||
CONF_VERIFY_SSL: host_configuration.verify_ssl,
|
||||
}
|
||||
)
|
||||
|
||||
async def validate_input(self, user_input: dict[str, Any]) -> str | None:
|
||||
"""Try connecting to Tautulli."""
|
||||
try:
|
||||
|
|
|
@ -5,9 +5,5 @@ ATTR_TOP_USER = "top_user"
|
|||
|
||||
CONF_MONITORED_USERS = "monitored_users"
|
||||
DEFAULT_NAME = "Tautulli"
|
||||
DEFAULT_PATH = ""
|
||||
DEFAULT_PORT = "8181"
|
||||
DEFAULT_SSL = False
|
||||
DEFAULT_VERIFY_SSL = True
|
||||
DOMAIN = "tautulli"
|
||||
LOGGER: Logger = getLogger(__package__)
|
||||
|
|
|
@ -11,61 +11,23 @@ from pytautulli import (
|
|||
PyTautulliApiSession,
|
||||
PyTautulliApiUser,
|
||||
)
|
||||
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_API_KEY,
|
||||
CONF_HOST,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
CONF_PATH,
|
||||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
CONF_VERIFY_SSL,
|
||||
DATA_KILOBITS,
|
||||
PERCENTAGE,
|
||||
)
|
||||
from homeassistant.const import DATA_KILOBITS, PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import EntityCategory, EntityDescription
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
||||
|
||||
from . import TautulliEntity
|
||||
from .const import (
|
||||
ATTR_TOP_USER,
|
||||
CONF_MONITORED_USERS,
|
||||
DEFAULT_NAME,
|
||||
DEFAULT_PATH,
|
||||
DEFAULT_PORT,
|
||||
DEFAULT_SSL,
|
||||
DEFAULT_VERIFY_SSL,
|
||||
DOMAIN,
|
||||
)
|
||||
from .const import ATTR_TOP_USER, DOMAIN
|
||||
from .coordinator import TautulliDataUpdateCoordinator
|
||||
|
||||
# Deprecated in Home Assistant 2022.4
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS): vol.All(cv.ensure_list, [cv.string]),
|
||||
vol.Optional(CONF_MONITORED_USERS): vol.All(cv.ensure_list, [cv.string]),
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.string,
|
||||
vol.Optional(CONF_PATH, default=DEFAULT_PATH): cv.string,
|
||||
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
|
||||
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def get_top_stats(
|
||||
home_stats: PyTautulliApiHomeStats, activity: PyTautulliApiActivity, key: str
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from pytautulli import exceptions
|
||||
from pytest import LogCaptureFixture
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.tautulli.const import DEFAULT_NAME, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.components.tautulli.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_API_KEY, CONF_SOURCE
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
@ -127,37 +126,6 @@ async def test_flow_user_unknown_error(hass: HomeAssistant) -> None:
|
|||
assert result2["data"] == CONF_DATA
|
||||
|
||||
|
||||
async def test_flow_import(hass: HomeAssistant, caplog: LogCaptureFixture) -> None:
|
||||
"""Test import step."""
|
||||
with patch_config_flow_tautulli(AsyncMock()):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=CONF_IMPORT_DATA,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == DEFAULT_NAME
|
||||
assert result["data"] == CONF_DATA
|
||||
assert "Tautulli platform in YAML" in caplog.text
|
||||
|
||||
|
||||
async def test_flow_import_single_instance_allowed(hass: HomeAssistant) -> None:
|
||||
"""Test import step single instance allowed."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, data=CONF_DATA)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch_config_flow_tautulli(AsyncMock()):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=CONF_IMPORT_DATA,
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "single_instance_allowed"
|
||||
|
||||
|
||||
async def test_flow_reauth(
|
||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue