mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Add translation placeholders for TPLink power strip (#108710)
This commit is contained in:
parent
22eed5419e
commit
c7db8a0bee
@ -40,7 +40,7 @@ class CoordinatedTPLinkEntity(CoordinatorEntity[TPLinkDataUpdateCoordinator]):
|
||||
"""Initialize the switch."""
|
||||
super().__init__(coordinator)
|
||||
self.device: SmartDevice = device
|
||||
self._attr_unique_id = self.device.device_id
|
||||
self._attr_unique_id = device.device_id
|
||||
self._attr_device_info = DeviceInfo(
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, device.mac)},
|
||||
identifiers={(DOMAIN, str(device.device_id))},
|
||||
|
@ -108,11 +108,13 @@ def async_emeter_from_device(
|
||||
|
||||
|
||||
def _async_sensors_for_device(
|
||||
device: SmartDevice, coordinator: TPLinkDataUpdateCoordinator
|
||||
device: SmartDevice,
|
||||
coordinator: TPLinkDataUpdateCoordinator,
|
||||
has_parent: bool = False,
|
||||
) -> list[SmartPlugSensor]:
|
||||
"""Generate the sensors for the device."""
|
||||
return [
|
||||
SmartPlugSensor(device, coordinator, description)
|
||||
SmartPlugSensor(device, coordinator, description, has_parent)
|
||||
for description in ENERGY_SENSORS
|
||||
if async_emeter_from_device(device, description) is not None
|
||||
]
|
||||
@ -136,7 +138,7 @@ async def async_setup_entry(
|
||||
# Historically we only add the children if the device is a strip
|
||||
for idx, child in enumerate(parent.children):
|
||||
entities.extend(
|
||||
_async_sensors_for_device(child, children_coordinators[idx])
|
||||
_async_sensors_for_device(child, children_coordinators[idx], True)
|
||||
)
|
||||
else:
|
||||
entities.extend(_async_sensors_for_device(parent, parent_coordinator))
|
||||
@ -154,13 +156,20 @@ class SmartPlugSensor(CoordinatedTPLinkEntity, SensorEntity):
|
||||
device: SmartDevice,
|
||||
coordinator: TPLinkDataUpdateCoordinator,
|
||||
description: TPLinkSensorEntityDescription,
|
||||
has_parent: bool = False,
|
||||
) -> None:
|
||||
"""Initialize the switch."""
|
||||
super().__init__(device, coordinator)
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = (
|
||||
f"{legacy_device_id(self.device)}_{self.entity_description.key}"
|
||||
)
|
||||
self._attr_unique_id = f"{legacy_device_id(device)}_{description.key}"
|
||||
if has_parent:
|
||||
assert device.alias
|
||||
self._attr_translation_placeholders = {"device_name": device.alias}
|
||||
if description.translation_key:
|
||||
self._attr_translation_key = f"{description.translation_key}_child"
|
||||
else:
|
||||
assert description.device_class
|
||||
self._attr_translation_key = f"{description.device_class.value}_child"
|
||||
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
|
@ -67,6 +67,21 @@
|
||||
},
|
||||
"today_consumption": {
|
||||
"name": "Today's consumption"
|
||||
},
|
||||
"current_consumption_child": {
|
||||
"name": "{device_name} current consumption"
|
||||
},
|
||||
"total_consumption_child": {
|
||||
"name": "{device_name} total consumption"
|
||||
},
|
||||
"today_consumption_child": {
|
||||
"name": "{device_name} today's consumption"
|
||||
},
|
||||
"current_child": {
|
||||
"name": "{device_name} current"
|
||||
},
|
||||
"voltage_child": {
|
||||
"name": "{device_name} voltage"
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user