mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Remove invalidation_version from deprecated (#44156)
* Remove invalidation_version from deprecated. We don't follow up and just hurts releases * Revert change to ZHA
This commit is contained in:
parent
76d6b55ff4
commit
594e905742
@ -23,7 +23,7 @@ from .const import (
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.115")
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def _await_cancel(task):
|
async def _await_cancel(task):
|
||||||
|
@ -32,7 +32,7 @@ from .helpers import async_get_blueprints
|
|||||||
_CONDITION_SCHEMA = vol.All(cv.ensure_list, [cv.CONDITION_SCHEMA])
|
_CONDITION_SCHEMA = vol.All(cv.ensure_list, [cv.CONDITION_SCHEMA])
|
||||||
|
|
||||||
PLATFORM_SCHEMA = vol.All(
|
PLATFORM_SCHEMA = vol.All(
|
||||||
cv.deprecated(CONF_HIDE_ENTITY, invalidation_version="0.110"),
|
cv.deprecated(CONF_HIDE_ENTITY),
|
||||||
script.make_script_schema(
|
script.make_script_schema(
|
||||||
{
|
{
|
||||||
# str on purpose
|
# str on purpose
|
||||||
|
@ -30,7 +30,7 @@ from .coordinator import CanaryDataUpdateCoordinator
|
|||||||
MIN_TIME_BETWEEN_SESSION_RENEW = timedelta(seconds=90)
|
MIN_TIME_BETWEEN_SESSION_RENEW = timedelta(seconds=90)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = vol.All(
|
PLATFORM_SCHEMA = vol.All(
|
||||||
cv.deprecated(CONF_FFMPEG_ARGUMENTS, invalidation_version="0.118"),
|
cv.deprecated(CONF_FFMPEG_ARGUMENTS),
|
||||||
PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
|
@ -33,10 +33,10 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
DOMAIN: vol.All(
|
DOMAIN: vol.All(
|
||||||
cv.deprecated(CONF_EMAIL, invalidation_version="0.119"),
|
cv.deprecated(CONF_EMAIL),
|
||||||
cv.deprecated(CONF_API_KEY, invalidation_version="0.119"),
|
cv.deprecated(CONF_API_KEY),
|
||||||
cv.deprecated(CONF_ZONE, invalidation_version="0.119"),
|
cv.deprecated(CONF_ZONE),
|
||||||
cv.deprecated(CONF_RECORDS, invalidation_version="0.119"),
|
cv.deprecated(CONF_RECORDS),
|
||||||
vol.Schema(
|
vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional(CONF_EMAIL): cv.string,
|
vol.Optional(CONF_EMAIL): cv.string,
|
||||||
|
@ -30,7 +30,7 @@ COMPONENT_TYPES = ["climate", "sensor", "switch"]
|
|||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
vol.All(
|
vol.All(
|
||||||
cv.deprecated(DOMAIN, invalidation_version="0.113.0"),
|
cv.deprecated(DOMAIN),
|
||||||
{
|
{
|
||||||
DOMAIN: vol.Schema(
|
DOMAIN: vol.Schema(
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.120")
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
|
|
||||||
PLATFORMS = ["media_player", "remote"]
|
PLATFORMS = ["media_player", "remote"]
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
|
@ -20,7 +20,7 @@ from .const import (
|
|||||||
|
|
||||||
DEFAULT_UPDATE_INTERVAL = timedelta(minutes=30)
|
DEFAULT_UPDATE_INTERVAL = timedelta(minutes=30)
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.119")
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
|
|
||||||
PLATFORMS = ["sensor"]
|
PLATFORMS = ["sensor"]
|
||||||
|
|
||||||
|
@ -80,13 +80,13 @@ SUPPORT_HYPERION = SUPPORT_COLOR | SUPPORT_BRIGHTNESS | SUPPORT_EFFECT
|
|||||||
|
|
||||||
# Usage of YAML for configuration of the Hyperion component is deprecated.
|
# Usage of YAML for configuration of the Hyperion component is deprecated.
|
||||||
PLATFORM_SCHEMA = vol.All(
|
PLATFORM_SCHEMA = vol.All(
|
||||||
cv.deprecated(CONF_HDMI_PRIORITY, invalidation_version="0.118"),
|
cv.deprecated(CONF_HDMI_PRIORITY),
|
||||||
cv.deprecated(CONF_HOST),
|
cv.deprecated(CONF_HOST),
|
||||||
cv.deprecated(CONF_PORT),
|
cv.deprecated(CONF_PORT),
|
||||||
cv.deprecated(CONF_DEFAULT_COLOR, invalidation_version="0.118"),
|
cv.deprecated(CONF_DEFAULT_COLOR),
|
||||||
cv.deprecated(CONF_NAME),
|
cv.deprecated(CONF_NAME),
|
||||||
cv.deprecated(CONF_PRIORITY),
|
cv.deprecated(CONF_PRIORITY),
|
||||||
cv.deprecated(CONF_EFFECT_LIST, invalidation_version="0.118"),
|
cv.deprecated(CONF_EFFECT_LIST),
|
||||||
PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
@ -11,7 +11,7 @@ from .const import DOMAIN, PLATFORM
|
|||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
DOMAIN: vol.All(
|
DOMAIN: vol.All(
|
||||||
cv.deprecated(CONF_NAME, invalidation_version="0.110"),
|
cv.deprecated(CONF_NAME),
|
||||||
vol.Schema({vol.Optional(CONF_NAME, default=DOMAIN): cv.string}),
|
vol.Schema({vol.Optional(CONF_NAME, default=DOMAIN): cv.string}),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -191,7 +191,7 @@ def embedded_broker_deprecated(value):
|
|||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
DOMAIN: vol.All(
|
DOMAIN: vol.All(
|
||||||
cv.deprecated(CONF_TLS_VERSION, invalidation_version="0.115"),
|
cv.deprecated(CONF_TLS_VERSION),
|
||||||
vol.Schema(
|
vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional(CONF_CLIENT_ID): cv.string,
|
vol.Optional(CONF_CLIENT_ID): cv.string,
|
||||||
|
@ -30,7 +30,7 @@ ATTR_SYSTEM_NAME = "system_name"
|
|||||||
DEFAULT_ATTRIBUTION = "Data provided by Notion"
|
DEFAULT_ATTRIBUTION = "Data provided by Notion"
|
||||||
DEFAULT_SCAN_INTERVAL = timedelta(minutes=1)
|
DEFAULT_SCAN_INTERVAL = timedelta(minutes=1)
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.119")
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
||||||
|
@ -74,7 +74,7 @@ SERVICE_STOP_PROGRAM_SCHEMA = vol.Schema(
|
|||||||
|
|
||||||
SERVICE_STOP_ZONE_SCHEMA = vol.Schema({vol.Required(CONF_ZONE_ID): cv.positive_int})
|
SERVICE_STOP_ZONE_SCHEMA = vol.Schema({vol.Required(CONF_ZONE_ID): cv.positive_int})
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.119")
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
|
|
||||||
PLATFORMS = ["binary_sensor", "sensor", "switch"]
|
PLATFORMS = ["binary_sensor", "sensor", "switch"]
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ from .const import (
|
|||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.120")
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
|
|
||||||
PLATFORMS = [MEDIA_PLAYER_DOMAIN, REMOTE_DOMAIN]
|
PLATFORMS = [MEDIA_PLAYER_DOMAIN, REMOTE_DOMAIN]
|
||||||
SCAN_INTERVAL = timedelta(seconds=15)
|
SCAN_INTERVAL = timedelta(seconds=15)
|
||||||
|
@ -33,7 +33,7 @@ from .const import (
|
|||||||
ENTITY_COMPONENTS,
|
ENTITY_COMPONENTS,
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.117")
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
LOGGER_INFO_REGEX = re.compile(r"^(\w+)\.?(\w+)?\.?(\w+)?\.?(\w+)?(?:\..*)?$")
|
LOGGER_INFO_REGEX = re.compile(r"^(\w+)\.?(\w+)?\.?(\w+)?\.?(\w+)?(?:\..*)?$")
|
||||||
|
@ -138,7 +138,7 @@ SERVICE_SET_SYSTEM_PROPERTIES_SCHEMA = SERVICE_BASE_SCHEMA.extend(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.119")
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -40,7 +40,7 @@ DOMAIN = const.DOMAIN
|
|||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
DOMAIN: vol.All(
|
DOMAIN: vol.All(
|
||||||
cv.deprecated(const.CONF_PROFILES, invalidation_version="0.114"),
|
cv.deprecated(const.CONF_PROFILES),
|
||||||
vol.Schema(
|
vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_CLIENT_ID): vol.All(cv.string, vol.Length(min=1)),
|
vol.Required(CONF_CLIENT_ID): vol.All(cv.string, vol.Length(min=1)),
|
||||||
|
@ -254,8 +254,10 @@ class ZHADevice(LogMixin):
|
|||||||
"device_event_type": "device_offline"
|
"device_event_type": "device_offline"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasattr(self._zigpy_device, "device_automation_triggers"):
|
if hasattr(self._zigpy_device, "device_automation_triggers"):
|
||||||
triggers.update(self._zigpy_device.device_automation_triggers)
|
triggers.update(self._zigpy_device.device_automation_triggers)
|
||||||
|
|
||||||
return triggers
|
return triggers
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -28,7 +28,6 @@ from typing import (
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from pkg_resources import parse_version
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
import voluptuous_serialize
|
import voluptuous_serialize
|
||||||
|
|
||||||
@ -80,7 +79,6 @@ from homeassistant.const import (
|
|||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
TEMP_FAHRENHEIT,
|
TEMP_FAHRENHEIT,
|
||||||
WEEKDAYS,
|
WEEKDAYS,
|
||||||
__version__,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import split_entity_id, valid_entity_id
|
from homeassistant.core import split_entity_id, valid_entity_id
|
||||||
from homeassistant.exceptions import TemplateError
|
from homeassistant.exceptions import TemplateError
|
||||||
@ -712,7 +710,6 @@ class multi_select:
|
|||||||
def deprecated(
|
def deprecated(
|
||||||
key: str,
|
key: str,
|
||||||
replacement_key: Optional[str] = None,
|
replacement_key: Optional[str] = None,
|
||||||
invalidation_version: Optional[str] = None,
|
|
||||||
default: Optional[Any] = None,
|
default: Optional[Any] = None,
|
||||||
) -> Callable[[Dict], Dict]:
|
) -> Callable[[Dict], Dict]:
|
||||||
"""
|
"""
|
||||||
@ -725,8 +722,6 @@ def deprecated(
|
|||||||
- No warning if only replacement_key provided
|
- No warning if only replacement_key provided
|
||||||
- No warning if neither key nor replacement_key are provided
|
- No warning if neither key nor replacement_key are provided
|
||||||
- Adds replacement_key with default value in this case
|
- Adds replacement_key with default value in this case
|
||||||
- Once the invalidation_version is crossed, raises vol.Invalid if key
|
|
||||||
is detected
|
|
||||||
"""
|
"""
|
||||||
module = inspect.getmodule(inspect.stack()[1][0])
|
module = inspect.getmodule(inspect.stack()[1][0])
|
||||||
if module is not None:
|
if module is not None:
|
||||||
@ -737,56 +732,24 @@ def deprecated(
|
|||||||
# https://github.com/home-assistant/core/issues/24982
|
# https://github.com/home-assistant/core/issues/24982
|
||||||
module_name = __name__
|
module_name = __name__
|
||||||
|
|
||||||
if replacement_key and invalidation_version:
|
if replacement_key:
|
||||||
warning = (
|
|
||||||
"The '{key}' option is deprecated,"
|
|
||||||
" please replace it with '{replacement_key}'."
|
|
||||||
" This option {invalidation_status} invalid in version"
|
|
||||||
" {invalidation_version}"
|
|
||||||
)
|
|
||||||
elif replacement_key:
|
|
||||||
warning = (
|
warning = (
|
||||||
"The '{key}' option is deprecated,"
|
"The '{key}' option is deprecated,"
|
||||||
" please replace it with '{replacement_key}'"
|
" please replace it with '{replacement_key}'"
|
||||||
)
|
)
|
||||||
elif invalidation_version:
|
|
||||||
warning = (
|
|
||||||
"The '{key}' option is deprecated,"
|
|
||||||
" please remove it from your configuration."
|
|
||||||
" This option {invalidation_status} invalid in version"
|
|
||||||
" {invalidation_version}"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
warning = (
|
warning = (
|
||||||
"The '{key}' option is deprecated,"
|
"The '{key}' option is deprecated,"
|
||||||
" please remove it from your configuration"
|
" please remove it from your configuration"
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_for_invalid_version() -> None:
|
|
||||||
"""Raise error if current version has reached invalidation."""
|
|
||||||
if not invalidation_version:
|
|
||||||
return
|
|
||||||
|
|
||||||
if parse_version(__version__) >= parse_version(invalidation_version):
|
|
||||||
raise vol.Invalid(
|
|
||||||
warning.format(
|
|
||||||
key=key,
|
|
||||||
replacement_key=replacement_key,
|
|
||||||
invalidation_status="became",
|
|
||||||
invalidation_version=invalidation_version,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def validator(config: Dict) -> Dict:
|
def validator(config: Dict) -> Dict:
|
||||||
"""Check if key is in config and log warning."""
|
"""Check if key is in config and log warning."""
|
||||||
if key in config:
|
if key in config:
|
||||||
check_for_invalid_version()
|
|
||||||
KeywordStyleAdapter(logging.getLogger(module_name)).warning(
|
KeywordStyleAdapter(logging.getLogger(module_name)).warning(
|
||||||
warning,
|
warning,
|
||||||
key=key,
|
key=key,
|
||||||
replacement_key=replacement_key,
|
replacement_key=replacement_key,
|
||||||
invalidation_status="will become",
|
|
||||||
invalidation_version=invalidation_version,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
value = config[key]
|
value = config[key]
|
||||||
|
@ -698,116 +698,6 @@ def test_deprecated_with_replacement_key(caplog, schema):
|
|||||||
assert test_data == output
|
assert test_data == output
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_with_invalidation_version(caplog, schema, version):
|
|
||||||
"""
|
|
||||||
Test deprecation behaves correctly with only an invalidation_version.
|
|
||||||
|
|
||||||
Expected behavior:
|
|
||||||
- Outputs the appropriate deprecation warning if key is detected
|
|
||||||
- Processes schema without changing any values
|
|
||||||
- No warning or difference in output if key is not provided
|
|
||||||
- Once the invalidation_version is crossed, raises vol.Invalid if key
|
|
||||||
is detected
|
|
||||||
"""
|
|
||||||
deprecated_schema = vol.All(
|
|
||||||
cv.deprecated("mars", invalidation_version="9999.99.9"), schema
|
|
||||||
)
|
|
||||||
|
|
||||||
message = (
|
|
||||||
"The 'mars' option is deprecated, "
|
|
||||||
"please remove it from your configuration. "
|
|
||||||
"This option will become invalid in version 9999.99.9"
|
|
||||||
)
|
|
||||||
|
|
||||||
test_data = {"mars": True}
|
|
||||||
output = deprecated_schema(test_data.copy())
|
|
||||||
assert len(caplog.records) == 1
|
|
||||||
assert message in caplog.text
|
|
||||||
assert test_data == output
|
|
||||||
|
|
||||||
caplog.clear()
|
|
||||||
assert len(caplog.records) == 0
|
|
||||||
|
|
||||||
test_data = {"venus": False}
|
|
||||||
output = deprecated_schema(test_data.copy())
|
|
||||||
assert len(caplog.records) == 0
|
|
||||||
assert test_data == output
|
|
||||||
|
|
||||||
invalidated_schema = vol.All(
|
|
||||||
cv.deprecated("mars", invalidation_version="0.1.0"), schema
|
|
||||||
)
|
|
||||||
test_data = {"mars": True}
|
|
||||||
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
|
||||||
invalidated_schema(test_data)
|
|
||||||
assert str(exc_info.value) == (
|
|
||||||
"The 'mars' option is deprecated, "
|
|
||||||
"please remove it from your configuration. This option became "
|
|
||||||
"invalid in version 0.1.0"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_with_replacement_key_and_invalidation_version(
|
|
||||||
caplog, schema, version
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Test deprecation behaves with a replacement key & invalidation_version.
|
|
||||||
|
|
||||||
Expected behavior:
|
|
||||||
- Outputs the appropriate deprecation warning if key is detected
|
|
||||||
- Processes schema moving the value from key to replacement_key
|
|
||||||
- Processes schema changing nothing if only replacement_key provided
|
|
||||||
- No warning if only replacement_key provided
|
|
||||||
- No warning or difference in output if neither key nor
|
|
||||||
replacement_key are provided
|
|
||||||
- Once the invalidation_version is crossed, raises vol.Invalid if key
|
|
||||||
is detected
|
|
||||||
"""
|
|
||||||
deprecated_schema = vol.All(
|
|
||||||
cv.deprecated(
|
|
||||||
"mars", replacement_key="jupiter", invalidation_version="9999.99.9"
|
|
||||||
),
|
|
||||||
schema,
|
|
||||||
)
|
|
||||||
|
|
||||||
warning = (
|
|
||||||
"The 'mars' option is deprecated, "
|
|
||||||
"please replace it with 'jupiter'. This option will become "
|
|
||||||
"invalid in version 9999.99.9"
|
|
||||||
)
|
|
||||||
|
|
||||||
test_data = {"mars": True}
|
|
||||||
output = deprecated_schema(test_data.copy())
|
|
||||||
assert len(caplog.records) == 1
|
|
||||||
assert warning in caplog.text
|
|
||||||
assert {"jupiter": True} == output
|
|
||||||
|
|
||||||
caplog.clear()
|
|
||||||
assert len(caplog.records) == 0
|
|
||||||
|
|
||||||
test_data = {"jupiter": True}
|
|
||||||
output = deprecated_schema(test_data.copy())
|
|
||||||
assert len(caplog.records) == 0
|
|
||||||
assert test_data == output
|
|
||||||
|
|
||||||
test_data = {"venus": True}
|
|
||||||
output = deprecated_schema(test_data.copy())
|
|
||||||
assert len(caplog.records) == 0
|
|
||||||
assert test_data == output
|
|
||||||
|
|
||||||
invalidated_schema = vol.All(
|
|
||||||
cv.deprecated("mars", replacement_key="jupiter", invalidation_version="0.1.0"),
|
|
||||||
schema,
|
|
||||||
)
|
|
||||||
test_data = {"mars": True}
|
|
||||||
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
|
||||||
invalidated_schema(test_data)
|
|
||||||
assert str(exc_info.value) == (
|
|
||||||
"The 'mars' option is deprecated, "
|
|
||||||
"please replace it with 'jupiter'. This option became "
|
|
||||||
"invalid in version 0.1.0"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_with_default(caplog, schema):
|
def test_deprecated_with_default(caplog, schema):
|
||||||
"""
|
"""
|
||||||
Test deprecation behaves correctly with a default value.
|
Test deprecation behaves correctly with a default value.
|
||||||
@ -894,69 +784,6 @@ def test_deprecated_with_replacement_key_and_default(caplog, schema):
|
|||||||
assert {"jupiter": True} == output
|
assert {"jupiter": True} == output
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_with_replacement_key_invalidation_version_default(
|
|
||||||
caplog, schema, version
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Test deprecation with a replacement key, invalidation_version & default.
|
|
||||||
|
|
||||||
Expected behavior:
|
|
||||||
- Outputs the appropriate deprecation warning if key is detected
|
|
||||||
- Processes schema moving the value from key to replacement_key
|
|
||||||
- Processes schema changing nothing if only replacement_key provided
|
|
||||||
- No warning if only replacement_key provided
|
|
||||||
- No warning if neither key nor replacement_key are provided
|
|
||||||
- Adds replacement_key with default value in this case
|
|
||||||
- Once the invalidation_version is crossed, raises vol.Invalid if key
|
|
||||||
is detected
|
|
||||||
"""
|
|
||||||
deprecated_schema = vol.All(
|
|
||||||
cv.deprecated(
|
|
||||||
"mars",
|
|
||||||
replacement_key="jupiter",
|
|
||||||
invalidation_version="9999.99.9",
|
|
||||||
default=False,
|
|
||||||
),
|
|
||||||
schema,
|
|
||||||
)
|
|
||||||
|
|
||||||
test_data = {"mars": True}
|
|
||||||
output = deprecated_schema(test_data.copy())
|
|
||||||
assert len(caplog.records) == 1
|
|
||||||
assert (
|
|
||||||
"The 'mars' option is deprecated, "
|
|
||||||
"please replace it with 'jupiter'. This option will become "
|
|
||||||
"invalid in version 9999.99.9"
|
|
||||||
) in caplog.text
|
|
||||||
assert {"jupiter": True} == output
|
|
||||||
|
|
||||||
caplog.clear()
|
|
||||||
assert len(caplog.records) == 0
|
|
||||||
|
|
||||||
test_data = {"jupiter": True}
|
|
||||||
output = deprecated_schema(test_data.copy())
|
|
||||||
assert len(caplog.records) == 0
|
|
||||||
assert test_data == output
|
|
||||||
|
|
||||||
test_data = {"venus": True}
|
|
||||||
output = deprecated_schema(test_data.copy())
|
|
||||||
assert len(caplog.records) == 0
|
|
||||||
assert {"venus": True, "jupiter": False} == output
|
|
||||||
|
|
||||||
invalidated_schema = vol.All(
|
|
||||||
cv.deprecated("mars", replacement_key="jupiter", invalidation_version="0.1.0"),
|
|
||||||
schema,
|
|
||||||
)
|
|
||||||
test_data = {"mars": True}
|
|
||||||
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
|
||||||
invalidated_schema(test_data)
|
|
||||||
assert str(exc_info.value) == (
|
|
||||||
"The 'mars' option is deprecated, "
|
|
||||||
"please replace it with 'jupiter'. This option became "
|
|
||||||
"invalid in version 0.1.0"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_deprecated_cant_find_module():
|
def test_deprecated_cant_find_module():
|
||||||
"""Test if the current module cannot be inspected."""
|
"""Test if the current module cannot be inspected."""
|
||||||
with patch("inspect.getmodule", return_value=None):
|
with patch("inspect.getmodule", return_value=None):
|
||||||
@ -964,7 +791,6 @@ def test_deprecated_cant_find_module():
|
|||||||
cv.deprecated(
|
cv.deprecated(
|
||||||
"mars",
|
"mars",
|
||||||
replacement_key="jupiter",
|
replacement_key="jupiter",
|
||||||
invalidation_version="1.0.0",
|
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1116,7 +1116,7 @@ async def test_component_config_exceptions(hass, caplog):
|
|||||||
("non_existing", vol.Schema({"zone": int}), None),
|
("non_existing", vol.Schema({"zone": int}), None),
|
||||||
("zone", vol.Schema({}), None),
|
("zone", vol.Schema({}), None),
|
||||||
("plex", vol.Schema(vol.All({"plex": {"host": str}})), "dict"),
|
("plex", vol.Schema(vol.All({"plex": {"host": str}})), "dict"),
|
||||||
("openuv", cv.deprecated("openuv", invalidation_version="0.115"), None),
|
("openuv", cv.deprecated("openuv"), None),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_identify_config_schema(domain, schema, expected):
|
def test_identify_config_schema(domain, schema, expected):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user