Remove deprecated YAML configuration from Stookalert (#61007)
This commit is contained in:
parent
eb5a321a9f
commit
e62148b8ff
3 changed files with 4 additions and 59 deletions
|
@ -4,59 +4,21 @@ from __future__ import annotations
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import stookalert
|
import stookalert
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
PLATFORM_SCHEMA,
|
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_NAME
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv
|
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|
||||||
|
|
||||||
from .const import CONF_PROVINCE, DOMAIN, LOGGER, PROVINCES
|
from .const import CONF_PROVINCE, DOMAIN
|
||||||
|
|
||||||
DEFAULT_NAME = "Stookalert"
|
|
||||||
ATTRIBUTION = "Data provided by rivm.nl"
|
|
||||||
SCAN_INTERVAL = timedelta(minutes=60)
|
SCAN_INTERVAL = timedelta(minutes=60)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_PROVINCE): vol.In(PROVINCES),
|
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Import the Stookalert platform into a config entry."""
|
|
||||||
LOGGER.warning(
|
|
||||||
"Configuration of the Stookalert platform in YAML is deprecated and will be "
|
|
||||||
"removed in Home Assistant 2022.1; 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_PROVINCE: config[CONF_PROVINCE],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -71,7 +33,7 @@ async def async_setup_entry(
|
||||||
class StookalertBinarySensor(BinarySensorEntity):
|
class StookalertBinarySensor(BinarySensorEntity):
|
||||||
"""Defines a Stookalert binary sensor."""
|
"""Defines a Stookalert binary sensor."""
|
||||||
|
|
||||||
_attr_attribution = ATTRIBUTION
|
_attr_attribution = "Data provided by rivm.nl"
|
||||||
_attr_device_class = BinarySensorDeviceClass.SAFETY
|
_attr_device_class = BinarySensorDeviceClass.SAFETY
|
||||||
|
|
||||||
def __init__(self, client: stookalert.stookalert, entry: ConfigEntry) -> None:
|
def __init__(self, client: stookalert.stookalert, entry: ConfigEntry) -> None:
|
||||||
|
|
|
@ -31,7 +31,3 @@ class StookalertFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=vol.Schema({vol.Required(CONF_PROVINCE): vol.In(PROVINCES)}),
|
data_schema=vol.Schema({vol.Required(CONF_PROVINCE): vol.In(PROVINCES)}),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
|
||||||
"""Handle a flow initialized by importing a config."""
|
|
||||||
return await self.async_step_user(config)
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.stookalert.const import CONF_PROVINCE, DOMAIN
|
from homeassistant.components.stookalert.const import CONF_PROVINCE, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import (
|
from homeassistant.data_entry_flow import (
|
||||||
RESULT_TYPE_ABORT,
|
RESULT_TYPE_ABORT,
|
||||||
|
@ -63,16 +63,3 @@ async def test_already_configured(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
assert result2.get("type") == RESULT_TYPE_ABORT
|
assert result2.get("type") == RESULT_TYPE_ABORT
|
||||||
assert result2.get("reason") == "already_configured"
|
assert result2.get("reason") == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow(hass: HomeAssistant) -> None:
|
|
||||||
"""Test the import configuration flow."""
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data={"province": "Overijssel"}
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result.get("type") == RESULT_TYPE_CREATE_ENTRY
|
|
||||||
assert result.get("title") == "Overijssel"
|
|
||||||
assert result.get("data") == {
|
|
||||||
CONF_PROVINCE: "Overijssel",
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue