Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use loader.async_suggest_report_issue in vacuum #101391

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions homeassistant/components/vacuum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
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__)

Expand Down Expand Up @@ -384,6 +388,16 @@ def add_to_platform_start(
# 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,
Expand All @@ -393,21 +407,24 @@ def add_to_platform_start(
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
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/vacuum/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
32 changes: 31 additions & 1 deletion tests/components/vacuum/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -54,7 +76,9 @@ async def async_setup_entry_init(
MockModule(
TEST_DOMAIN,
async_setup_entry=async_setup_entry_init,
partial_manifest=manifest_extra,
),
built_in=False,
)

entity1 = VacuumEntity()
Expand Down Expand Up @@ -91,3 +115,9 @@ async def async_setup_entry_platform(
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
)