Răsfoiți Sursa

Add support for Compteur Energy Meter

Issue #202
Jason Rumney 3 ani în urmă
părinte
comite
9b8da34ed4

+ 1 - 1
ACKNOWLEDGEMENTS.md

@@ -94,7 +94,7 @@ Further device support has been made with the assistance of users.  Please consi
 - [Krispkiwi](https://github.com/Krispkiwi) for assistance with M027 curtain modules and debugging Kogan Kettle.
 - [craibo](https://github.com/craibo) for contributing support for Jiahong ET-72W thermostats.
 - [x-keita](https://github.com/x-keita) for contributing support for Betterlife BL1500 IR heaters and Nexxt smart switches.
-- [Der-Nax](https:github.com/Der-Nax) for assistant with a second variant of energy monitoring smart switch and for contributing support for PY321-TY power clamps.
+- [Der-Nax](https:github.com/Der-Nax) for assistant with a second variant of energy monitoring smart switch and for contributing support for PY321-TY power clamps and Compteur smart meters.
 - [17hoehbr](https://github.com/17hoehbr) for assistance supporting APOSEN A550
 - [yurgh](https://github.com/yurgh) for assistant supporting Eesee Adam dehumidifier
 - [KaportsevIA](https://github.com/KaportsevIA) for assistance supporting Hyundai Sahara dehumidifier, Yandax color bulb and ES01 powerstrip.

+ 1 - 0
README.md

@@ -139,6 +139,7 @@ the device will not work despite being listed below.
 ### Smart Meter/Circuit Breaker
 - SmartMCB SMT006 Energy Meter
 - PC321-TY 3 phase Power Clamp meter
+- Compteur Digital Electric (single phase)
 
 ### Battery Charger
 - Parkside PLGS 2012 A1 Smart Charger for powertools

+ 70 - 0
custom_components/tuya_local/devices/compteur_energy_meter.yaml

@@ -0,0 +1,70 @@
+name: Compteur Digital Electric
+products:
+  - id: 1whdy4a8ypamjloi
+primary_entity:
+  entity: sensor
+  class: energy
+  dps:
+    - id: 17
+      type: integer
+      name: sensor
+      mapping:
+        - scale: 1000
+      unit: kWh
+      class: total_increasing
+    - id: 21
+      name: unknown_21
+      type: integer
+    - id: 22
+      name: unknown_22
+      type: integer
+    - id: 23
+      name: unknown_23
+      type: integer
+    - id: 24
+      name: unknown_24
+      type: integer
+    - id: 25
+      name: unknown_25
+      type: integer
+    - id: 26
+      name: unknown_26
+      type: integer
+secondary_entities:
+  - entity: sensor
+    category: diagnostic
+    name: Voltage
+    class: voltage
+    dps:
+      - id: 20
+        name: sensor
+        type: integer
+        unit: V
+        class: measurement
+        mapping:
+          - scale: 10
+  - entity: sensor
+    category: diagnostic
+    class: current
+    name: Current
+    dps:
+      - id: 18
+        name: sensor
+        type: integer
+        unit: A
+        class: measurement
+        mapping:
+          - scale: 1000
+  - entity: sensor
+    category: diagnostic
+    class: power
+    name: Power
+    dps:
+      - id: 19
+        name: sensor
+        type: integer
+        unit: W
+        class: measurement
+        mapping:
+          - scale: 10
+

+ 13 - 0
tests/const.py

@@ -1421,3 +1421,16 @@ ENERGY_POWERSTRIP_PAYLOAD = {
     "108": 101000,
     "109": 205,
 }
+
+COMPTEUR_SMARTMETER_PAYLOAD = {
+    "17": 12345,
+    "18": 2000,
+    "19": 4400,
+    "20": 2200,
+    "21": 0,
+    "22": 0,
+    "23": 0,
+    "24": 0,
+    "25": 0,
+    "26": 0,
+}

+ 105 - 0
tests/devices/test_compteur_energy_meter.py

@@ -0,0 +1,105 @@
+"""Tests for the Compteur Energy meter"""
+from homeassistant.components.sensor import (
+    SensorDeviceClass,
+    STATE_CLASS_MEASUREMENT,
+    STATE_CLASS_TOTAL_INCREASING,
+)
+from homeassistant.const import (
+    ELECTRIC_CURRENT_AMPERE,
+    ELECTRIC_POTENTIAL_VOLT,
+    ENERGY_KILO_WATT_HOUR,
+    POWER_WATT,
+)
+
+from ..const import COMPTEUR_SMARTMETER_PAYLOAD
+from ..mixins.sensor import MultiSensorTests
+from .base_device_tests import TuyaDeviceTestCase
+
+
+ENERGY_DP = "17"
+CURRENT_DP = "18"
+POWER_DP = "19"
+VOLTAGE_DP = "20"
+UNKNOWN21_DP = "21"
+UNKNOWN22_DP = "22"
+UNKNOWN23_DP = "23"
+UNKNOWN24_DP = "24"
+UNKNOWN25_DP = "25"
+UNKNOWN26_DP = "26"
+
+
+class TestCompteurEnergyMeter(MultiSensorTests, TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig(
+            "compteur_energy_meter.yaml",
+            COMPTEUR_SMARTMETER_PAYLOAD,
+        )
+        self.setUpMultiSensors(
+            [
+                {
+                    "dps": ENERGY_DP,
+                    "name": "sensor",
+                    "unit": ENERGY_KILO_WATT_HOUR,
+                    "device_class": SensorDeviceClass.ENERGY,
+                    "state_class": STATE_CLASS_TOTAL_INCREASING,
+                    "testdata": (12345, 12.345),
+                },
+                {
+                    "dps": VOLTAGE_DP,
+                    "name": "sensor_voltage",
+                    "unit": ELECTRIC_POTENTIAL_VOLT,
+                    "device_class": SensorDeviceClass.VOLTAGE,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (2348, 234.8),
+                },
+                {
+                    "dps": CURRENT_DP,
+                    "name": "sensor_current",
+                    "unit": ELECTRIC_CURRENT_AMPERE,
+                    "device_class": SensorDeviceClass.CURRENT,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (4567, 4.567),
+                },
+                {
+                    "dps": POWER_DP,
+                    "name": "sensor_power",
+                    "unit": POWER_WATT,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "device_class": SensorDeviceClass.POWER,
+                    "testdata": (890, 89.0),
+                },
+            ]
+        )
+        self.mark_secondary(
+            [
+                "sensor_voltage",
+                "sensor_current",
+                "sensor_power",
+            ]
+        )
+
+    def test_multi_sensor_extra_state_attributes(self):
+        self.dps[UNKNOWN21_DP] = 21
+        self.dps[UNKNOWN22_DP] = 22
+        self.dps[UNKNOWN23_DP] = 23
+        self.dps[UNKNOWN24_DP] = 24
+        self.dps[UNKNOWN25_DP] = 25
+        self.dps[UNKNOWN26_DP] = 26
+
+        for k, v in self.multiSensor.items():
+            if k == "sensor":
+                self.assertDictEqual(
+                    v.extra_state_attributes,
+                    {
+                        "unknown_21": 21,
+                        "unknown_22": 22,
+                        "unknown_23": 23,
+                        "unknown_24": 24,
+                        "unknown_25": 25,
+                        "unknown_26": 26,
+                    },
+                )
+            else:
+                self.assertEqual(v.extra_state_attributes, {})