Move Shelly sensor get_entity_translation_attributes to utils (#156590)

Signed-off-by: David Rapan <david@rapan.cz>
This commit is contained in:
David Rapan
2025-11-14 15:44:48 +02:00
committed by GitHub
parent 9b4696a80b
commit 9f78a2263d
2 changed files with 18 additions and 19 deletions
+1 -19
View File
@@ -63,6 +63,7 @@ from .utils import (
get_blu_trv_device_info,
get_device_entry_gen,
get_device_uptime,
get_entity_translation_attributes,
get_rpc_channel_name,
get_shelly_air_lamp_life,
get_virtual_component_unit,
@@ -73,25 +74,6 @@ from .utils import (
PARALLEL_UPDATES = 0
def get_entity_translation_attributes(
channel_name: str | None,
translation_key: str | None,
device_class: str | None,
default_to_device_class_name: bool,
) -> tuple[dict[str, str] | None, str | None]:
"""Translation attributes for entity with channel name."""
if channel_name is None:
return None, None
key = translation_key
if key is None and default_to_device_class_name:
key = device_class
final_translation_key = f"{key}_with_channel_name" if key else None
return {"channel_name": channel_name}, final_translation_key
@dataclass(frozen=True, kw_only=True)
class BlockSensorDescription(BlockEntityDescription, SensorEntityDescription):
"""Class to describe a BLOCK sensor."""
+17
View File
@@ -459,6 +459,23 @@ def get_rpc_entity_name(
return channel_name
def get_entity_translation_attributes(
channel_name: str | None,
translation_key: str | None,
device_class: str | None,
default_to_device_class_name: bool,
) -> tuple[dict[str, str] | None, str | None]:
"""Translation attributes for entity with channel name."""
if channel_name is None:
return None, None
key = translation_key
if key is None and default_to_device_class_name:
key = device_class
return {"channel_name": channel_name}, f"{key}_with_channel_name" if key else None
def get_device_entry_gen(entry: ConfigEntry) -> int:
"""Return the device generation from config entry."""
return entry.data.get(CONF_GEN, 1) # type: ignore[no-any-return]