Remove deprecated YAML config from sonarr (#41904)
parent
b39d82c154
commit
243a4e5df6
|
@ -73,12 +73,6 @@ class SonarrConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
"""Get the options flow for this handler."""
|
||||
return SonarrOptionsFlowHandler(config_entry)
|
||||
|
||||
async def async_step_import(
|
||||
self, user_input: Optional[ConfigType] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""Handle a flow initiated by configuration file."""
|
||||
return await self.async_step_user(user_input)
|
||||
|
||||
async def async_step_reauth(
|
||||
self, data: Optional[ConfigType] = None
|
||||
) -> Dict[str, Any]:
|
||||
|
|
|
@ -4,113 +4,19 @@ import logging
|
|||
from typing import Any, Callable, Dict, List, Optional
|
||||
|
||||
from sonarr import Sonarr, SonarrConnectionError, SonarrError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY,
|
||||
CONF_HOST,
|
||||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
CONF_VERIFY_SSL,
|
||||
DATA_BYTES,
|
||||
DATA_EXABYTES,
|
||||
DATA_GIGABYTES,
|
||||
DATA_KILOBYTES,
|
||||
DATA_MEGABYTES,
|
||||
DATA_PETABYTES,
|
||||
DATA_TERABYTES,
|
||||
DATA_YOTTABYTES,
|
||||
DATA_ZETTABYTES,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DATA_GIGABYTES
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from . import SonarrEntity
|
||||
from .const import (
|
||||
CONF_BASE_PATH,
|
||||
CONF_DAYS,
|
||||
CONF_INCLUDED,
|
||||
CONF_UNIT,
|
||||
CONF_UPCOMING_DAYS,
|
||||
CONF_URLBASE,
|
||||
CONF_WANTED_MAX_ITEMS,
|
||||
DATA_SONARR,
|
||||
DEFAULT_BASE_PATH,
|
||||
DEFAULT_HOST,
|
||||
DEFAULT_PORT,
|
||||
DEFAULT_SSL,
|
||||
DOMAIN,
|
||||
)
|
||||
from .const import CONF_UPCOMING_DAYS, CONF_WANTED_MAX_ITEMS, DATA_SONARR, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
BYTE_SIZES = [
|
||||
DATA_BYTES,
|
||||
DATA_KILOBYTES,
|
||||
DATA_MEGABYTES,
|
||||
DATA_GIGABYTES,
|
||||
DATA_TERABYTES,
|
||||
DATA_PETABYTES,
|
||||
DATA_EXABYTES,
|
||||
DATA_ZETTABYTES,
|
||||
DATA_YOTTABYTES,
|
||||
]
|
||||
|
||||
DEFAULT_URLBASE = ""
|
||||
DEFAULT_DAYS = "1"
|
||||
DEFAULT_UNIT = DATA_GIGABYTES
|
||||
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
cv.deprecated(CONF_INCLUDED, invalidation_version="0.112"),
|
||||
cv.deprecated(CONF_MONITORED_CONDITIONS, invalidation_version="0.112"),
|
||||
cv.deprecated(CONF_UNIT, invalidation_version="0.112"),
|
||||
PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Optional(CONF_DAYS, default=DEFAULT_DAYS): cv.string,
|
||||
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
|
||||
vol.Optional(CONF_INCLUDED, default=[]): cv.ensure_list,
|
||||
vol.Optional(CONF_MONITORED_CONDITIONS, default=[]): cv.ensure_list,
|
||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
|
||||
vol.Optional(CONF_UNIT, default=DEFAULT_UNIT): vol.In(BYTE_SIZES),
|
||||
vol.Optional(CONF_URLBASE, default=DEFAULT_URLBASE): cv.string,
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistantType,
|
||||
config: ConfigType,
|
||||
async_add_entities: Callable[[List[Entity], bool], None],
|
||||
discovery_info: Any = None,
|
||||
) -> None:
|
||||
"""Import the platform into a config entry."""
|
||||
if len(hass.config_entries.async_entries(DOMAIN)) > 0:
|
||||
return True
|
||||
|
||||
config[CONF_BASE_PATH] = f"{config[CONF_URLBASE]}{DEFAULT_BASE_PATH}"
|
||||
config[CONF_UPCOMING_DAYS] = int(config[CONF_DAYS])
|
||||
config[CONF_VERIFY_SSL] = False
|
||||
|
||||
del config[CONF_DAYS]
|
||||
del config[CONF_INCLUDED]
|
||||
del config[CONF_MONITORED_CONDITIONS]
|
||||
del config[CONF_URLBASE]
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistantType,
|
||||
|
@ -259,10 +165,6 @@ class SonarrDiskspaceSensor(SonarrSensor):
|
|||
enabled_default=False,
|
||||
)
|
||||
|
||||
def _to_unit(self, value):
|
||||
"""Return a value converted to unit of measurement."""
|
||||
return value / 1024 ** BYTE_SIZES.index(self._unit_of_measurement)
|
||||
|
||||
@sonarr_exception_handler
|
||||
async def async_update(self) -> None:
|
||||
"""Update entity."""
|
||||
|
@ -276,8 +178,8 @@ class SonarrDiskspaceSensor(SonarrSensor):
|
|||
attrs = {}
|
||||
|
||||
for disk in self._disks:
|
||||
free = self._to_unit(disk.free)
|
||||
total = self._to_unit(disk.total)
|
||||
free = disk.free / 1024 ** 3
|
||||
total = disk.total / 1024 ** 3
|
||||
usage = free / total * 100
|
||||
|
||||
attrs[
|
||||
|
@ -289,7 +191,7 @@ class SonarrDiskspaceSensor(SonarrSensor):
|
|||
@property
|
||||
def state(self) -> str:
|
||||
"""Return the state of the sensor."""
|
||||
free = self._to_unit(self._total_free)
|
||||
free = self._total_free / 1024 ** 3
|
||||
return f"{free:.2f}"
|
||||
|
||||
|
||||
|
|
|
@ -28,13 +28,6 @@ PORT = 8989
|
|||
BASE_PATH = "/api"
|
||||
API_KEY = "MOCK_API_KEY"
|
||||
|
||||
MOCK_SENSOR_CONFIG = {
|
||||
"platform": DOMAIN,
|
||||
"host": HOST,
|
||||
"api_key": API_KEY,
|
||||
"days": 3,
|
||||
}
|
||||
|
||||
MOCK_REAUTH_INPUT = {CONF_API_KEY: "test-api-key-reauth"}
|
||||
|
||||
MOCK_USER_INPUT = {
|
||||
|
|
|
@ -6,7 +6,7 @@ from homeassistant.components.sonarr.const import (
|
|||
DEFAULT_WANTED_MAX_ITEMS,
|
||||
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_API_KEY, CONF_HOST, CONF_SOURCE, CONF_VERIFY_SSL
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
|
@ -96,28 +96,6 @@ async def test_unknown_error(
|
|||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_full_import_flow_implementation(
|
||||
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test the full manual import flow from start to finish."""
|
||||
mock_connection(aioclient_mock)
|
||||
|
||||
user_input = MOCK_USER_INPUT.copy()
|
||||
|
||||
with _patch_async_setup(), _patch_async_setup_entry():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={CONF_SOURCE: SOURCE_IMPORT},
|
||||
data=user_input,
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == HOST
|
||||
|
||||
assert result["data"]
|
||||
assert result["data"][CONF_HOST] == HOST
|
||||
|
||||
|
||||
async def test_full_reauth_flow_implementation(
|
||||
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
|
|
|
@ -4,8 +4,7 @@ from datetime import timedelta
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.sonarr.const import CONF_BASE_PATH, DOMAIN
|
||||
from homeassistant.config_entries import ENTRY_STATE_LOADED
|
||||
from homeassistant.components.sonarr.const import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_ICON,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
|
@ -13,42 +12,16 @@ from homeassistant.const import (
|
|||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.components.sonarr import (
|
||||
MOCK_SENSOR_CONFIG,
|
||||
_patch_async_setup,
|
||||
_patch_async_setup_entry,
|
||||
mock_connection,
|
||||
setup_integration,
|
||||
)
|
||||
from tests.components.sonarr import mock_connection, setup_integration
|
||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
||||
|
||||
UPCOMING_ENTITY_ID = f"{SENSOR_DOMAIN}.sonarr_upcoming"
|
||||
|
||||
|
||||
async def test_import_from_sensor_component(
|
||||
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
"""Test import from sensor platform."""
|
||||
mock_connection(aioclient_mock)
|
||||
|
||||
with _patch_async_setup(), _patch_async_setup_entry():
|
||||
assert await async_setup_component(
|
||||
hass, SENSOR_DOMAIN, {SENSOR_DOMAIN: MOCK_SENSOR_CONFIG}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
|
||||
assert entries[0].state == ENTRY_STATE_LOADED
|
||||
assert entries[0].data[CONF_BASE_PATH] == "/api"
|
||||
|
||||
|
||||
async def test_sensors(
|
||||
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
|
||||
) -> None:
|
||||
|
|
Loading…
Reference in New Issue