Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions zhaquirks/tuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,15 @@ def handle_get_data(self, command: TuyaCommand) -> foundation.Status:
dp_error = True
# return foundation.Status.UNSUPPORTED_ATTRIBUTE

_LOGGER.debug(
"[0x%04x:%s:0x%04x] Received value %s " "for attribute 0x%04x",
self.endpoint.device.nwk,
self.endpoint.endpoint_id,
self.cluster_id,
record.data.payload,
record.dp,
)

return (
foundation.Status.SUCCESS
if not dp_error
Expand Down
201 changes: 200 additions & 1 deletion zhaquirks/tuya/ts0601_din_power.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Tuya Din Power Meter."""

from zigpy.profiles import zha
from zigpy.quirks.v2 import SensorDeviceClass, SensorStateClass
from zigpy.quirks.v2.homeassistant import PERCENTAGE, UnitOfEnergy
import zigpy.types as t
from zigpy.zcl.clusters.general import Basic, Groups, Ota, Scenes, Time
from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement
Expand All @@ -15,7 +17,13 @@
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.tuya import TuyaManufClusterAttributes, TuyaOnOff, TuyaSwitch
from zhaquirks.tuya import (
TuyaLocalCluster,
TuyaManufClusterAttributes,
TuyaOnOff,
TuyaSwitch,
)
from zhaquirks.tuya.builder import TuyaQuirkBuilder

TUYA_TOTAL_ENERGY_ATTR = 0x0211
TUYA_CURRENT_ATTR = 0x0212
Expand Down Expand Up @@ -233,6 +241,197 @@ def __init__(self, *args, **kwargs):
}


class Tuya3PhaseElectricalMeasurement(ElectricalMeasurement, TuyaLocalCluster):
"""Tuya Electrical Measurement cluster."""

_CONSTANT_ATTRIBUTES = {
ElectricalMeasurement.AttributeDefs.ac_current_divisor.id: 1000,
ElectricalMeasurement.AttributeDefs.ac_voltage_divisor.id: 10,
ElectricalMeasurement.AttributeDefs.ac_frequency_divisor.id: 100,
}


(
TuyaQuirkBuilder("_TZE204_ugekduaj", "TS0601")
.tuya_dp(
dp_id=101,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="ac_frequency",
)
# Energy consumed
.tuya_sensor(
dp_id=1,
attribute_name="energy_consumed",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
fallback_name="Total energy",
)
.tuya_sensor(
dp_id=112,
attribute_name="energy_consumed_ph_a",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_ph_a",
fallback_name="Energy phase A",
)
.tuya_sensor(
dp_id=114,
attribute_name="energy_consumed_ph_b",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_ph_b",
fallback_name="Energy phase B",
)
.tuya_sensor(
dp_id=116,
attribute_name="energy_consumed_ph_c",
divisor=100,
type=t.uint32_t,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_ph_c",
fallback_name="Energy phase C",
)
# Energy produced
.tuya_sensor(
dp_id=2,
attribute_name="energy_produced",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_produced",
fallback_name="Energy produced",
)
.tuya_sensor(
dp_id=113,
attribute_name="energy_produced_ph_a",
type=t.uint32_t,
converter=lambda x: x / 100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_produced_ph_a",
fallback_name="Energy produced phase A",
)
.tuya_sensor(
dp_id=115,
attribute_name="energy_produced_ph_b",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_produced_ph_b",
fallback_name="Energy produced phase B",
)
.tuya_sensor(
dp_id=117,
attribute_name="energy_produced_ph_c",
type=t.uint32_t,
divisor=100,
state_class=SensorStateClass.TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
unit=UnitOfEnergy.KILO_WATT_HOUR,
translation_key="energy_produced_ph_c",
fallback_name="Energy produced phase C",
)
# Power
.tuya_dp(
dp_id=111,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="total_active_power",
)
.tuya_dp(
dp_id=104,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="active_power",
)
.tuya_dp(
dp_id=107,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="active_power_ph_b",
)
.tuya_dp(
dp_id=110,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="active_power_ph_c",
)
# Voltage
.tuya_dp(
dp_id=102,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_voltage",
)
.tuya_dp(
dp_id=105,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_voltage_ph_b",
)
.tuya_dp(
dp_id=108,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_voltage_ph_c",
)
# Current
.tuya_dp(
dp_id=103,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_current",
)
.tuya_dp(
dp_id=106,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_current_ph_b",
)
.tuya_dp(
dp_id=109,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="rms_current_ph_c",
)
# Power factor
.tuya_sensor(
dp_id=15,
attribute_name="power_factor",
type=t.uint8_t,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER_FACTOR,
unit=PERCENTAGE,
translation_key="total_power_factor",
fallback_name="Total power factor",
)
.tuya_dp(
dp_id=118,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="power_factor",
)
.tuya_dp(
dp_id=119,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="power_factor_ph_b",
)
.tuya_dp(
dp_id=120,
ep_attribute=Tuya3PhaseElectricalMeasurement.ep_attribute,
attribute_name="power_factor_ph_c",
)
.adds(Tuya3PhaseElectricalMeasurement)
.skip_configuration()
.add_to_registry()
)


class HikingPowerMeter(TuyaSwitch):
"""Hiking Power Meter Device - DDS238-2."""

Expand Down
Loading