Clean up deprecation message & config schema from Cloudflare (#50079)

pull/50102/head
Franck Nijhof 2021-05-05 07:56:50 +02:00 committed by GitHub
parent cc21de569d
commit 301d642ad8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 50 deletions

View File

@ -10,11 +10,9 @@ from pycfdns.exceptions import (
CloudflareConnectionException,
CloudflareException,
)
import voluptuous as vol
from homeassistant.components import persistent_notification
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, CONF_API_TOKEN, CONF_EMAIL, CONF_ZONE
from homeassistant.const import CONF_API_TOKEN, CONF_ZONE
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -31,43 +29,7 @@ from .const import (
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.All(
cv.deprecated(CONF_EMAIL),
cv.deprecated(CONF_API_KEY),
cv.deprecated(CONF_ZONE),
cv.deprecated(CONF_RECORDS),
vol.Schema(
{
vol.Optional(CONF_EMAIL): cv.string,
vol.Optional(CONF_API_KEY): cv.string,
vol.Optional(CONF_ZONE): cv.string,
vol.Optional(CONF_RECORDS): vol.All(cv.ensure_list, [cv.string]),
}
),
)
},
extra=vol.ALLOW_EXTRA,
)
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
"""Set up the component."""
hass.data.setdefault(DOMAIN, {})
if len(hass.config_entries.async_entries(DOMAIN)) > 0:
return True
if DOMAIN in config and CONF_API_KEY in config[DOMAIN]:
persistent_notification.async_create(
hass,
"Cloudflare integration now requires an API Token. Please go to the integrations page to setup.",
"Cloudflare Setup",
"cloudflare_setup",
)
return True
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@ -104,6 +66,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
update_interval = timedelta(minutes=DEFAULT_UPDATE_INTERVAL)
undo_interval = async_track_time_interval(hass, update_records, update_interval)
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = {
DATA_UNDO_UPDATE_INTERVAL: undo_interval,
}

View File

@ -88,13 +88,6 @@ def _get_mock_cfupdate(
return client
def _patch_async_setup(return_value=True):
return patch(
"homeassistant.components.cloudflare.async_setup",
return_value=return_value,
)
def _patch_async_setup_entry(return_value=True):
return patch(
"homeassistant.components.cloudflare.async_setup_entry",

View File

@ -20,7 +20,6 @@ from . import (
USER_INPUT,
USER_INPUT_RECORDS,
USER_INPUT_ZONE,
_patch_async_setup,
_patch_async_setup_entry,
)
@ -58,7 +57,7 @@ async def test_user_form(hass, cfupdate_flow):
assert result["step_id"] == "records"
assert result["errors"] == {}
with _patch_async_setup() as mock_setup, _patch_async_setup_entry() as mock_setup_entry:
with _patch_async_setup_entry() as mock_setup_entry:
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
USER_INPUT_RECORDS,
@ -76,7 +75,6 @@ async def test_user_form(hass, cfupdate_flow):
assert result["result"]
assert result["result"].unique_id == USER_INPUT_ZONE[CONF_ZONE]
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1