From c204196a7ad1860897e2ecfb189f7bd1d6a9e219 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 20 Oct 2021 20:49:10 +0200 Subject: [PATCH] Add Formaldehyde Detector (jqbj) device support to Tuya (#58118) --- .../components/tuya/binary_sensor.py | 10 ++++ homeassistant/components/tuya/const.py | 6 +++ homeassistant/components/tuya/sensor.py | 46 ++++++++++++++++++- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/tuya/binary_sensor.py b/homeassistant/components/tuya/binary_sensor.py index 934f1fda7ef..8adf930641c 100644 --- a/homeassistant/components/tuya/binary_sensor.py +++ b/homeassistant/components/tuya/binary_sensor.py @@ -70,6 +70,16 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = { on_value="presence", ), ), + # Formaldehyde Detector + # Note: Not documented + "jqbj": ( + TuyaBinarySensorEntityDescription( + key=DPCode.CH2O_STATE, + device_class=DEVICE_CLASS_SAFETY, + on_value="alarm", + ), + TAMPER_BINARY_SENSOR, + ), # Door Window Sensor # https://developer.tuya.com/en/docs/iot/s?id=K9gf48hm02l8m "mcs": ( diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index 7825c919a31..e445116d39c 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -138,6 +138,8 @@ class DPCode(str, Enum): BRIGHT_VALUE_2 = "bright_value_2" BRIGHT_VALUE_V2 = "bright_value_v2" C_F = "c_f" # Temperature unit switching + CH2O_STATE = "ch2o_state" + CH2O_VALUE = "ch2o_value" CHILD_LOCK = "child_lock" # Child lock CO2_STATE = "co2_state" CO2_VALUE = "co2_value" # CO2 concentration @@ -182,6 +184,7 @@ class DPCode(str, Enum): PERCENT_STATE_2 = "percent_state_2" PERCENT_STATE_3 = "percent_state_3" PIR = "pir" # Motion sensor + PM25_VALUE = "pm25_value" POWDER_SET = "powder_set" # Powder POWER_GO = "power_go" PRESENCE_STATE = "presence_state" @@ -234,6 +237,9 @@ class DPCode(str, Enum): TEMP_VALUE_V2 = "temp_value_v2" TEMPER_ALARM = "temper_alarm" # Tamper alarm UV = "uv" # UV sterilization + VA_HUMIDITY = "va_humidity" + VA_TEMPERATURE = "va_temperature" + VOC_VALUE = "voc_value" WARM = "warm" # Heat preservation WARM_TIME = "warm_time" # Heat preservation time WATER_RESET = "water_reset" # Resetting of water usage days diff --git a/homeassistant/components/tuya/sensor.py b/homeassistant/components/tuya/sensor.py index 469d2a2e83c..c1407652d92 100644 --- a/homeassistant/components/tuya/sensor.py +++ b/homeassistant/components/tuya/sensor.py @@ -18,8 +18,10 @@ from homeassistant.const import ( DEVICE_CLASS_CURRENT, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, + DEVICE_CLASS_PM25, DEVICE_CLASS_POWER, DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, DEVICE_CLASS_VOLTAGE, ENTITY_CATEGORY_DIAGNOSTIC, PERCENTAGE, @@ -79,7 +81,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { ), SensorEntityDescription( key=DPCode.CO2_VALUE, - name="Carbon Dioxide (CO2)", + name="Carbon Dioxide", device_class=DEVICE_CLASS_CO2, state_class=STATE_CLASS_MEASUREMENT, ), @@ -110,6 +112,46 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { entity_registry_enabled_default=False, ), ), + # Formaldehyde Detector + # Note: Not documented + "jqbj": ( + SensorEntityDescription( + key=DPCode.CO2_VALUE, + name="Carbon Dioxide", + device_class=DEVICE_CLASS_CO2, + state_class=STATE_CLASS_MEASUREMENT, + ), + SensorEntityDescription( + key=DPCode.VOC_VALUE, + name="Volatile Organic Compound", + device_class=DEVICE_CLASS_VOLATILE_ORGANIC_COMPOUNDS, + state_class=STATE_CLASS_MEASUREMENT, + ), + SensorEntityDescription( + key=DPCode.PM25_VALUE, + name="Particulate Matter 2.5 µm", + device_class=DEVICE_CLASS_PM25, + state_class=STATE_CLASS_MEASUREMENT, + ), + SensorEntityDescription( + key=DPCode.VA_HUMIDITY, + name="Humidity", + device_class=DEVICE_CLASS_HUMIDITY, + state_class=STATE_CLASS_MEASUREMENT, + ), + SensorEntityDescription( + key=DPCode.VA_TEMPERATURE, + name="Temperature", + device_class=DEVICE_CLASS_TEMPERATURE, + state_class=STATE_CLASS_MEASUREMENT, + ), + SensorEntityDescription( + key=DPCode.CH2O_VALUE, + name="Formaldehyde", + state_class=STATE_CLASS_MEASUREMENT, + ), + *BATTERY_SENSORS, + ), # Luminance Sensor # https://developer.tuya.com/en/docs/iot/categoryldcg?id=Kaiuz3n7u69l8 "ldcg": ( @@ -138,7 +180,7 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { ), SensorEntityDescription( key=DPCode.CO2_VALUE, - name="Carbon Dioxide (CO2)", + name="Carbon Dioxide", device_class=DEVICE_CLASS_CO2, state_class=STATE_CLASS_MEASUREMENT, ),