From 94e4863cbe727ebe4094e2958d637262f94a6216 Mon Sep 17 00:00:00 2001
From: "Teemu R." <tpr@iki.fi>
Date: Wed, 29 Jan 2025 06:34:26 +0100
Subject: [PATCH] Add power protection entities for tplink (#132267)

Co-authored-by: Steven B <51370195+sdb9696@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
---
 .../components/tplink/binary_sensor.py        |  4 ++
 homeassistant/components/tplink/number.py     |  4 ++
 homeassistant/components/tplink/strings.json  |  6 ++
 .../components/tplink/fixtures/features.json  | 11 ++++
 .../tplink/snapshots/test_binary_sensor.ambr  | 47 ++++++++++++++++
 .../tplink/snapshots/test_number.ambr         | 55 +++++++++++++++++++
 6 files changed, 127 insertions(+)

diff --git a/homeassistant/components/tplink/binary_sensor.py b/homeassistant/components/tplink/binary_sensor.py
index e08495f5c88..6986765b110 100644
--- a/homeassistant/components/tplink/binary_sensor.py
+++ b/homeassistant/components/tplink/binary_sensor.py
@@ -35,6 +35,10 @@ BINARY_SENSOR_DESCRIPTIONS: Final = (
         key="overheated",
         device_class=BinarySensorDeviceClass.PROBLEM,
     ),
+    TPLinkBinarySensorEntityDescription(
+        key="overloaded",
+        device_class=BinarySensorDeviceClass.PROBLEM,
+    ),
     TPLinkBinarySensorEntityDescription(
         key="battery_low",
         device_class=BinarySensorDeviceClass.BATTERY,
diff --git a/homeassistant/components/tplink/number.py b/homeassistant/components/tplink/number.py
index b47c50d688f..a9d002c0083 100644
--- a/homeassistant/components/tplink/number.py
+++ b/homeassistant/components/tplink/number.py
@@ -65,6 +65,10 @@ NUMBER_DESCRIPTIONS: Final = (
         key="tilt_step",
         mode=NumberMode.BOX,
     ),
+    TPLinkNumberEntityDescription(
+        key="power_protection_threshold",
+        mode=NumberMode.SLIDER,
+    ),
     TPLinkNumberEntityDescription(
         key="clean_count",
         mode=NumberMode.SLIDER,
diff --git a/homeassistant/components/tplink/strings.json b/homeassistant/components/tplink/strings.json
index 034aff7a763..fe661fa2529 100644
--- a/homeassistant/components/tplink/strings.json
+++ b/homeassistant/components/tplink/strings.json
@@ -109,6 +109,9 @@
       "overheated": {
         "name": "Overheated"
       },
+      "overloaded": {
+        "name": "Overloaded"
+      },
       "cloud_connection": {
         "name": "Cloud connection"
       },
@@ -268,6 +271,9 @@
       "temperature_offset": {
         "name": "Temperature offset"
       },
+      "power_protection_threshold": {
+        "name": "Power protection"
+      },
       "pan_step": {
         "name": "Pan degrees"
       },
diff --git a/tests/components/tplink/fixtures/features.json b/tests/components/tplink/fixtures/features.json
index d366a91c33c..c49c5881d5c 100644
--- a/tests/components/tplink/fixtures/features.json
+++ b/tests/components/tplink/fixtures/features.json
@@ -195,6 +195,11 @@
     "type": "BinarySensor",
     "category": "Info"
   },
+  "overloaded": {
+    "value": false,
+    "type": "BinarySensor",
+    "category": "Info"
+  },
   "battery_low": {
     "value": false,
     "type": "BinarySensor",
@@ -284,6 +289,12 @@
     "minimum_value": -10,
     "maximum_value": 10
   },
+  "power_protection_threshold": {
+    "value": 100,
+    "type": "Number",
+    "category": "Config",
+    "minimum_value": 0
+  },
   "target_temperature": {
     "value": false,
     "type": "Number",
diff --git a/tests/components/tplink/snapshots/test_binary_sensor.ambr b/tests/components/tplink/snapshots/test_binary_sensor.ambr
index e16d4409511..125592b053c 100644
--- a/tests/components/tplink/snapshots/test_binary_sensor.ambr
+++ b/tests/components/tplink/snapshots/test_binary_sensor.ambr
@@ -300,6 +300,53 @@
     'state': 'off',
   })
 # ---
+# name: test_states[binary_sensor.my_device_overloaded-entry]
+  EntityRegistryEntrySnapshot({
+    'aliases': set({
+    }),
+    'area_id': None,
+    'capabilities': None,
+    'config_entry_id': <ANY>,
+    'device_class': None,
+    'device_id': <ANY>,
+    'disabled_by': None,
+    'domain': 'binary_sensor',
+    'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
+    'entity_id': 'binary_sensor.my_device_overloaded',
+    'has_entity_name': True,
+    'hidden_by': None,
+    'icon': None,
+    'id': <ANY>,
+    'labels': set({
+    }),
+    'name': None,
+    'options': dict({
+    }),
+    'original_device_class': <BinarySensorDeviceClass.PROBLEM: 'problem'>,
+    'original_icon': None,
+    'original_name': 'Overloaded',
+    'platform': 'tplink',
+    'previous_unique_id': None,
+    'supported_features': 0,
+    'translation_key': 'overloaded',
+    'unique_id': '123456789ABCDEFGH_overloaded',
+    'unit_of_measurement': None,
+  })
+# ---
+# name: test_states[binary_sensor.my_device_overloaded-state]
+  StateSnapshot({
+    'attributes': ReadOnlyDict({
+      'device_class': 'problem',
+      'friendly_name': 'my_device Overloaded',
+    }),
+    'context': <ANY>,
+    'entity_id': 'binary_sensor.my_device_overloaded',
+    'last_changed': <ANY>,
+    'last_reported': <ANY>,
+    'last_updated': <ANY>,
+    'state': 'off',
+  })
+# ---
 # name: test_states[binary_sensor.my_device_temperature_warning-entry]
   EntityRegistryEntrySnapshot({
     'aliases': set({
diff --git a/tests/components/tplink/snapshots/test_number.ambr b/tests/components/tplink/snapshots/test_number.ambr
index 6733c5423a0..4bdb92aeab6 100644
--- a/tests/components/tplink/snapshots/test_number.ambr
+++ b/tests/components/tplink/snapshots/test_number.ambr
@@ -145,6 +145,61 @@
     'state': '10',
   })
 # ---
+# name: test_states[number.my_device_power_protection-entry]
+  EntityRegistryEntrySnapshot({
+    'aliases': set({
+    }),
+    'area_id': None,
+    'capabilities': dict({
+      'max': 65536,
+      'min': 0,
+      'mode': <NumberMode.SLIDER: 'slider'>,
+      'step': 1.0,
+    }),
+    'config_entry_id': <ANY>,
+    'device_class': None,
+    'device_id': <ANY>,
+    'disabled_by': None,
+    'domain': 'number',
+    'entity_category': <EntityCategory.CONFIG: 'config'>,
+    'entity_id': 'number.my_device_power_protection',
+    'has_entity_name': True,
+    'hidden_by': None,
+    'icon': None,
+    'id': <ANY>,
+    'labels': set({
+    }),
+    'name': None,
+    'options': dict({
+    }),
+    'original_device_class': None,
+    'original_icon': None,
+    'original_name': 'Power protection',
+    'platform': 'tplink',
+    'previous_unique_id': None,
+    'supported_features': 0,
+    'translation_key': 'power_protection_threshold',
+    'unique_id': '123456789ABCDEFGH_power_protection_threshold',
+    'unit_of_measurement': None,
+  })
+# ---
+# name: test_states[number.my_device_power_protection-state]
+  StateSnapshot({
+    'attributes': ReadOnlyDict({
+      'friendly_name': 'my_device Power protection',
+      'max': 65536,
+      'min': 0,
+      'mode': <NumberMode.SLIDER: 'slider'>,
+      'step': 1.0,
+    }),
+    'context': <ANY>,
+    'entity_id': 'number.my_device_power_protection',
+    'last_changed': <ANY>,
+    'last_reported': <ANY>,
+    'last_updated': <ANY>,
+    'state': '100',
+  })
+# ---
 # name: test_states[number.my_device_smooth_off-entry]
   EntityRegistryEntrySnapshot({
     'aliases': set({
-- 
GitLab