mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +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."""
|
"""Initialize the switch."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.device: SmartDevice = device
|
self.device: SmartDevice = device
|
||||||
self._attr_unique_id = self.device.device_id
|
self._attr_unique_id = device.device_id
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
connections={(dr.CONNECTION_NETWORK_MAC, device.mac)},
|
connections={(dr.CONNECTION_NETWORK_MAC, device.mac)},
|
||||||
identifiers={(DOMAIN, str(device.device_id))},
|
identifiers={(DOMAIN, str(device.device_id))},
|
||||||
|
@ -108,11 +108,13 @@ def async_emeter_from_device(
|
|||||||
|
|
||||||
|
|
||||||
def _async_sensors_for_device(
|
def _async_sensors_for_device(
|
||||||
device: SmartDevice, coordinator: TPLinkDataUpdateCoordinator
|
device: SmartDevice,
|
||||||
|
coordinator: TPLinkDataUpdateCoordinator,
|
||||||
|
has_parent: bool = False,
|
||||||
) -> list[SmartPlugSensor]:
|
) -> list[SmartPlugSensor]:
|
||||||
"""Generate the sensors for the device."""
|
"""Generate the sensors for the device."""
|
||||||
return [
|
return [
|
||||||
SmartPlugSensor(device, coordinator, description)
|
SmartPlugSensor(device, coordinator, description, has_parent)
|
||||||
for description in ENERGY_SENSORS
|
for description in ENERGY_SENSORS
|
||||||
if async_emeter_from_device(device, description) is not None
|
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
|
# Historically we only add the children if the device is a strip
|
||||||
for idx, child in enumerate(parent.children):
|
for idx, child in enumerate(parent.children):
|
||||||
entities.extend(
|
entities.extend(
|
||||||
_async_sensors_for_device(child, children_coordinators[idx])
|
_async_sensors_for_device(child, children_coordinators[idx], True)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
entities.extend(_async_sensors_for_device(parent, parent_coordinator))
|
entities.extend(_async_sensors_for_device(parent, parent_coordinator))
|
||||||
@ -154,13 +156,20 @@ class SmartPlugSensor(CoordinatedTPLinkEntity, SensorEntity):
|
|||||||
device: SmartDevice,
|
device: SmartDevice,
|
||||||
coordinator: TPLinkDataUpdateCoordinator,
|
coordinator: TPLinkDataUpdateCoordinator,
|
||||||
description: TPLinkSensorEntityDescription,
|
description: TPLinkSensorEntityDescription,
|
||||||
|
has_parent: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the switch."""
|
"""Initialize the switch."""
|
||||||
super().__init__(device, coordinator)
|
super().__init__(device, coordinator)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = (
|
self._attr_unique_id = f"{legacy_device_id(device)}_{description.key}"
|
||||||
f"{legacy_device_id(self.device)}_{self.entity_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
|
@property
|
||||||
def native_value(self) -> float | None:
|
def native_value(self) -> float | None:
|
||||||
|
@ -67,6 +67,21 @@
|
|||||||
},
|
},
|
||||||
"today_consumption": {
|
"today_consumption": {
|
||||||
"name": "Today's 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": {
|
"switch": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user