From fcaa2fcf039c54fb5333b5c9f1720a5dbcc9e0f6 Mon Sep 17 00:00:00 2001
From: Jan-Philipp Benecke <jan-philipp@bnck.me>
Date: Sun, 21 Jan 2024 13:44:32 +0100
Subject: [PATCH] Make remaining WLED entities translatable (#108534)

---
 .../components/wled/binary_sensor.py          |  2 +-
 homeassistant/components/wled/light.py        |  3 +-
 homeassistant/components/wled/number.py       |  7 ++--
 homeassistant/components/wled/select.py       |  5 +--
 homeassistant/components/wled/strings.json    | 34 +++++++++++++++++++
 homeassistant/components/wled/switch.py       |  5 +--
 .../wled/snapshots/test_binary_sensor.ambr    |  2 +-
 .../wled/snapshots/test_number.ambr           | 12 +++----
 .../wled/snapshots/test_select.ambr           |  2 +-
 .../wled/snapshots/test_switch.ambr           |  2 +-
 10 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/homeassistant/components/wled/binary_sensor.py b/homeassistant/components/wled/binary_sensor.py
index a248ea57c7d..6191235f423 100644
--- a/homeassistant/components/wled/binary_sensor.py
+++ b/homeassistant/components/wled/binary_sensor.py
@@ -34,7 +34,7 @@ class WLEDUpdateBinarySensor(WLEDEntity, BinarySensorEntity):
 
     _attr_entity_category = EntityCategory.DIAGNOSTIC
     _attr_device_class = BinarySensorDeviceClass.UPDATE
-    _attr_name = "Firmware"
+    _attr_translation_key = "firmware"
 
     # Disabled by default, as this entity is deprecated.
     _attr_entity_registry_enabled_default = False
diff --git a/homeassistant/components/wled/light.py b/homeassistant/components/wled/light.py
index b793654c886..5ca86978f0f 100644
--- a/homeassistant/components/wled/light.py
+++ b/homeassistant/components/wled/light.py
@@ -121,7 +121,8 @@ class WLEDSegmentLight(WLEDEntity, LightEntity):
         if segment == 0:
             self._attr_name = None
         else:
-            self._attr_name = f"Segment {segment}"
+            self._attr_translation_key = "segment"
+            self._attr_translation_placeholders = {"segment": str(segment)}
 
         self._attr_unique_id = (
             f"{self.coordinator.data.info.mac_address}_{self._segment}"
diff --git a/homeassistant/components/wled/number.py b/homeassistant/components/wled/number.py
index 0fa7d464722..5b88165207f 100644
--- a/homeassistant/components/wled/number.py
+++ b/homeassistant/components/wled/number.py
@@ -49,7 +49,7 @@ class WLEDNumberEntityDescription(NumberEntityDescription):
 NUMBERS = [
     WLEDNumberEntityDescription(
         key=ATTR_SPEED,
-        name="Speed",
+        translation_key="speed",
         icon="mdi:speedometer",
         entity_category=EntityCategory.CONFIG,
         native_step=1,
@@ -59,7 +59,7 @@ NUMBERS = [
     ),
     WLEDNumberEntityDescription(
         key=ATTR_INTENSITY,
-        name="Intensity",
+        translation_key="intensity",
         entity_category=EntityCategory.CONFIG,
         native_step=1,
         native_min_value=0,
@@ -87,7 +87,8 @@ class WLEDNumber(WLEDEntity, NumberEntity):
         # Segment 0 uses a simpler name, which is more natural for when using
         # a single segment / using WLED with one big LED strip.
         if segment != 0:
-            self._attr_name = f"Segment {segment} {description.name}"
+            self._attr_translation_key = f"segment_{description.translation_key}"
+            self._attr_translation_placeholders = {"segment": str(segment)}
 
         self._attr_unique_id = (
             f"{coordinator.data.info.mac_address}_{description.key}_{segment}"
diff --git a/homeassistant/components/wled/select.py b/homeassistant/components/wled/select.py
index 977c76025ac..7df43a4250d 100644
--- a/homeassistant/components/wled/select.py
+++ b/homeassistant/components/wled/select.py
@@ -139,7 +139,7 @@ class WLEDPaletteSelect(WLEDEntity, SelectEntity):
 
     _attr_entity_category = EntityCategory.CONFIG
     _attr_icon = "mdi:palette-outline"
-    _attr_name = "Color palette"
+    _attr_translation_key = "color_palette"
     _segment: int
 
     def __init__(self, coordinator: WLEDDataUpdateCoordinator, segment: int) -> None:
@@ -149,7 +149,8 @@ class WLEDPaletteSelect(WLEDEntity, SelectEntity):
         # Segment 0 uses a simpler name, which is more natural for when using
         # a single segment / using WLED with one big LED strip.
         if segment != 0:
-            self._attr_name = f"Segment {segment} color palette"
+            self._attr_translation_key = "segment_color_palette"
+            self._attr_translation_placeholders = {"segment": str(segment)}
 
         self._attr_unique_id = f"{coordinator.data.info.mac_address}_palette_{segment}"
         self._attr_options = [
diff --git a/homeassistant/components/wled/strings.json b/homeassistant/components/wled/strings.json
index eff6dfab572..22b1e451a68 100644
--- a/homeassistant/components/wled/strings.json
+++ b/homeassistant/components/wled/strings.json
@@ -35,12 +35,40 @@
     }
   },
   "entity": {
+    "binary_sensor": {
+      "firmware": {
+        "name": "Firmware"
+      }
+    },
     "light": {
       "main": {
         "name": "Main"
+      },
+      "segment": {
+        "name": "Segment {segment}"
+      }
+    },
+    "number": {
+      "intensity": {
+        "name": "Intensity"
+      },
+      "segment_intensity": {
+        "name": "Segment {segment} intensity"
+      },
+      "speed": {
+        "name": "Speed"
+      },
+      "segment_speed": {
+        "name": "Segment {segment} speed"
       }
     },
     "select": {
+      "color_palette": {
+        "name": "Color palette"
+      },
+      "segment_color_palette": {
+        "name": "Segment {segment} color palette"
+      },
       "live_override": {
         "name": "Live override",
         "state": {
@@ -97,6 +125,12 @@
       },
       "sync_receive": {
         "name": "Sync receive"
+      },
+      "reverse": {
+        "name": "Reverse"
+      },
+      "segment_reverse": {
+        "name": "Segment {segment} reverse"
       }
     }
   },
diff --git a/homeassistant/components/wled/switch.py b/homeassistant/components/wled/switch.py
index 680684e96df..1fb300bd01d 100644
--- a/homeassistant/components/wled/switch.py
+++ b/homeassistant/components/wled/switch.py
@@ -159,7 +159,7 @@ class WLEDReverseSwitch(WLEDEntity, SwitchEntity):
 
     _attr_icon = "mdi:swap-horizontal-bold"
     _attr_entity_category = EntityCategory.CONFIG
-    _attr_name = "Reverse"
+    _attr_translation_key = "reverse"
     _segment: int
 
     def __init__(self, coordinator: WLEDDataUpdateCoordinator, segment: int) -> None:
@@ -169,7 +169,8 @@ class WLEDReverseSwitch(WLEDEntity, SwitchEntity):
         # Segment 0 uses a simpler name, which is more natural for when using
         # a single segment / using WLED with one big LED strip.
         if segment != 0:
-            self._attr_name = f"Segment {segment} reverse"
+            self._attr_translation_key = "segment_reverse"
+            self._attr_translation_placeholders = {"segment": str(segment)}
 
         self._attr_unique_id = f"{coordinator.data.info.mac_address}_reverse_{segment}"
         self._segment = segment
diff --git a/tests/components/wled/snapshots/test_binary_sensor.ambr b/tests/components/wled/snapshots/test_binary_sensor.ambr
index 6fc9b2497b5..03d1d4f61dc 100644
--- a/tests/components/wled/snapshots/test_binary_sensor.ambr
+++ b/tests/components/wled/snapshots/test_binary_sensor.ambr
@@ -38,7 +38,7 @@
     'platform': 'wled',
     'previous_unique_id': None,
     'supported_features': 0,
-    'translation_key': None,
+    'translation_key': 'firmware',
     'unique_id': 'aabbccddeeff_update',
     'unit_of_measurement': None,
   })
diff --git a/tests/components/wled/snapshots/test_number.ambr b/tests/components/wled/snapshots/test_number.ambr
index 47dafe039b2..5539f1f4503 100644
--- a/tests/components/wled/snapshots/test_number.ambr
+++ b/tests/components/wled/snapshots/test_number.ambr
@@ -2,7 +2,7 @@
 # name: test_numbers[number.wled_rgb_light_segment_1_intensity-42-intensity]
   StateSnapshot({
     'attributes': ReadOnlyDict({
-      'friendly_name': 'WLED RGB Light Segment 1 Intensity',
+      'friendly_name': 'WLED RGB Light Segment 1 intensity',
       'max': 255,
       'min': 0,
       'mode': <NumberMode.AUTO: 'auto'>,
@@ -42,11 +42,11 @@
     }),
     'original_device_class': None,
     'original_icon': None,
-    'original_name': 'Segment 1 Intensity',
+    'original_name': 'Segment 1 intensity',
     'platform': 'wled',
     'previous_unique_id': None,
     'supported_features': 0,
-    'translation_key': None,
+    'translation_key': 'segment_intensity',
     'unique_id': 'aabbccddeeff_intensity_1',
     'unit_of_measurement': None,
   })
@@ -86,7 +86,7 @@
 # name: test_numbers[number.wled_rgb_light_segment_1_speed-42-speed]
   StateSnapshot({
     'attributes': ReadOnlyDict({
-      'friendly_name': 'WLED RGB Light Segment 1 Speed',
+      'friendly_name': 'WLED RGB Light Segment 1 speed',
       'icon': 'mdi:speedometer',
       'max': 255,
       'min': 0,
@@ -127,11 +127,11 @@
     }),
     'original_device_class': None,
     'original_icon': 'mdi:speedometer',
-    'original_name': 'Segment 1 Speed',
+    'original_name': 'Segment 1 speed',
     'platform': 'wled',
     'previous_unique_id': None,
     'supported_features': 0,
-    'translation_key': None,
+    'translation_key': 'segment_speed',
     'unique_id': 'aabbccddeeff_speed_1',
     'unit_of_measurement': None,
   })
diff --git a/tests/components/wled/snapshots/test_select.ambr b/tests/components/wled/snapshots/test_select.ambr
index 92604f86d2d..9c8cb52b4a6 100644
--- a/tests/components/wled/snapshots/test_select.ambr
+++ b/tests/components/wled/snapshots/test_select.ambr
@@ -230,7 +230,7 @@
     'platform': 'wled',
     'previous_unique_id': None,
     'supported_features': 0,
-    'translation_key': None,
+    'translation_key': 'segment_color_palette',
     'unique_id': 'aabbccddeeff_palette_1',
     'unit_of_measurement': None,
   })
diff --git a/tests/components/wled/snapshots/test_switch.ambr b/tests/components/wled/snapshots/test_switch.ambr
index feecfd1e1ff..8031624c75b 100644
--- a/tests/components/wled/snapshots/test_switch.ambr
+++ b/tests/components/wled/snapshots/test_switch.ambr
@@ -117,7 +117,7 @@
     'platform': 'wled',
     'previous_unique_id': None,
     'supported_features': 0,
-    'translation_key': None,
+    'translation_key': 'reverse',
     'unique_id': 'aabbccddeeff_reverse_0',
     'unit_of_measurement': None,
   })
-- 
GitLab