Skip to content

Commit 9f78a22

Browse files
authored
Move Shelly sensor get_entity_translation_attributes to utils (home-assistant#156590)
Signed-off-by: David Rapan <[email protected]>
1 parent 9b4696a commit 9f78a22

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

homeassistant/components/shelly/sensor.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
get_blu_trv_device_info,
6464
get_device_entry_gen,
6565
get_device_uptime,
66+
get_entity_translation_attributes,
6667
get_rpc_channel_name,
6768
get_shelly_air_lamp_life,
6869
get_virtual_component_unit,
@@ -73,25 +74,6 @@
7374
PARALLEL_UPDATES = 0
7475

7576

76-
def get_entity_translation_attributes(
77-
channel_name: str | None,
78-
translation_key: str | None,
79-
device_class: str | None,
80-
default_to_device_class_name: bool,
81-
) -> tuple[dict[str, str] | None, str | None]:
82-
"""Translation attributes for entity with channel name."""
83-
if channel_name is None:
84-
return None, None
85-
86-
key = translation_key
87-
if key is None and default_to_device_class_name:
88-
key = device_class
89-
90-
final_translation_key = f"{key}_with_channel_name" if key else None
91-
92-
return {"channel_name": channel_name}, final_translation_key
93-
94-
9577
@dataclass(frozen=True, kw_only=True)
9678
class BlockSensorDescription(BlockEntityDescription, SensorEntityDescription):
9779
"""Class to describe a BLOCK sensor."""

homeassistant/components/shelly/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,23 @@ def get_rpc_entity_name(
459459
return channel_name
460460

461461

462+
def get_entity_translation_attributes(
463+
channel_name: str | None,
464+
translation_key: str | None,
465+
device_class: str | None,
466+
default_to_device_class_name: bool,
467+
) -> tuple[dict[str, str] | None, str | None]:
468+
"""Translation attributes for entity with channel name."""
469+
if channel_name is None:
470+
return None, None
471+
472+
key = translation_key
473+
if key is None and default_to_device_class_name:
474+
key = device_class
475+
476+
return {"channel_name": channel_name}, f"{key}_with_channel_name" if key else None
477+
478+
462479
def get_device_entry_gen(entry: ConfigEntry) -> int:
463480
"""Return the device generation from config entry."""
464481
return entry.data.get(CONF_GEN, 1) # type: ignore[no-any-return]

0 commit comments

Comments
 (0)