mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Improve (and align) deprecation messages (#147948)
This commit is contained in:
parent
528daad854
commit
76be2fdba1
@ -197,7 +197,7 @@ def _print_deprecation_warning_internal_impl(
|
||||
|
||||
logger = logging.getLogger(module_name)
|
||||
if breaks_in_ha_version:
|
||||
breaks_in = f" which will be removed in HA Core {breaks_in_ha_version}"
|
||||
breaks_in = f" It will be removed in HA Core {breaks_in_ha_version}."
|
||||
else:
|
||||
breaks_in = ""
|
||||
try:
|
||||
@ -205,9 +205,10 @@ def _print_deprecation_warning_internal_impl(
|
||||
except MissingIntegrationFrame:
|
||||
if log_when_no_integration_is_found:
|
||||
logger.warning(
|
||||
"%s is a deprecated %s%s. Use %s instead",
|
||||
obj_name,
|
||||
"The deprecated %s %s was %s.%s Use %s instead",
|
||||
description,
|
||||
obj_name,
|
||||
verb,
|
||||
breaks_in,
|
||||
replacement,
|
||||
)
|
||||
@ -219,25 +220,22 @@ def _print_deprecation_warning_internal_impl(
|
||||
module=integration_frame.module,
|
||||
)
|
||||
logger.warning(
|
||||
(
|
||||
"%s was %s from %s, this is a deprecated %s%s. Use %s instead,"
|
||||
" please %s"
|
||||
),
|
||||
("The deprecated %s %s was %s from %s.%s Use %s instead, please %s"),
|
||||
description,
|
||||
obj_name,
|
||||
verb,
|
||||
integration_frame.integration,
|
||||
description,
|
||||
breaks_in,
|
||||
replacement,
|
||||
report_issue,
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"%s was %s from %s, this is a deprecated %s%s. Use %s instead",
|
||||
"The deprecated %s %s was %s from %s.%s Use %s instead",
|
||||
description,
|
||||
obj_name,
|
||||
verb,
|
||||
integration_frame.integration,
|
||||
description,
|
||||
breaks_in,
|
||||
replacement,
|
||||
)
|
||||
|
@ -1826,9 +1826,9 @@ def import_and_test_deprecated_constant(
|
||||
module.__name__,
|
||||
logging.WARNING,
|
||||
(
|
||||
f"{constant_name} was used from test_constant_deprecation,"
|
||||
f" this is a deprecated constant which will be removed in HA Core {breaks_in_ha_version}. "
|
||||
f"Use {replacement_name} instead, please report "
|
||||
f"The deprecated constant {constant_name} was used from "
|
||||
"test_constant_deprecation. It will be removed in HA Core "
|
||||
f"{breaks_in_ha_version}. Use {replacement_name} instead, please report "
|
||||
"it to the author of the 'test_constant_deprecation' custom integration"
|
||||
),
|
||||
) in caplog.record_tuples
|
||||
@ -1860,9 +1860,9 @@ def import_and_test_deprecated_alias(
|
||||
module.__name__,
|
||||
logging.WARNING,
|
||||
(
|
||||
f"{alias_name} was used from test_constant_deprecation,"
|
||||
f" this is a deprecated alias which will be removed in HA Core {breaks_in_ha_version}. "
|
||||
f"Use {replacement_name} instead, please report "
|
||||
f"The deprecated alias {alias_name} was used from "
|
||||
"test_constant_deprecation. It will be removed in HA Core "
|
||||
f"{breaks_in_ha_version}. Use {replacement_name} instead, please report "
|
||||
"it to the author of the 'test_constant_deprecation' custom integration"
|
||||
),
|
||||
) in caplog.record_tuples
|
||||
|
@ -1098,7 +1098,9 @@ def test_deprecated_function_is_hassio(
|
||||
(
|
||||
"homeassistant.components.hassio",
|
||||
logging.WARNING,
|
||||
"is_hassio is a deprecated function which will be removed in HA Core 2025.11. Use homeassistant.helpers.hassio.is_hassio instead",
|
||||
"The deprecated function is_hassio was called. It will be "
|
||||
"removed in HA Core 2025.11. Use homeassistant.helpers"
|
||||
".hassio.is_hassio instead",
|
||||
)
|
||||
]
|
||||
|
||||
@ -1114,7 +1116,9 @@ def test_deprecated_function_get_supervisor_ip(
|
||||
(
|
||||
"homeassistant.helpers.hassio",
|
||||
logging.WARNING,
|
||||
"get_supervisor_ip is a deprecated function which will be removed in HA Core 2025.11. Use homeassistant.helpers.hassio.get_supervisor_ip instead",
|
||||
"The deprecated function get_supervisor_ip was called. It will "
|
||||
"be removed in HA Core 2025.11. Use homeassistant.helpers"
|
||||
".hassio.get_supervisor_ip instead",
|
||||
)
|
||||
]
|
||||
|
||||
|
@ -135,7 +135,7 @@ def test_deprecated_class(mock_get_logger) -> None:
|
||||
("breaks_in_ha_version", "extra_msg"),
|
||||
[
|
||||
(None, ""),
|
||||
("2099.1", " which will be removed in HA Core 2099.1"),
|
||||
("2099.1", " It will be removed in HA Core 2099.1."),
|
||||
],
|
||||
)
|
||||
def test_deprecated_function(
|
||||
@ -154,8 +154,9 @@ def test_deprecated_function(
|
||||
|
||||
mock_deprecated_function()
|
||||
assert (
|
||||
f"mock_deprecated_function is a deprecated function{extra_msg}. "
|
||||
"Use new_function instead"
|
||||
"The deprecated function mock_deprecated_function was called."
|
||||
f"{extra_msg}"
|
||||
" Use new_function instead"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
@ -163,7 +164,7 @@ def test_deprecated_function(
|
||||
("breaks_in_ha_version", "extra_msg"),
|
||||
[
|
||||
(None, ""),
|
||||
("2099.1", " which will be removed in HA Core 2099.1"),
|
||||
("2099.1", " It will be removed in HA Core 2099.1."),
|
||||
],
|
||||
)
|
||||
def test_deprecated_function_called_from_built_in_integration(
|
||||
@ -210,9 +211,9 @@ def test_deprecated_function_called_from_built_in_integration(
|
||||
):
|
||||
mock_deprecated_function()
|
||||
assert (
|
||||
"mock_deprecated_function was called from hue, "
|
||||
f"this is a deprecated function{extra_msg}. "
|
||||
"Use new_function instead"
|
||||
"The deprecated function mock_deprecated_function was called from hue."
|
||||
f"{extra_msg}"
|
||||
" Use new_function instead"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
@ -220,7 +221,7 @@ def test_deprecated_function_called_from_built_in_integration(
|
||||
("breaks_in_ha_version", "extra_msg"),
|
||||
[
|
||||
(None, ""),
|
||||
("2099.1", " which will be removed in HA Core 2099.1"),
|
||||
("2099.1", " It will be removed in HA Core 2099.1."),
|
||||
],
|
||||
)
|
||||
def test_deprecated_function_called_from_custom_integration(
|
||||
@ -270,9 +271,9 @@ def test_deprecated_function_called_from_custom_integration(
|
||||
):
|
||||
mock_deprecated_function()
|
||||
assert (
|
||||
"mock_deprecated_function was called from hue, "
|
||||
f"this is a deprecated function{extra_msg}. "
|
||||
"Use new_function instead, please report it to the author of the "
|
||||
"The deprecated function mock_deprecated_function was called from hue."
|
||||
f"{extra_msg}"
|
||||
" Use new_function instead, please report it to the author of the "
|
||||
"'hue' custom integration"
|
||||
) in caplog.text
|
||||
|
||||
@ -316,7 +317,7 @@ def _get_value(
|
||||
),
|
||||
(
|
||||
DeprecatedConstant(1, "NEW_CONSTANT", "2099.1"),
|
||||
" which will be removed in HA Core 2099.1. Use NEW_CONSTANT instead",
|
||||
". It will be removed in HA Core 2099.1. Use NEW_CONSTANT instead",
|
||||
"constant",
|
||||
),
|
||||
(
|
||||
@ -326,7 +327,7 @@ def _get_value(
|
||||
),
|
||||
(
|
||||
DeprecatedConstantEnum(TestDeprecatedConstantEnum.TEST, "2099.1"),
|
||||
" which will be removed in HA Core 2099.1. Use TestDeprecatedConstantEnum.TEST instead",
|
||||
". It will be removed in HA Core 2099.1. Use TestDeprecatedConstantEnum.TEST instead",
|
||||
"constant",
|
||||
),
|
||||
(
|
||||
@ -336,7 +337,7 @@ def _get_value(
|
||||
),
|
||||
(
|
||||
DeprecatedAlias(1, "new_alias", "2099.1"),
|
||||
" which will be removed in HA Core 2099.1. Use new_alias instead",
|
||||
". It will be removed in HA Core 2099.1. Use new_alias instead",
|
||||
"alias",
|
||||
),
|
||||
],
|
||||
@ -405,7 +406,7 @@ def test_check_if_deprecated_constant(
|
||||
assert (
|
||||
module_name,
|
||||
logging.WARNING,
|
||||
f"TEST_CONSTANT was used from hue, this is a deprecated {description}{extra_msg}{extra_extra_msg}",
|
||||
f"The deprecated {description} TEST_CONSTANT was used from hue{extra_msg}{extra_extra_msg}",
|
||||
) in caplog.record_tuples
|
||||
|
||||
|
||||
@ -594,7 +595,7 @@ def test_enum_with_deprecated_members(
|
||||
"tests.helpers.test_deprecation",
|
||||
logging.WARNING,
|
||||
(
|
||||
"TestEnum.CATS was used from hue, this is a deprecated enum member which "
|
||||
"The deprecated enum member TestEnum.CATS was used from hue. It "
|
||||
"will be removed in HA Core 2025.11.0. Use TestEnum.CATS_PER_CM instead"
|
||||
f"{extra_extra_msg}"
|
||||
),
|
||||
@ -603,7 +604,7 @@ def test_enum_with_deprecated_members(
|
||||
"tests.helpers.test_deprecation",
|
||||
logging.WARNING,
|
||||
(
|
||||
"TestEnum.DOGS was used from hue, this is a deprecated enum member. Use "
|
||||
"The deprecated enum member TestEnum.DOGS was used from hue. Use "
|
||||
f"TestEnum.DOGS_PER_CM instead{extra_extra_msg}"
|
||||
),
|
||||
) in caplog.record_tuples
|
||||
|
@ -359,8 +359,8 @@ def test_deprecated_json_loads(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""
|
||||
json_helper.json_loads("{}")
|
||||
assert (
|
||||
"json_loads is a deprecated function which will be removed in "
|
||||
"HA Core 2025.8. Use homeassistant.util.json.json_loads instead"
|
||||
"The deprecated function json_loads was called. It will be removed "
|
||||
"in HA Core 2025.8. Use homeassistant.util.json.json_loads instead"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
|
@ -166,8 +166,8 @@ def test_deprecated_unit_of_conductivity_members(
|
||||
|
||||
def deprecation_message(member: str, replacement: str) -> str:
|
||||
return (
|
||||
f"UnitOfConductivity.{member} was used from hue, this is a deprecated enum "
|
||||
"member which will be removed in HA Core 2025.11.0. Use UnitOfConductivity."
|
||||
f"The deprecated enum member UnitOfConductivity.{member} was used from hue. "
|
||||
"It will be removed in HA Core 2025.11.0. Use UnitOfConductivity."
|
||||
f"{replacement} instead, please report it to the author of the 'hue' custom"
|
||||
" integration"
|
||||
)
|
||||
|
@ -121,8 +121,8 @@ def test_timestamp_to_utc(caplog: pytest.LogCaptureFixture) -> None:
|
||||
utc_now = dt_util.utcnow()
|
||||
assert dt_util.utc_to_timestamp(utc_now) == utc_now.timestamp()
|
||||
assert (
|
||||
"utc_to_timestamp is a deprecated function which will be removed "
|
||||
"in HA Core 2026.1. Use datetime.timestamp instead" in caplog.text
|
||||
"The deprecated function utc_to_timestamp was called. It will be "
|
||||
"removed in HA Core 2026.1. Use datetime.timestamp instead" in caplog.text
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user