Remove deprecated YAML configuration from Whois (#67163)

* Remove deprecated YAML configuration from Whois

* Clean up platform schema
This commit is contained in:
Franck Nijhof 2022-02-24 10:03:42 +01:00 committed by GitHub
parent 6bd21f05dc
commit 1d03313bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 101 deletions

View File

@ -13,7 +13,7 @@ from whois.exceptions import (
)
from homeassistant.config_entries import ConfigFlow
from homeassistant.const import CONF_DOMAIN, CONF_NAME
from homeassistant.const import CONF_DOMAIN
from homeassistant.data_entry_flow import FlowResult
from .const import DOMAIN
@ -69,12 +69,3 @@ class WhoisFlowHandler(ConfigFlow, domain=DOMAIN):
),
errors=errors,
)
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
"""Handle a flow initialized by importing a config."""
self.imported_name = config[CONF_NAME]
return await self.async_step_user(
user_input={
CONF_DOMAIN: config[CONF_DOMAIN],
}
)

View File

@ -14,8 +14,6 @@ LOGGER = logging.getLogger(__package__)
SCAN_INTERVAL = timedelta(hours=24)
DEFAULT_NAME = "Whois"
ATTR_EXPIRES = "expires"
ATTR_NAME_SERVERS = "name_servers"
ATTR_REGISTRAR = "registrar"

View File

@ -6,44 +6,25 @@ from dataclasses import dataclass
from datetime import datetime, timezone
from typing import cast
import voluptuous as vol
from whois import Domain
from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_DOMAIN, CONF_NAME, TIME_DAYS
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_DOMAIN, TIME_DAYS
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from .const import (
ATTR_EXPIRES,
ATTR_NAME_SERVERS,
ATTR_REGISTRAR,
ATTR_UPDATED,
DEFAULT_NAME,
DOMAIN,
LOGGER,
)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_DOMAIN): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}
)
from .const import ATTR_EXPIRES, ATTR_NAME_SERVERS, ATTR_REGISTRAR, ATTR_UPDATED, DOMAIN
@dataclass
@ -152,28 +133,6 @@ SENSORS: tuple[WhoisSensorEntityDescription, ...] = (
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the WHOIS sensor."""
LOGGER.warning(
"Configuration of the Whois platform in YAML is deprecated and will be "
"removed in Home Assistant 2022.4; Your existing configuration "
"has been imported into the UI automatically and can be safely removed "
"from your configuration.yaml file"
)
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_DOMAIN: config[CONF_DOMAIN], CONF_NAME: config[CONF_NAME]},
)
)
async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,

View File

@ -10,8 +10,8 @@ from whois.exceptions import (
)
from homeassistant.components.whois.const import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.const import CONF_DOMAIN, CONF_NAME
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import (
RESULT_TYPE_ABORT,
@ -124,24 +124,3 @@ async def test_already_configured(
assert result.get("reason") == "already_configured"
assert len(mock_setup_entry.mock_calls) == 0
async def test_import_flow(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
mock_whois_config_flow: MagicMock,
) -> None:
"""Test the import configuration flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_DOMAIN: "Example.com", CONF_NAME: "My Example Domain"},
)
assert result.get("type") == RESULT_TYPE_CREATE_ENTRY
assert result.get("title") == "My Example Domain"
assert result.get("data") == {
CONF_DOMAIN: "example.com",
}
assert len(mock_setup_entry.mock_calls) == 1

View File

@ -9,12 +9,9 @@ from whois.exceptions import (
WhoisCommandFailed,
)
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.whois.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry
@ -59,22 +56,3 @@ async def test_error_handling(
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
assert len(mock_whois.mock_calls) == 1
async def test_import_config(
hass: HomeAssistant,
mock_whois: MagicMock,
mock_whois_config_flow: MagicMock,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test the Whois being set up from config via import."""
assert await async_setup_component(
hass,
SENSOR_DOMAIN,
{SENSOR_DOMAIN: {"platform": DOMAIN, CONF_DOMAIN: "home-assistant.io"}},
)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert len(mock_whois.mock_calls) == 1
assert "the Whois platform in YAML is deprecated" in caplog.text