From 58f8f9c82ac7fea17bd76a2d26d594d150a4de8a Mon Sep 17 00:00:00 2001
From: Patrick ZAJDA <patrick@zajda.fr>
Date: Tue, 27 Jun 2023 11:52:20 +0200
Subject: [PATCH] Add state attribute translations to Switchbot (#90861)

---
 homeassistant/components/switchbot/cover.py   |  2 +
 .../components/switchbot/humidifier.py        |  1 +
 homeassistant/components/switchbot/lock.py    |  1 +
 .../components/switchbot/strings.json         | 54 +++++++++++++++++++
 homeassistant/components/switchbot/switch.py  |  1 +
 5 files changed, 59 insertions(+)

diff --git a/homeassistant/components/switchbot/cover.py b/homeassistant/components/switchbot/cover.py
index 495ce0468a0..da6c710fed8 100644
--- a/homeassistant/components/switchbot/cover.py
+++ b/homeassistant/components/switchbot/cover.py
@@ -51,6 +51,7 @@ class SwitchBotCurtainEntity(SwitchbotEntity, CoverEntity, RestoreEntity):
         | CoverEntityFeature.STOP
         | CoverEntityFeature.SET_POSITION
     )
+    _attr_translation_key = "cover"
 
     def __init__(self, coordinator: SwitchbotDataUpdateCoordinator) -> None:
         """Initialize the Switchbot."""
@@ -120,6 +121,7 @@ class SwitchBotBlindTiltEntity(SwitchbotEntity, CoverEntity, RestoreEntity):
         | CoverEntityFeature.STOP_TILT
         | CoverEntityFeature.SET_TILT_POSITION
     )
+    _attr_translation_key = "cover"
     CLOSED_UP_THRESHOLD = 80
     CLOSED_DOWN_THRESHOLD = 20
 
diff --git a/homeassistant/components/switchbot/humidifier.py b/homeassistant/components/switchbot/humidifier.py
index 148e4c3545f..e5f1e3c46b4 100644
--- a/homeassistant/components/switchbot/humidifier.py
+++ b/homeassistant/components/switchbot/humidifier.py
@@ -40,6 +40,7 @@ class SwitchBotHumidifier(SwitchbotSwitchedEntity, HumidifierEntity):
     _attr_available_modes = [MODE_NORMAL, MODE_AUTO]
     _device: switchbot.SwitchbotHumidifier
     _attr_min_humidity = 1
+    _attr_translation_key = "humidifier"
 
     @property
     def is_on(self) -> bool | None:
diff --git a/homeassistant/components/switchbot/lock.py b/homeassistant/components/switchbot/lock.py
index 738755ae636..69ce0aa4750 100644
--- a/homeassistant/components/switchbot/lock.py
+++ b/homeassistant/components/switchbot/lock.py
@@ -26,6 +26,7 @@ async def async_setup_entry(
 class SwitchBotLock(SwitchbotEntity, LockEntity):
     """Representation of a Switchbot lock."""
 
+    _attr_translation_key = "lock"
     _device: switchbot.SwitchbotLock
 
     def __init__(self, coordinator: SwitchbotDataUpdateCoordinator) -> None:
diff --git a/homeassistant/components/switchbot/strings.json b/homeassistant/components/switchbot/strings.json
index 74226583420..2d31a883e4b 100644
--- a/homeassistant/components/switchbot/strings.json
+++ b/homeassistant/components/switchbot/strings.json
@@ -108,6 +108,60 @@
       "power": {
         "name": "[%key:component::sensor::entity_component::power::name%]"
       }
+    },
+    "cover": {
+      "cover": {
+        "state_attributes": {
+          "last_run_success": {
+            "state": {
+              "true": "[%key:component::binary_sensor::entity_component::problem::state::off%]",
+              "false": "[%key:component::binary_sensor::entity_component::problem::state::on%]"
+            }
+          }
+        }
+      }
+    },
+    "humidifier": {
+      "humidifier": {
+        "state_attributes": {
+          "last_run_success": {
+            "state": {
+              "true": "[%key:component::binary_sensor::entity_component::problem::state::off%]",
+              "false": "[%key:component::binary_sensor::entity_component::problem::state::on%]"
+            }
+          }
+        }
+      }
+    },
+    "lock": {
+      "lock": {
+        "state_attributes": {
+          "last_run_success": {
+            "state": {
+              "true": "[%key:component::binary_sensor::entity_component::problem::state::off%]",
+              "false": "[%key:component::binary_sensor::entity_component::problem::state::on%]"
+            }
+          }
+        }
+      }
+    },
+    "switch": {
+      "bot": {
+        "state_attributes": {
+          "last_run_success": {
+            "state": {
+              "true": "[%key:component::binary_sensor::entity_component::problem::state::off%]",
+              "false": "[%key:component::binary_sensor::entity_component::problem::state::on%]"
+            }
+          },
+          "switch_mode": {
+            "state": {
+              "true": "Pull/Retract",
+              "false": "Momentary"
+            }
+          }
+        }
+      }
     }
   }
 }
diff --git a/homeassistant/components/switchbot/switch.py b/homeassistant/components/switchbot/switch.py
index befbf00f8be..25b76ea24cb 100644
--- a/homeassistant/components/switchbot/switch.py
+++ b/homeassistant/components/switchbot/switch.py
@@ -34,6 +34,7 @@ class SwitchBotSwitch(SwitchbotSwitchedEntity, SwitchEntity, RestoreEntity):
     """Representation of a Switchbot switch."""
 
     _attr_device_class = SwitchDeviceClass.SWITCH
+    _attr_translation_key = "bot"
     _device: switchbot.Switchbot
 
     def __init__(self, coordinator: SwitchbotDataUpdateCoordinator) -> None: