1 """Helper class for deprecating entities."""
3 from __future__
import annotations
5 from collections.abc
import Sequence
6 from dataclasses
import dataclass
7 from typing
import TYPE_CHECKING
15 from .const
import DOMAIN
18 from .entity
import CoordinatedTPLinkFeatureEntity, TPLinkFeatureEntityDescription
21 @dataclass(slots=True)
23 """Class to define deprecation info for deprecated entities."""
27 breaks_in_ha_version: str
33 entity_description: TPLinkFeatureEntityDescription,
35 """Return true if the entity should be created based on the deprecated_info.
37 If deprecated_info is not defined will return true.
38 If entity not yet created will return false.
39 If entity disabled will return false.
41 if not entity_description.deprecated_info:
44 deprecated_info = entity_description.deprecated_info
45 platform = deprecated_info.platform
47 ent_reg = er.async_get(hass)
48 entity_id = ent_reg.async_get_entity_id(
56 entity_entry = ent_reg.async_get(entity_id)
58 return not entity_entry.disabled
65 entities: Sequence[CoordinatedTPLinkFeatureEntity],
67 """Remove disabled deprecated entities or create issues if necessary."""
68 ent_reg = er.async_get(hass)
69 for entity
in entities:
70 if not (deprecated_info := entity.entity_description.deprecated_info):
73 assert entity.unique_id
74 entity_id = ent_reg.async_get_entity_id(
84 for item
in entity_automations + entity_scripts:
88 f
"deprecated_entity_{entity_id}_{item}",
89 breaks_in_ha_version=deprecated_info.breaks_in_ha_version,
92 severity=IssueSeverity.WARNING,
93 translation_key=
"deprecated_entity",
94 translation_placeholders={
98 "new_platform": deprecated_info.new_platform,
103 unique_ids = {entity.unique_id
for entity
in entities}
104 for entity_entry
in er.async_entries_for_config_entry(ent_reg, entry_id):
106 entity_entry.domain == platform
107 and entity_entry.disabled
108 and entity_entry.unique_id
not in unique_ids
110 ent_reg.async_remove(entity_entry.entity_id)
list[str] automations_with_entity(HomeAssistant hass, str entity_id)
None async_create_issue(HomeAssistant hass, str entry_id)
list[str] scripts_with_entity(HomeAssistant hass, str entity_id)
None async_cleanup_deprecated(HomeAssistant hass, str platform, str entry_id, Sequence[CoordinatedTPLinkFeatureEntity] entities)
bool async_check_create_deprecated(HomeAssistant hass, str unique_id, TPLinkFeatureEntityDescription entity_description)