Add entity name translations to AVM Fritz!Tools (#90703)

* add entity name translation

* apply suggestions

* sort strings
This commit is contained in:
Michael 2023-04-03 13:35:35 +02:00 committed by GitHub
parent eb748416ed
commit 33a4c2c162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 27 deletions

View File

@ -38,14 +38,14 @@ class FritzBinarySensorEntityDescription(
SENSOR_TYPES: tuple[FritzBinarySensorEntityDescription, ...] = (
FritzBinarySensorEntityDescription(
key="is_connected",
name="Connection",
translation_key="is_connected",
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda status, _: bool(status.is_connected),
),
FritzBinarySensorEntityDescription(
key="is_linked",
name="Link",
translation_key="is_linked",
device_class=BinarySensorDeviceClass.PLUG,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda status, _: bool(status.is_linked),

View File

@ -39,28 +39,28 @@ class FritzButtonDescription(ButtonEntityDescription, FritzButtonDescriptionMixi
BUTTONS: Final = [
FritzButtonDescription(
key="firmware_update",
name="Firmware Update",
translation_key="firmware_update",
device_class=ButtonDeviceClass.UPDATE,
entity_category=EntityCategory.CONFIG,
press_action=lambda avm_wrapper: avm_wrapper.async_trigger_firmware_update(),
),
FritzButtonDescription(
key="reboot",
name="Reboot",
translation_key="reboot",
device_class=ButtonDeviceClass.RESTART,
entity_category=EntityCategory.CONFIG,
press_action=lambda avm_wrapper: avm_wrapper.async_trigger_reboot(),
),
FritzButtonDescription(
key="reconnect",
name="Reconnect",
translation_key="reconnect",
device_class=ButtonDeviceClass.RESTART,
entity_category=EntityCategory.CONFIG,
press_action=lambda avm_wrapper: avm_wrapper.async_trigger_reconnect(),
),
FritzButtonDescription(
key="cleanup",
name="Cleanup",
translation_key="cleanup",
icon="mdi:broom",
entity_category=EntityCategory.CONFIG,
press_action=lambda avm_wrapper: avm_wrapper.async_trigger_cleanup(),
@ -86,6 +86,7 @@ class FritzButton(ButtonEntity):
"""Defines a Fritz!Box base button."""
entity_description: FritzButtonDescription
_attr_has_entity_name = True
def __init__(
self,
@ -97,11 +98,11 @@ class FritzButton(ButtonEntity):
self.entity_description = description
self.avm_wrapper = avm_wrapper
self._attr_name = f"{device_friendly_name} {description.name}"
self._attr_unique_id = f"{self.avm_wrapper.unique_id}-{description.key}"
self._attr_device_info = DeviceInfo(
connections={(CONNECTION_NETWORK_MAC, avm_wrapper.mac)}
connections={(CONNECTION_NETWORK_MAC, avm_wrapper.mac)},
name=device_friendly_name,
)
async def async_press(self) -> None:

View File

@ -1043,7 +1043,6 @@ class FritzBoxBaseCoordinatorEntity(update_coordinator.CoordinatorEntity):
)
self.entity_description = description
self._device_name = device_name
self._attr_name = description.name
self._attr_unique_id = f"{avm_wrapper.unique_id}-{description.key}"
@property

View File

@ -152,20 +152,20 @@ class FritzSensorEntityDescription(SensorEntityDescription, FritzEntityDescripti
SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
FritzSensorEntityDescription(
key="external_ip",
name="External IP",
translation_key="external_ip",
icon="mdi:earth",
value_fn=_retrieve_external_ip_state,
),
FritzSensorEntityDescription(
key="external_ipv6",
name="External IPv6",
translation_key="external_ipv6",
icon="mdi:earth",
value_fn=_retrieve_external_ipv6_state,
is_suitable=lambda info: info.ipv6_active,
),
FritzSensorEntityDescription(
key="device_uptime",
name="Device Uptime",
translation_key="device_uptime",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_device_uptime_state,
@ -173,14 +173,14 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="connection_uptime",
name="Connection Uptime",
translation_key="connection_uptime",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_connection_uptime_state,
),
FritzSensorEntityDescription(
key="kb_s_sent",
name="Upload Throughput",
translation_key="kb_s_sent",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfDataRate.KILOBYTES_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
@ -189,7 +189,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="kb_s_received",
name="Download Throughput",
translation_key="kb_s_received",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfDataRate.KILOBYTES_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
@ -198,7 +198,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="max_kb_s_sent",
name="Max Connection Upload Throughput",
translation_key="max_kb_s_sent",
native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
icon="mdi:upload",
@ -207,7 +207,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="max_kb_s_received",
name="Max Connection Download Throughput",
translation_key="max_kb_s_received",
native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
icon="mdi:download",
@ -216,7 +216,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="gb_sent",
name="GB sent",
translation_key="gb_sent",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
@ -225,7 +225,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="gb_received",
name="GB received",
translation_key="gb_received",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
@ -234,7 +234,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="link_kb_s_sent",
name="Link Upload Throughput",
translation_key="link_kb_s_sent",
native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
icon="mdi:upload",
@ -242,7 +242,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="link_kb_s_received",
name="Link Download Throughput",
translation_key="link_kb_s_received",
native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
icon="mdi:download",
@ -250,7 +250,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="link_noise_margin_sent",
name="Link Upload Noise Margin",
translation_key="link_noise_margin_sent",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
icon="mdi:upload",
value_fn=_retrieve_link_noise_margin_sent_state,
@ -258,7 +258,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="link_noise_margin_received",
name="Link Download Noise Margin",
translation_key="link_noise_margin_received",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
icon="mdi:download",
value_fn=_retrieve_link_noise_margin_received_state,
@ -266,7 +266,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="link_attenuation_sent",
name="Link Upload Power Attenuation",
translation_key="link_attenuation_sent",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
icon="mdi:upload",
value_fn=_retrieve_link_attenuation_sent_state,
@ -274,7 +274,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
),
FritzSensorEntityDescription(
key="link_attenuation_received",
name="Link Download Power Attenuation",
translation_key="link_attenuation_received",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
icon="mdi:download",
value_fn=_retrieve_link_attenuation_received_state,

View File

@ -52,5 +52,39 @@
}
}
}
},
"entity": {
"binary_sensor": {
"is_connected": { "name": "Connection" },
"is_linked": { "name": "Link" }
},
"button": {
"cleanup": { "name": "Cleanup" },
"firmware_update": { "name": "Firmware update" },
"reboot": {
"name": "[%key:component::button::entity_component::restart::name%]"
},
"reconnect": { "name": "Reconnect" }
},
"sensor": {
"connection_uptime": { "name": "Connection uptime" },
"device_uptime": { "name": "Last restart" },
"external_ip": { "name": "External IP" },
"external_ipv6": { "name": "External IPv6" },
"gb_received": { "name": "GB received" },
"gb_sent": { "name": "GB sent" },
"kb_s_received": { "name": "Download throughput" },
"kb_s_sent": { "name": "Upload throughput" },
"link_attenuation_received": {
"name": "Link download power attenuation"
},
"link_attenuation_sent": { "name": "Link upload power attenuation" },
"link_kb_s_received": { "name": "Link download throughput" },
"link_kb_s_sent": { "name": "Link upload throughput" },
"link_noise_margin_received": { "name": "Link download noise margin" },
"link_noise_margin_sent": { "name": "Link upload noise margin" },
"max_kb_s_received": { "name": "Max connection download throughput" },
"max_kb_s_sent": { "name": "Max connection upload throughput" }
}
}
}

View File

@ -36,7 +36,7 @@ async def test_button_setup(hass: HomeAssistant, fc_class_mock, fh_class_mock) -
("entity_id", "wrapper_method"),
[
("button.mock_title_firmware_update", "async_trigger_firmware_update"),
("button.mock_title_reboot", "async_trigger_reboot"),
("button.mock_title_restart", "async_trigger_reboot"),
("button.mock_title_reconnect", "async_trigger_reconnect"),
("button.mock_title_cleanup", "async_trigger_cleanup"),
],

View File

@ -39,7 +39,7 @@ SENSOR_STATES: dict[str, dict[str, Any]] = {
ATTR_STATE: "fec0::1",
ATTR_ICON: "mdi:earth",
},
"sensor.mock_title_device_uptime": {
"sensor.mock_title_last_restart": {
# ATTR_STATE: "2022-02-05T17:46:04+00:00",
ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
},