From c2e46db76d6410b64cf370a349c71cf42978d04a Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Mon, 3 Apr 2023 13:35:35 +0200 Subject: [PATCH] Add entity name translations to AVM Fritz!Tools (#90703) * add entity name translation * apply suggestions * sort strings --- .../components/fritz/binary_sensor.py | 4 +-- homeassistant/components/fritz/button.py | 13 +++---- homeassistant/components/fritz/common.py | 1 - homeassistant/components/fritz/sensor.py | 32 ++++++++--------- homeassistant/components/fritz/strings.json | 34 +++++++++++++++++++ tests/components/fritz/test_button.py | 2 +- tests/components/fritz/test_sensor.py | 2 +- 7 files changed, 61 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/fritz/binary_sensor.py b/homeassistant/components/fritz/binary_sensor.py index 228b7d5935c..d2edb99e026 100644 --- a/homeassistant/components/fritz/binary_sensor.py +++ b/homeassistant/components/fritz/binary_sensor.py @@ -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), diff --git a/homeassistant/components/fritz/button.py b/homeassistant/components/fritz/button.py index a186d50960e..f732e32b75a 100644 --- a/homeassistant/components/fritz/button.py +++ b/homeassistant/components/fritz/button.py @@ -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: diff --git a/homeassistant/components/fritz/common.py b/homeassistant/components/fritz/common.py index f6025e773e0..89a51581bf7 100644 --- a/homeassistant/components/fritz/common.py +++ b/homeassistant/components/fritz/common.py @@ -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 diff --git a/homeassistant/components/fritz/sensor.py b/homeassistant/components/fritz/sensor.py index 4b15f3f92de..2b156046098 100644 --- a/homeassistant/components/fritz/sensor.py +++ b/homeassistant/components/fritz/sensor.py @@ -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, diff --git a/homeassistant/components/fritz/strings.json b/homeassistant/components/fritz/strings.json index 2d76479f2b9..45262d6f8ac 100644 --- a/homeassistant/components/fritz/strings.json +++ b/homeassistant/components/fritz/strings.json @@ -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" } + } } } diff --git a/tests/components/fritz/test_button.py b/tests/components/fritz/test_button.py index 36af1c27f5e..1dcf14d4b4c 100644 --- a/tests/components/fritz/test_button.py +++ b/tests/components/fritz/test_button.py @@ -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"), ], diff --git a/tests/components/fritz/test_sensor.py b/tests/components/fritz/test_sensor.py index 7871dd23c03..b2f389627ac 100644 --- a/tests/components/fritz/test_sensor.py +++ b/tests/components/fritz/test_sensor.py @@ -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, },