Skip to content

Commit 4646929

Browse files
authored
Avoid custom template platform deprecations (home-assistant#157415)
1 parent 010aea9 commit 4646929

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

homeassistant/components/template/helpers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
CONF_DEFAULT_ENTITY_ID,
4747
CONF_PICTURE,
4848
DOMAIN,
49+
PLATFORMS,
4950
)
5051
from .entity import AbstractTemplateEntity
5152
from .template_entity import TemplateEntity
@@ -234,6 +235,8 @@ def create_legacy_template_issue(
234235
hass: HomeAssistant, config: ConfigType, domain: str
235236
) -> None:
236237
"""Create a repair for legacy template entities."""
238+
if domain not in PLATFORMS:
239+
return
237240

238241
breadcrumb = "Template Entity"
239242
# Default entity id should be in most legacy configuration because

tests/components/template/test_helpers.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from homeassistant.components.template.fan import LEGACY_FIELDS as FAN_LEGACY_FIELDS
1414
from homeassistant.components.template.helpers import (
1515
async_setup_template_platform,
16+
create_legacy_template_issue,
1617
format_migration_config,
1718
rewrite_legacy_to_modern_config,
1819
rewrite_legacy_to_modern_configs,
@@ -637,3 +638,40 @@ async def test_yaml_config_recursion_depth(hass: HomeAssistant) -> None:
637638

638639
with pytest.raises(RecursionError):
639640
format_migration_config({1: {2: {3: {4: {5: {6: [{7: {8: {9: {10: {}}}}}]}}}}}})
641+
642+
643+
@pytest.mark.parametrize(
644+
("domain", "config"),
645+
[
646+
(
647+
"media_player",
648+
{
649+
"media_player": {
650+
"platform": "template",
651+
"name": "My Media Player",
652+
"unique_id": "Foobar",
653+
},
654+
},
655+
),
656+
(
657+
"climate",
658+
{
659+
"climate": {
660+
"platform": "template",
661+
"name": "My Climate",
662+
"unique_id": "Foobar",
663+
},
664+
},
665+
),
666+
],
667+
)
668+
async def test_custom_integration_deprecation(
669+
hass: HomeAssistant,
670+
domain: str,
671+
config: dict,
672+
issue_registry: ir.IssueRegistry,
673+
) -> None:
674+
"""Test that custom integrations do not create deprecations."""
675+
676+
create_legacy_template_issue(hass, config, domain)
677+
assert len(issue_registry.issues) == 0

0 commit comments

Comments
 (0)