|
| 1 | +"""Quirk for HOBEIAN ZG-303Z soil sensor.""" |
| 2 | + |
| 3 | +from zigpy.profiles import zha |
| 4 | +from zigpy.quirks import CustomDevice |
| 5 | +from zigpy.zcl.clusters.general import Basic, Identify, PowerConfiguration |
| 6 | +from zigpy.zcl.clusters.measurement import RelativeHumidity, SoilMoisture, TemperatureMeasurement |
| 7 | + |
| 8 | +from zhaquirks.const import ( |
| 9 | + DEVICE_TYPE, |
| 10 | + ENDPOINTS, |
| 11 | + INPUT_CLUSTERS, |
| 12 | + MODELS_INFO, |
| 13 | + OUTPUT_CLUSTERS, |
| 14 | + PROFILE_ID, |
| 15 | +) |
| 16 | +from zhaquirks.tuya import TuyaLocalCluster |
| 17 | +from zhaquirks.tuya.mcu import DPToAttributeMapping, TuyaMCUCluster |
| 18 | + |
| 19 | +class HobeianRelativeHumidity(RelativeHumidity, TuyaLocalCluster): |
| 20 | + """Tuya local RelativeHumidity cluster.""" |
| 21 | + |
| 22 | +class HobeianSoilMoisture(SoilMoisture, TuyaLocalCluster): |
| 23 | + """Tuya local SoilMoisture cluster.""" |
| 24 | + |
| 25 | +class HobeianMcuCluster(TuyaMCUCluster): |
| 26 | + """Tuya Hobeian MCU cluster.""" |
| 27 | + |
| 28 | + dp_to_attribute = { |
| 29 | + 3: DPToAttributeMapping( |
| 30 | + HobeianSoilMoisture.ep_attribute, |
| 31 | + "measured_value", |
| 32 | + endpoint_id=2, |
| 33 | + converter=lambda x: x * 100, |
| 34 | + ), |
| 35 | + 5: DPToAttributeMapping( |
| 36 | + TemperatureMeasurement.ep_attribute, |
| 37 | + "measured_value", |
| 38 | + converter=lambda x: x * 10, |
| 39 | + ), |
| 40 | + 15: DPToAttributeMapping( |
| 41 | + PowerConfiguration.ep_attribute, |
| 42 | + "battery_percentage_remaining", |
| 43 | + ), |
| 44 | + 109: DPToAttributeMapping( |
| 45 | + HobeianRelativeHumidity.ep_attribute, |
| 46 | + "measured_value", |
| 47 | + endpoint_id=3, |
| 48 | + converter=lambda x: x * 100, |
| 49 | + ), |
| 50 | + } |
| 51 | + |
| 52 | + data_point_handlers = { |
| 53 | + 3: "_dp_2_attr_update", |
| 54 | + 5: "_dp_2_attr_update", |
| 55 | + 15: "_dp_2_attr_update", |
| 56 | + 109: "_dp_2_attr_update", |
| 57 | + } |
| 58 | + |
| 59 | +class HobeianZG303Z(CustomDevice): |
| 60 | + """Hobeian ZG-303Z soil sensor.""" |
| 61 | + |
| 62 | + signature = { |
| 63 | + MODELS_INFO: [ |
| 64 | + ("HOBEIAN", "ZG-303Z"), |
| 65 | + ("_TZE200_npj9bug3", "TS0601"), |
| 66 | + ], |
| 67 | + ENDPOINTS: { |
| 68 | + 1: { |
| 69 | + PROFILE_ID: zha.PROFILE_ID, |
| 70 | + DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR, |
| 71 | + INPUT_CLUSTERS: [ |
| 72 | + Basic.cluster_id, |
| 73 | + PowerConfiguration.cluster_id, |
| 74 | + Identify.cluster_id, |
| 75 | + TemperatureMeasurement.cluster_id, |
| 76 | + RelativeHumidity.cluster_id, # Original signature shows RelativeHumidity on EP 1 |
| 77 | + 0xef00, |
| 78 | + ], |
| 79 | + OUTPUT_CLUSTERS: [Identify.cluster_id], |
| 80 | + } |
| 81 | + }, |
| 82 | + } |
| 83 | + |
| 84 | + replacement = { |
| 85 | + ENDPOINTS: { |
| 86 | + 1: { |
| 87 | + PROFILE_ID: zha.PROFILE_ID, |
| 88 | + DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR, |
| 89 | + INPUT_CLUSTERS: [ |
| 90 | + Basic.cluster_id, |
| 91 | + PowerConfiguration.cluster_id, |
| 92 | + Identify.cluster_id, |
| 93 | + TemperatureMeasurement.cluster_id, |
| 94 | + HobeianMcuCluster, |
| 95 | + ], |
| 96 | + OUTPUT_CLUSTERS: [Identify.cluster_id], |
| 97 | + }, |
| 98 | + # Endpoint 2: Dedicated to Soil Moisture to prevent overwriting other values |
| 99 | + 2: { |
| 100 | + PROFILE_ID: zha.PROFILE_ID, |
| 101 | + DEVICE_TYPE: zha.DeviceType.SIMPLE_SENSOR, |
| 102 | + INPUT_CLUSTERS: [ |
| 103 | + HobeianSoilMoisture, |
| 104 | + ], |
| 105 | + OUTPUT_CLUSTERS: [], |
| 106 | + }, |
| 107 | + # Endpoint 3: Dedicated to Relative Humidity to prevent overwriting other values |
| 108 | + 3: { |
| 109 | + PROFILE_ID: zha.PROFILE_ID, |
| 110 | + DEVICE_TYPE: zha.DeviceType.SIMPLE_SENSOR, |
| 111 | + INPUT_CLUSTERS: [ |
| 112 | + HobeianRelativeHumidity, |
| 113 | + ], |
| 114 | + OUTPUT_CLUSTERS: [], |
| 115 | + }, |
| 116 | + }, |
| 117 | + } |
0 commit comments