Pārlūkot izejas kodu

Add support for PC321-TY 3-phase power clamp meter.

Issue #192
Jason Rumney 3 gadi atpakaļ
vecāks
revīzija
7c48df8fbb

+ 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.
-- [Der-Nax](https:github.com/Der-Nax) for assistant with a second variant of energy monitoring smart switch.
+- [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.
 - [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 and Yandax color bulb.

+ 1 - 0
README.md

@@ -137,6 +137,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
 
 ### Battery Charger
 - Parkside PLGS 2012 A1 Smart Charger for powertools

+ 230 - 0
custom_components/tuya_local/devices/pc321ty_energy_meter.yaml

@@ -0,0 +1,230 @@
+name: PC321-TY Power Clamp
+product:
+  - id: r64livttuufctble
+primary_entity:
+  entity: sensor
+  class: energy
+  dps:
+    - id: 131
+      type: integer
+      name: sensor
+      mapping:
+        - scale: 100
+      unit: kWh
+      class: total_increasing
+secondary_entities:
+  - entity: sensor
+    category: diagnostic
+    name: Voltage A
+    class: voltage
+    dps:
+      - id: 101
+        name: sensor
+        type: integer
+        unit: V
+        class: measurement
+        mapping:
+          - scale: 10
+  - entity: sensor
+    category: diagnostic
+    class: current
+    name: Current A
+    dps:
+      - id: 102
+        name: sensor
+        type: integer
+        unit: A
+        class: measurement
+        mapping:
+          - scale: 1000
+  - entity: sensor
+    category: diagnostic
+    class: power
+    name: Power A
+    dps:
+      - id: 103
+        name: sensor
+        type: integer
+        unit: W
+        class: measurement
+  - entity: sensor
+    category: diagnostic
+    class: power_factor
+    name: Power factor A
+    dps:
+      - id: 104
+        name: sensor
+        type: integer
+        class: measurement
+        mapping:
+          - scale: 100
+  - entity: sensor
+    category: diagnostic
+    class: energy
+    name: Energy A
+    dps:
+      - id: 106
+        name: sensor
+        type: integer
+        unit: kWh
+        class: total_increasing
+        mapping:
+          - scale: 100
+  - entity: sensor
+    category: diagnostic
+    name: Voltage B
+    class: voltage
+    dps:
+      - id: 111
+        name: sensor
+        type: integer
+        unit: V
+        class: measurement
+        mapping:
+          - scale: 10
+  - entity: sensor
+    category: diagnostic
+    class: current
+    name: Current B
+    dps:
+      - id: 112
+        name: sensor
+        type: integer
+        unit: A
+        class: measurement
+        mapping:
+          - scale: 1000
+  - entity: sensor
+    category: diagnostic
+    class: power
+    name: Power B
+    dps:
+      - id: 113
+        name: sensor
+        type: integer
+        unit: W
+        class: measurement
+  - entity: sensor
+    category: diagnostic
+    class: power_factor
+    name: Power factor B
+    dps:
+      - id: 114
+        name: sensor
+        type: integer
+        class: measurement
+        mapping:
+          - scale: 100
+  - entity: sensor
+    category: diagnostic
+    class: energy
+    name: Energy B
+    dps:
+      - id: 116
+        name: sensor
+        type: integer
+        unit: kWh
+        class: total_increasing
+        mapping:
+          - scale: 100
+  - entity: sensor
+    category: diagnostic
+    name: Voltage C
+    class: voltage
+    dps:
+      - id: 121
+        name: sensor
+        type: integer
+        unit: V
+        class: measurement
+        mapping:
+          - scale: 10
+  - entity: sensor
+    category: diagnostic
+    class: current
+    name: Current C
+    dps:
+      - id: 122
+        name: sensor
+        type: integer
+        unit: A
+        class: measurement
+        mapping:
+          - scale: 1000
+  - entity: sensor
+    category: diagnostic
+    class: power
+    name: Power C
+    dps:
+      - id: 123
+        name: sensor
+        type: integer
+        class: measurement
+        unit: W
+  - entity: sensor
+    category: diagnostic
+    class: power_factor
+    name: Power factor C
+    dps:
+      - id: 124
+        name: sensor
+        type: integer
+        class: measurement
+        mapping:
+          - scale: 100
+  - entity: sensor
+    category: diagnostic
+    class: energy
+    name: Energy C
+    dps:
+      - id: 126
+        name: sensor
+        type: integer
+        unit: kWh
+        class: total_increasing
+        mapping:
+          - scale: 100
+  - entity: sensor
+    category: diagnostic
+    class: current
+    name: Total current
+    dps:
+      - id: 132
+        type: integer
+        name: sensor
+        unit: A
+        class: measurement
+        mapping:
+          - scale: 1000
+  - entity: sensor
+    category: diagnostic
+    class: power
+    name: Total active power
+    dps:
+      - id: 133
+        type: integer
+        name: sensor
+        unit: W
+        class: measurement
+  - entity: sensor
+    category: diagnostic
+    class: frequency
+    name: Frequency
+    dps:
+      - id: 135
+        type: integer
+        name: sensor
+        unit: Hz
+        class: measurement
+  - entity: sensor
+    category: diagnostic
+    class: temperature
+    name: Temperature
+    dps:
+      - id: 136
+        type: integer
+        name: sensor
+        unit: C
+        class: measurement
+        mapping:
+          - scale: 10

+ 23 - 0
tests/const.py

@@ -1353,3 +1353,26 @@ ELECTRIQ_AIRFLEX15W_PAYLOAD = {
     "111": 80,
     "112": 68,
 }
+
+PC321TY_POWERCLAMP_PAYLOAD = {
+    "101": 2284,
+    "102": 1073,
+    "103": 191,
+    "104": 78,
+    "106": 251,
+    "111": 2354,
+    "112": 748,
+    "113": 47,
+    "114": 100,
+    "116": 267,
+    "121": 2350,
+    "122": 753,
+    "123": 149,
+    "124": 84,
+    "126": 517,
+    "131": 1036,
+    "132": 2574,
+    "133": 188,
+    "135": 50,
+    "136": 390,
+}

+ 228 - 0
tests/devices/test_pc321ty_energy_meter.py

@@ -0,0 +1,228 @@
+"""Tests for the PC321-TY Power Clamp 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,
+    FREQUENCY_HERTZ,
+    POWER_WATT,
+    TEMP_CELSIUS,
+)
+
+from ..const import PC321TY_POWERCLAMP_PAYLOAD
+from ..mixins.sensor import MultiSensorTests
+from .base_device_tests import TuyaDeviceTestCase
+
+VOLTAGE1_DP = "101"
+CURRENT1_DP = "102"
+POWER1_DP = "103"
+PFACTOR1_DP = "104"
+ENERGY1_DP = "106"
+VOLTAGE2_DP = "111"
+CURRENT2_DP = "112"
+POWER2_DP = "113"
+PFACTOR2_DP = "114"
+ENERGY2_DP = "116"
+VOLTAGE3_DP = "121"
+CURRENT3_DP = "122"
+POWER3_DP = "123"
+PFACTOR3_DP = "124"
+ENERGY3_DP = "126"
+TOTALENERGY_DP = "131"
+TOTALCURRENT_DP = "132"
+TOTALPOWER_DP = "133"
+FREQUENCY_DP = "135"
+TEMPERATURE_DP = "136"
+
+
+class TestPC321TYPowerClamp(MultiSensorTests, TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig(
+            "pc321ty_energy_meter.yaml",
+            PC321TY_POWERCLAMP_PAYLOAD,
+        )
+        self.setUpMultiSensors(
+            [
+                {
+                    "dps": TOTALENERGY_DP,
+                    "name": "sensor",
+                    "unit": ENERGY_KILO_WATT_HOUR,
+                    "device_class": SensorDeviceClass.ENERGY,
+                    "state_class": STATE_CLASS_TOTAL_INCREASING,
+                    "testdata": (12345, 123.45),
+                },
+                {
+                    "dps": VOLTAGE1_DP,
+                    "name": "sensor_voltage_a",
+                    "unit": ELECTRIC_POTENTIAL_VOLT,
+                    "device_class": SensorDeviceClass.VOLTAGE,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (2348, 234.8),
+                },
+                {
+                    "dps": CURRENT1_DP,
+                    "name": "sensor_current_a",
+                    "unit": ELECTRIC_CURRENT_AMPERE,
+                    "device_class": SensorDeviceClass.CURRENT,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (4567, 4.567),
+                },
+                {
+                    "dps": POWER1_DP,
+                    "name": "sensor_power_a",
+                    "unit": POWER_WATT,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "device_class": SensorDeviceClass.POWER,
+                },
+                {
+                    "dps": PFACTOR1_DP,
+                    "name": "sensor_power_factor_a",
+                    "device_class": SensorDeviceClass.POWER_FACTOR,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (5000, 50.00),
+                },
+                {
+                    "dps": ENERGY1_DP,
+                    "name": "sensor_energy_a",
+                    "unit": ENERGY_KILO_WATT_HOUR,
+                    "device_class": SensorDeviceClass.ENERGY,
+                    "state_class": STATE_CLASS_TOTAL_INCREASING,
+                    "testdata": (12345, 123.45),
+                },
+                {
+                    "dps": VOLTAGE2_DP,
+                    "name": "sensor_voltage_b",
+                    "unit": ELECTRIC_POTENTIAL_VOLT,
+                    "device_class": SensorDeviceClass.VOLTAGE,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (2348, 234.8),
+                },
+                {
+                    "dps": CURRENT2_DP,
+                    "name": "sensor_current_b",
+                    "unit": ELECTRIC_CURRENT_AMPERE,
+                    "device_class": SensorDeviceClass.CURRENT,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (4567, 4.567),
+                },
+                {
+                    "dps": POWER2_DP,
+                    "name": "sensor_power_b",
+                    "unit": POWER_WATT,
+                    "device_class": SensorDeviceClass.POWER,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                },
+                {
+                    "dps": PFACTOR2_DP,
+                    "name": "sensor_power_factor_b",
+                    "device_class": SensorDeviceClass.POWER_FACTOR,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (5000, 50.00),
+                },
+                {
+                    "dps": ENERGY2_DP,
+                    "name": "sensor_energy_b",
+                    "unit": ENERGY_KILO_WATT_HOUR,
+                    "device_class": SensorDeviceClass.ENERGY,
+                    "state_class": STATE_CLASS_TOTAL_INCREASING,
+                    "testdata": (12345, 123.45),
+                },
+                {
+                    "dps": VOLTAGE3_DP,
+                    "name": "sensor_voltage_c",
+                    "unit": ELECTRIC_POTENTIAL_VOLT,
+                    "device_class": SensorDeviceClass.VOLTAGE,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (2348, 234.8),
+                },
+                {
+                    "dps": CURRENT3_DP,
+                    "name": "sensor_current_c",
+                    "unit": ELECTRIC_CURRENT_AMPERE,
+                    "device_class": SensorDeviceClass.CURRENT,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (4567, 4.567),
+                },
+                {
+                    "dps": POWER3_DP,
+                    "name": "sensor_power_c",
+                    "unit": POWER_WATT,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "device_class": SensorDeviceClass.POWER,
+                },
+                {
+                    "dps": PFACTOR3_DP,
+                    "name": "sensor_power_factor_c",
+                    "device_class": SensorDeviceClass.POWER_FACTOR,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (5000, 50.00),
+                },
+                {
+                    "dps": ENERGY3_DP,
+                    "name": "sensor_energy_c",
+                    "unit": ENERGY_KILO_WATT_HOUR,
+                    "device_class": SensorDeviceClass.ENERGY,
+                    "state_class": STATE_CLASS_TOTAL_INCREASING,
+                    "testdata": (12345, 123.45),
+                },
+                {
+                    "dps": TOTALCURRENT_DP,
+                    "name": "sensor_total_current",
+                    "unit": ELECTRIC_CURRENT_AMPERE,
+                    "device_class": SensorDeviceClass.CURRENT,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (12345, 12.345),
+                },
+                {
+                    "dps": TOTALPOWER_DP,
+                    "name": "sensor_total_active_power",
+                    "unit": POWER_WATT,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "device_class": SensorDeviceClass.POWER,
+                },
+                {
+                    "dps": FREQUENCY_DP,
+                    "name": "sensor_frequency",
+                    "unit": FREQUENCY_HERTZ,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "device_class": SensorDeviceClass.FREQUENCY,
+                },
+                {
+                    "dps": TEMPERATURE_DP,
+                    "name": "sensor_temperature",
+                    "unit": TEMP_CELSIUS,
+                    "device_class": SensorDeviceClass.TEMPERATURE,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                    "testdata": (234, 23.4),
+                },
+            ]
+        )
+        self.mark_secondary(
+            [
+                "sensor_voltage_a",
+                "sensor_current_a",
+                "sensor_power_a",
+                "sensor_power_factor_a",
+                "sensor_energy_a",
+                "sensor_voltage_b",
+                "sensor_current_b",
+                "sensor_power_b",
+                "sensor_power_factor_b",
+                "sensor_energy_b",
+                "sensor_voltage_c",
+                "sensor_current_c",
+                "sensor_power_c",
+                "sensor_power_factor_c",
+                "sensor_energy_c",
+                "sensor_total_current",
+                "sensor_total_active_power",
+                "sensor_frequency",
+                "sensor_temperature",
+            ]
+        )