Explorar o código

Smartplugs: disable non-working energy sensors by default

Many smartplugs provide an "add_ele" dp which reports energy usage
over such a short period that it is not usable as an energy sensor
within HA. On some smartplugs this was initially exposed as a sensor
entity in case it was useful in specific cases, but in general we now
know it is not useful, so later configs have this as an attribute of
the switch or power sensor instead.

For those configs that have it as a separate entity, this change
disables the entity by default, to avoid confusing users over its
usefulness. The change also adds the measurement class so that if
users enable it, they can get long term statistics.

Issue #3000
Jason Rumney hai 11 meses
pai
achega
7d9f0caa95

+ 2 - 0
custom_components/tuya_local/devices/aubess_1gang_switch.yaml

@@ -87,11 +87,13 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 20
         name: sensor
         type: integer
         optional: true
+        class: measurement
         unit: Wh
   - entity: sensor
     class: current

+ 2 - 0
custom_components/tuya_local/devices/blitzwolf_bwshp6_smartplug.yaml

@@ -21,11 +21,13 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 17
         type: integer
         name: sensor
         unit: Wh
+        class: measurement
         optional: true
       - id: 25
         type: integer

+ 2 - 0
custom_components/tuya_local/devices/brilliant_double_switch.yaml

@@ -59,11 +59,13 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 101
         type: integer
         name: sensor
         unit: kWh
+        class: measurement
         mapping:
           - scale: 1000
   - entity: sensor

+ 2 - 0
custom_components/tuya_local/devices/brilliant_quad_switch.yaml

@@ -111,11 +111,13 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 101
         type: integer
         name: sensor
         unit: kWh
+        class: measurement
         mapping:
           - scale: 1000
   - entity: sensor

+ 2 - 0
custom_components/tuya_local/devices/brilliant_single_switch.yaml

@@ -28,11 +28,13 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 101
         type: integer
         name: sensor
         unit: kWh
+        class: measurement
         mapping:
           - scale: 1000
   - entity: sensor

+ 2 - 0
custom_components/tuya_local/devices/brilliant_triple_switch.yaml

@@ -85,11 +85,13 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 101
         type: integer
         name: sensor
         unit: kWh
+        class: measurement
         mapping:
           - scale: 1000
   - entity: sensor

+ 2 - 0
custom_components/tuya_local/devices/gosund_sp112_usbsmartplug.yaml

@@ -35,11 +35,13 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 17
         type: integer
         name: sensor
         unit: Wh
+        class: measurement
         optional: true
       - id: 25
         type: integer

+ 2 - 0
custom_components/tuya_local/devices/grid_connect_usb_double_power_point.yaml

@@ -38,12 +38,14 @@ entities:
         type: boolean
   - entity: sensor
     category: diagnostic
+    hidden: true
     name: Energy
     dps:
       - id: 17
         name: sensor
         type: integer
         unit: Wh
+        class: measurement
       - id: 25
         name: calibration
         type: integer

+ 2 - 0
custom_components/tuya_local/devices/loratap_dual_switch.yaml

@@ -92,11 +92,13 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 20
         name: sensor
         type: integer
         optional: true
+        class: measurement
         unit: kWh
         mapping:
           - scale: 1000

+ 2 - 0
custom_components/tuya_local/devices/pj1103_clamp_meter.yaml

@@ -91,12 +91,14 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 17
         type: integer
         name: sensor
         optional: true
         unit: kWh
+        class: measurement
         mapping:
           - dps_val: null
           - scale: 1000

+ 2 - 0
custom_components/tuya_local/devices/smart_powerstrip_3_outlet_energy.yaml

@@ -96,6 +96,7 @@ entities:
             step: 60
   - entity: sensor
     category: diagnostic
+    hidden: true
     name: Energy
     dps:
       - id: 17
@@ -103,6 +104,7 @@ entities:
         type: integer
         unit: kWh
         optional: true
+        class: measurement
         mapping:
           - scale: 1000
       - id: 25

+ 2 - 0
custom_components/tuya_local/devices/smartplugv2_childlock.yaml

@@ -34,12 +34,14 @@ entities:
   - entity: sensor
     name: Energy
     category: diagnostic
+    hidden: true
     dps:
       - id: 17
         type: integer
         name: sensor
         unit: Wh
         optional: true
+        class: measurement
   - entity: sensor
     class: current
     category: diagnostic

+ 2 - 0
custom_components/tuya_local/devices/smartplugv2_energy.yaml

@@ -51,12 +51,14 @@ entities:
             step: 60
   - entity: sensor
     category: diagnostic
+    hidden: true
     name: Energy
     dps:
       - id: 17
         name: sensor
         type: integer
         unit: Wh
+        class: measurement
         optional: true
       - id: 25
         type: integer

+ 2 - 0
custom_components/tuya_local/devices/smartplugv2_energyv2.yaml

@@ -50,6 +50,7 @@ entities:
             step: 60
   - entity: sensor
     category: diagnostic
+    hidden: true
     name: Energy
     dps:
       - id: 17
@@ -57,6 +58,7 @@ entities:
         type: integer
         optional: true
         unit: Wh
+        class: measurement
       - id: 25
         type: integer
         name: calibration

+ 2 - 0
custom_components/tuya_local/devices/smartplugv2_energyv3.yaml

@@ -53,6 +53,7 @@ entities:
             step: 60
   - entity: sensor
     category: diagnostic
+    hidden: true
     name: Energy
     dps:
       - id: 17
@@ -60,6 +61,7 @@ entities:
         type: integer
         unit: Wh
         optional: true
+        class: measurement
       - id: 25
         type: integer
         name: calibration

+ 1 - 0
tests/devices/test_grid_connect_double_power_point.py

@@ -90,6 +90,7 @@ class TestGridConnectDoubleSwitch(
                     "name": "sensor_energy",
                     "dps": ENERGY_DPS,
                     "unit": UnitOfEnergy.WATT_HOUR,
+                    "state_class": "measurement",
                 },
                 {
                     "name": "sensor_current",

+ 1 - 0
tests/devices/test_smartplugv2_energy.py

@@ -94,6 +94,7 @@ class TestSwitchV2Energy(
                     "name": "sensor_energy",
                     "dps": ENERGY_DPS,
                     "unit": UnitOfEnergy.WATT_HOUR,
+                    "state_class": "measurement",
                 },
                 {
                     "name": "sensor_voltage",