mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Improve entity translation typing (#112788)
* Improve entity translation typing * Improve entity translation typing
This commit is contained in:
parent
a66399ad3d
commit
6a7c255b93
@ -610,7 +610,7 @@ class Entity(
|
|||||||
|
|
||||||
def _device_class_name_helper(
|
def _device_class_name_helper(
|
||||||
self,
|
self,
|
||||||
component_translations: dict[str, Any],
|
component_translations: dict[str, str],
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
"""Return a translated name of the entity based on its device class."""
|
"""Return a translated name of the entity based on its device class."""
|
||||||
if not self.has_entity_name:
|
if not self.has_entity_name:
|
||||||
@ -675,7 +675,7 @@ class Entity(
|
|||||||
def _name_internal(
|
def _name_internal(
|
||||||
self,
|
self,
|
||||||
device_class_name: str | None,
|
device_class_name: str | None,
|
||||||
platform_translations: dict[str, Any],
|
platform_translations: dict[str, str],
|
||||||
) -> str | UndefinedType | None:
|
) -> str | UndefinedType | None:
|
||||||
"""Return the name of the entity."""
|
"""Return the name of the entity."""
|
||||||
if hasattr(self, "_attr_name"):
|
if hasattr(self, "_attr_name"):
|
||||||
@ -685,8 +685,6 @@ class Entity(
|
|||||||
and (name_translation_key := self._name_translation_key)
|
and (name_translation_key := self._name_translation_key)
|
||||||
and (name := platform_translations.get(name_translation_key))
|
and (name := platform_translations.get(name_translation_key))
|
||||||
):
|
):
|
||||||
if TYPE_CHECKING:
|
|
||||||
assert isinstance(name, str)
|
|
||||||
return self._substitute_name_placeholders(name)
|
return self._substitute_name_placeholders(name)
|
||||||
if hasattr(self, "entity_description"):
|
if hasattr(self, "entity_description"):
|
||||||
description_name = self.entity_description.name
|
description_name = self.entity_description.name
|
||||||
|
@ -130,10 +130,10 @@ class EntityPlatform:
|
|||||||
# Storage for entities for this specific platform only
|
# Storage for entities for this specific platform only
|
||||||
# which are indexed by entity_id
|
# which are indexed by entity_id
|
||||||
self.entities: dict[str, Entity] = {}
|
self.entities: dict[str, Entity] = {}
|
||||||
self.component_translations: dict[str, Any] = {}
|
self.component_translations: dict[str, str] = {}
|
||||||
self.platform_translations: dict[str, Any] = {}
|
self.platform_translations: dict[str, str] = {}
|
||||||
self.object_id_component_translations: dict[str, Any] = {}
|
self.object_id_component_translations: dict[str, str] = {}
|
||||||
self.object_id_platform_translations: dict[str, Any] = {}
|
self.object_id_platform_translations: dict[str, str] = {}
|
||||||
self._tasks: list[asyncio.Task[None]] = []
|
self._tasks: list[asyncio.Task[None]] = []
|
||||||
# Stop tracking tasks after setup is completed
|
# Stop tracking tasks after setup is completed
|
||||||
self._setup_complete = False
|
self._setup_complete = False
|
||||||
@ -419,7 +419,7 @@ class EntityPlatform:
|
|||||||
|
|
||||||
async def _async_get_translations(
|
async def _async_get_translations(
|
||||||
self, language: str, category: str, integration: str
|
self, language: str, category: str, integration: str
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, str]:
|
||||||
"""Get translations for a language, category, and integration."""
|
"""Get translations for a language, category, and integration."""
|
||||||
try:
|
try:
|
||||||
return await translation.async_get_translations(
|
return await translation.async_get_translations(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user