From 1104b8a54984ab870e5185d72708bbd666a8001e Mon Sep 17 00:00:00 2001 From: exelsis423 <119899103+exelsis423@users.noreply.github.com> Date: Fri, 22 Sep 2023 08:26:20 +0200 Subject: [PATCH] Create owon pc 321 z.py --- zhaquirks/owon/owon pc 321 z.py | 135 ++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 zhaquirks/owon/owon pc 321 z.py diff --git a/zhaquirks/owon/owon pc 321 z.py b/zhaquirks/owon/owon pc 321 z.py new file mode 100644 index 0000000000..fea1605941 --- /dev/null +++ b/zhaquirks/owon/owon pc 321 z.py @@ -0,0 +1,135 @@ +""" QUIRK FOR OWON PC321 Z """ + +import logging +import zigpy.types as t + +from typing import Dict, Final +from zigpy.profiles import zha +from zigpy.quirks import CustomCluster, CustomDevice +from zigpy.zcl.foundation import ZCLAttributeDef, ZCLCommandDef + +from zigpy.zcl.clusters.general import ( + Basic, + Identify, + ) +from zigpy.zcl.clusters.smartenergy import Metering +from zhaquirks.const import ( + DEVICE_TYPE, + ENDPOINTS, + INPUT_CLUSTERS, + MODELS_INFO, + OUTPUT_CLUSTERS, + PROFILE_ID, + SKIP_CONFIGURATION, + ) + + + +_LOGGER = logging.getLogger(__name__) + + + +class Owon_PC321_Z_Simple_Metering(CustomCluster, Metering): + """ Owon PC321 CustomCluster """ + + + cluster_id = 0x0702 + ep_attribute: str = "owon_smartenergy_metering" + + attributes = Metering.attributes.copy() + attributes.update( + { + 0x2000: ("L1_phase_power", t.uint24_t, True), + 0x2001: ("L2_phase_power", t.uint24_t, True), + 0x2002: ("L3_phase_power", t.uint24_t, True), + 0x2100: ("L1_phase_reactive_power", t.uint24_t, True), + 0x2101: ("L2_phase_reactive_power", t.uint24_t, True), + 0x2102: ("L3_phase_reactive_power", t.uint24_t, True), + 0x2103: ("reactive_power_summation_of_the_3_phases", t.uint24_t, True), + 0x3000: ("L1_phase_voltage", t.uint24_t, True), + 0x3001: ("L2_phase_voltage", t.uint24_t, True), + 0x3002: ("L3_phase_voltage", t.uint24_t, True), + 0x3100: ("L1_phase_current", t.uint24_t, True), + 0x3101: ("L2_phase_current", t.uint24_t, True), + 0x3102: ("L3_phase_current", t.uint24_t, True), + 0x3103: ("current_summation_of_the_3_phases", t.uint24_t, True), + 0x3104: ("leakage_current", t.uint24_t, True), + 0x4000: ("L1_phase_energy_consumption", t.uint48_t, True), + 0x4001: ("L2_phase_energy_consumption", t.uint48_t, True), + 0x4002: ("L3_phase_energy_consumption", t.uint48_t, True), + 0x4100: ("L1_phase_reactive_energy_consumption", t.uint48_t, True), + 0x4101: ("L2_phase_reactive_energy_consumption", t.uint48_t, True), + 0x4102: ("L3_phase_reactive_energy_consumption", t.uint48_t, True), + 0x4103: ("reactive_energy_summation_of_the_3_phases", t.uint48_t, True), + } + ) + + + server_commands: dict[int, ZCLCommandDef] = { + 0x20: ZCLCommandDef("get_history_record", {}, False, is_manufacturer_specific=True), + 0x21: ZCLCommandDef("stop_sending_historical_record", {}, False, is_manufacturer_specific=True), + } + + client_commands: dict[int, ZCLCommandDef] = { + 0x20: ZCLCommandDef("sent_historical_record", {}, True, is_manufacturer_specific=True), + } + + + + + +class Owon_OC321_Z_Clear_Metering(CustomCluster): + cluster_id = 0xFFE0 + ep_attribute = "clear_metering" + + attributes: dict[int, ZCLAttributeDef] = {} + + server_commands: dict[int, ZCLCommandDef] = { + 0x00: ZCLCommandDef("clear_measurement_data", {}, is_manufacturer_specific=True), + } + client_commands: dict[int, ZCLCommandDef] = {} + + +""" New Device Owon PC321 Z """ + +class Owon_PC321_Z(CustomDevice): + + signature = { + #MODELS_INFO: [("Owon", "PC321")], + ENDPOINTS: { + # + 1: { + PROFILE_ID: zha.PROFILE_ID, + DEVICE_TYPE: zha.DeviceType.CONSUMPTION_AWARENESS_DEVICE, + INPUT_CLUSTERS: [ + Basic.cluster_id, + Identify.cluster_id, + Metering.cluster_id, + ], + OUTPUT_CLUSTERS: [Identify.cluster_id], + }, + }, + "manufacturer": "OWON Technology Inc.", + } + replacement = { + ENDPOINTS: { + # + 1: { + PROFILE_ID: zha.PROFILE_ID, + DEVICE_TYPE: zha.DeviceType.CONSUMPTION_AWARENESS_DEVICE, + INPUT_CLUSTERS: [ + Basic.cluster_id, + Identify.cluster_id, + Owon_PC321_Z_Simple_Metering, + Owon_OC321_Z_Clear_Metering, + ], + OUTPUT_CLUSTERS: [Identify.cluster_id], + }, + }, + }