|
| 1 | +"""Xiaomi LYWSD03MMC Bluetooth temperature and humidity sensor with custom firmware.""" |
| 2 | + |
| 3 | +from zigpy.profiles import zha |
| 4 | +from zigpy.quirks import CustomDevice |
| 5 | +from zigpy.types import Bool, int16s, uint16_t |
| 6 | +from zigpy.zcl.clusters.general import Basic, Identify, Ota, PowerConfiguration |
| 7 | +from zigpy.zcl.clusters.hvac import UserInterface |
| 8 | +from zigpy.zcl.clusters.measurement import RelativeHumidity, TemperatureMeasurement |
| 9 | +from zigpy.zcl.foundation import ZCLAttributeDef |
| 10 | + |
| 11 | +from zhaquirks import CustomCluster |
| 12 | +from zhaquirks.const import ( |
| 13 | + DEVICE_TYPE, |
| 14 | + ENDPOINTS, |
| 15 | + INPUT_CLUSTERS, |
| 16 | + MODELS_INFO, |
| 17 | + OUTPUT_CLUSTERS, |
| 18 | + PROFILE_ID, |
| 19 | +) |
| 20 | + |
| 21 | + |
| 22 | +class TemperatureMeasurementCustom(CustomCluster, TemperatureMeasurement): |
| 23 | + """Temperature Measurement Cluster with calibration attribute.""" |
| 24 | + |
| 25 | + class AttributeDefs(TemperatureMeasurement.AttributeDefs): |
| 26 | + """Attribute Definitions.""" |
| 27 | + |
| 28 | + # A value in 0.01ºC offset to fix up incorrect values from sensor |
| 29 | + temperature_calibration = ZCLAttributeDef( |
| 30 | + id=0x0010, |
| 31 | + type=int16s, |
| 32 | + access="rw", |
| 33 | + is_manufacturer_specific=True, |
| 34 | + ) |
| 35 | + |
| 36 | + |
| 37 | +class RelativeHumidityCustom(CustomCluster, RelativeHumidity): |
| 38 | + """Relative Humidity Cluster with calibration attribute.""" |
| 39 | + |
| 40 | + class AttributeDefs(RelativeHumidity.AttributeDefs): |
| 41 | + """Attribute Definitions.""" |
| 42 | + |
| 43 | + # A value in 0.01%RH offset to fix up incorrect values from sensor |
| 44 | + humidity_calibration = ZCLAttributeDef( |
| 45 | + id=0x0010, |
| 46 | + type=int16s, |
| 47 | + access="rw", |
| 48 | + is_manufacturer_specific=True, |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +class UserInterfaceCustom(CustomCluster, UserInterface): |
| 53 | + """Custom User Interface Cluster with smiley control.""" |
| 54 | + |
| 55 | + class AttributeDefs(UserInterface.AttributeDefs): |
| 56 | + """Attribute Definitions.""" |
| 57 | + |
| 58 | + # of the 3 ZCL Thermostat User Interface spec attributes, |
| 59 | + # only the first one (TemperatureDisplayMode) is implemented fully. |
| 60 | + # KeypadLockout is implemented but completely unused in the device firmware |
| 61 | + # and ScheduleProgrammingVisibility is not implemented at all |
| 62 | + # https://github.com/devbis/z03mmc/blob/1.1.0/src/sensorEpCfg.c#L256 |
| 63 | + |
| 64 | + # 0 - smiley is off, 1 - smiley is on (according to comfort values) |
| 65 | + smiley = ZCLAttributeDef( |
| 66 | + id=0x0010, |
| 67 | + type=Bool, |
| 68 | + access="rw", |
| 69 | + is_manufacturer_specific=True, |
| 70 | + ) |
| 71 | + |
| 72 | + # display. 0 - display is off, 1 - display is on |
| 73 | + display = ZCLAttributeDef( |
| 74 | + id=0x0011, |
| 75 | + type=Bool, |
| 76 | + access="rw", |
| 77 | + is_manufacturer_specific=True, |
| 78 | + ) |
| 79 | + |
| 80 | + # comfort temperature min: A value in 0.01ºC to set minimum comfort temperature for happy face |
| 81 | + comfort_temperature_min = ZCLAttributeDef( |
| 82 | + id=0x0102, |
| 83 | + type=int16s, |
| 84 | + access="rw", |
| 85 | + is_manufacturer_specific=True, |
| 86 | + ) |
| 87 | + |
| 88 | + # comfort temperature max: A value in 0.01ºC to set maximum comfort temperature for happy face |
| 89 | + comfort_temperature_max = ZCLAttributeDef( |
| 90 | + id=0x0103, |
| 91 | + type=int16s, |
| 92 | + access="rw", |
| 93 | + is_manufacturer_specific=True, |
| 94 | + ) |
| 95 | + |
| 96 | + # comfort humidity min: A value in 0.01%RH to set minimum comfort humidity for happy face |
| 97 | + comfort_humidity_min = ZCLAttributeDef( |
| 98 | + id=0x0104, |
| 99 | + type=uint16_t, |
| 100 | + access="rw", |
| 101 | + is_manufacturer_specific=True, |
| 102 | + ) |
| 103 | + |
| 104 | + # comfort humidity max: A value in 0.01%RH to set maximum comfort humidity for happy face |
| 105 | + comfort_humidity_max = ZCLAttributeDef( |
| 106 | + id=0x0105, |
| 107 | + type=uint16_t, |
| 108 | + access="rw", |
| 109 | + is_manufacturer_specific=True, |
| 110 | + ) |
| 111 | + |
| 112 | + |
| 113 | +# https://github.com/devbis/z03mmc |
| 114 | +# defined by 1.1.0 firmware (0x11003001) |
| 115 | +# see README.md in the repo for more info |
| 116 | +class DevbisLYWSD03MMC(CustomDevice): |
| 117 | + """LYWSD03MMC sensor with devbis custom firmware.""" |
| 118 | + |
| 119 | + signature = { |
| 120 | + MODELS_INFO: [("Xiaomi", "LYWSD03MMC")], |
| 121 | + ENDPOINTS: { |
| 122 | + 1: { |
| 123 | + PROFILE_ID: zha.PROFILE_ID, |
| 124 | + DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR, |
| 125 | + INPUT_CLUSTERS: [ |
| 126 | + Basic.cluster_id, |
| 127 | + Identify.cluster_id, |
| 128 | + PowerConfiguration.cluster_id, |
| 129 | + RelativeHumidity.cluster_id, |
| 130 | + TemperatureMeasurement.cluster_id, |
| 131 | + UserInterface.cluster_id, |
| 132 | + ], |
| 133 | + OUTPUT_CLUSTERS: [Ota.cluster_id], |
| 134 | + }, |
| 135 | + }, |
| 136 | + } |
| 137 | + replacement = { |
| 138 | + ENDPOINTS: { |
| 139 | + 1: { |
| 140 | + PROFILE_ID: zha.PROFILE_ID, |
| 141 | + DEVICE_TYPE: zha.DeviceType.TEMPERATURE_SENSOR, |
| 142 | + INPUT_CLUSTERS: [ |
| 143 | + Basic.cluster_id, |
| 144 | + Identify.cluster_id, |
| 145 | + PowerConfiguration.cluster_id, |
| 146 | + RelativeHumidityCustom, |
| 147 | + TemperatureMeasurementCustom, |
| 148 | + UserInterfaceCustom, |
| 149 | + ], |
| 150 | + OUTPUT_CLUSTERS: [Ota.cluster_id], |
| 151 | + }, |
| 152 | + }, |
| 153 | + } |
0 commit comments