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