mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Use loader.async_suggest_report_issue in vacuum (#101391)
This commit is contained in:
parent
b7914582db
commit
a428bbfc2e
@ -40,7 +40,11 @@ from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.entity_platform import EntityPlatform
|
||||
from homeassistant.helpers.icon import icon_for_battery_level
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.loader import (
|
||||
async_get_issue_tracker,
|
||||
async_suggest_report_issue,
|
||||
bind_hass,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -384,6 +388,16 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
|
||||
# we don't worry about demo and mqtt has it's own deprecation warnings.
|
||||
if self.platform.platform_name in ("demo", "mqtt"):
|
||||
return
|
||||
translation_key = "deprecated_vacuum_base_class"
|
||||
translation_placeholders = {"platform": self.platform.platform_name}
|
||||
issue_tracker = async_get_issue_tracker(
|
||||
hass,
|
||||
integration_domain=self.platform.platform_name,
|
||||
module=type(self).__module__,
|
||||
)
|
||||
if issue_tracker:
|
||||
translation_placeholders["issue_tracker"] = issue_tracker
|
||||
translation_key = "deprecated_vacuum_base_class_url"
|
||||
ir.async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
@ -393,21 +407,24 @@ class VacuumEntity(_BaseVacuum, ToggleEntity):
|
||||
is_persistent=False,
|
||||
issue_domain=self.platform.platform_name,
|
||||
severity=ir.IssueSeverity.WARNING,
|
||||
translation_key="deprecated_vacuum_base_class",
|
||||
translation_placeholders={
|
||||
"platform": self.platform.platform_name,
|
||||
},
|
||||
translation_key=translation_key,
|
||||
translation_placeholders=translation_placeholders,
|
||||
)
|
||||
|
||||
report_issue = async_suggest_report_issue(
|
||||
hass,
|
||||
integration_domain=self.platform.platform_name,
|
||||
module=type(self).__module__,
|
||||
)
|
||||
_LOGGER.warning(
|
||||
(
|
||||
"%s::%s is extending the deprecated base class VacuumEntity instead of "
|
||||
"StateVacuumEntity, this is not valid and will be unsupported "
|
||||
"from Home Assistant 2024.2. Please report it to the author of the '%s'"
|
||||
" custom integration"
|
||||
"from Home Assistant 2024.2. Please %s"
|
||||
),
|
||||
self.platform.platform_name,
|
||||
self.__class__.__name__,
|
||||
self.platform.platform_name,
|
||||
report_issue,
|
||||
)
|
||||
|
||||
entity_description: VacuumEntityDescription
|
||||
|
@ -33,6 +33,10 @@
|
||||
"deprecated_vacuum_base_class": {
|
||||
"title": "The {platform} custom integration is using deprecated vacuum feature",
|
||||
"description": "The custom integration `{platform}` is extending the deprecated base class `VacuumEntity` instead of `StateVacuumEntity`.\n\nPlease report it to the author of the `{platform}` custom integration.\n\nOnce an updated version of `{platform}` is available, install it and restart Home Assistant to fix this issue."
|
||||
},
|
||||
"deprecated_vacuum_base_class_url": {
|
||||
"title": "[%key:component::vacuum::issues::deprecated_vacuum_base_class::title%]",
|
||||
"description": "The custom integration `{platform}` is extending the deprecated base class `VacuumEntity` instead of `StateVacuumEntity`.\n\nPlease create a bug report at {issue_tracker}.\n\nOnce an updated version of `{platform}` is available, install it and restart Home Assistant to fix this issue."
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
|
@ -36,8 +36,30 @@ def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]:
|
||||
yield
|
||||
|
||||
|
||||
ISSUE_TRACKER = "https://blablabla.com"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("manifest_extra", "translation_key", "translation_placeholders_extra"),
|
||||
[
|
||||
(
|
||||
{},
|
||||
"deprecated_vacuum_base_class",
|
||||
{},
|
||||
),
|
||||
(
|
||||
{"issue_tracker": ISSUE_TRACKER},
|
||||
"deprecated_vacuum_base_class_url",
|
||||
{"issue_tracker": ISSUE_TRACKER},
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_deprecated_base_class(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
manifest_extra: dict[str, str],
|
||||
translation_key: str,
|
||||
translation_placeholders_extra: dict[str, str],
|
||||
) -> None:
|
||||
"""Test warnings when adding VacuumEntity to the state machine."""
|
||||
|
||||
@ -54,7 +76,9 @@ async def test_deprecated_base_class(
|
||||
MockModule(
|
||||
TEST_DOMAIN,
|
||||
async_setup_entry=async_setup_entry_init,
|
||||
partial_manifest=manifest_extra,
|
||||
),
|
||||
built_in=False,
|
||||
)
|
||||
|
||||
entity1 = VacuumEntity()
|
||||
@ -91,3 +115,9 @@ async def test_deprecated_base_class(
|
||||
VACUUM_DOMAIN, f"deprecated_vacuum_base_class_{TEST_DOMAIN}"
|
||||
)
|
||||
assert issue.issue_domain == TEST_DOMAIN
|
||||
assert issue.issue_id == f"deprecated_vacuum_base_class_{TEST_DOMAIN}"
|
||||
assert issue.translation_key == translation_key
|
||||
assert (
|
||||
issue.translation_placeholders
|
||||
== {"platform": "test"} | translation_placeholders_extra
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user