From e4573273dcc91035fcb06ff4afd051c957de6963 Mon Sep 17 00:00:00 2001 From: Elad Bar <3207137+elad-bar@users.noreply.github.com> Date: Tue, 17 May 2022 18:57:19 +0300 Subject: [PATCH] Add Tuya Multi-functional Sensor (dgnbj) (#71778) Co-authored-by: Franck Nijhof --- .../components/tuya/binary_sensor.py | 73 +++++++++++++++++ homeassistant/components/tuya/number.py | 9 +++ homeassistant/components/tuya/select.py | 9 +++ homeassistant/components/tuya/sensor.py | 78 +++++++++++++++++++ homeassistant/components/tuya/siren.py | 8 ++ 5 files changed, 177 insertions(+) diff --git a/homeassistant/components/tuya/binary_sensor.py b/homeassistant/components/tuya/binary_sensor.py index 2c61151bfaf..d5e4a9b22b0 100644 --- a/homeassistant/components/tuya/binary_sensor.py +++ b/homeassistant/components/tuya/binary_sensor.py @@ -46,6 +46,79 @@ TAMPER_BINARY_SENSOR = TuyaBinarySensorEntityDescription( # end up being a binary sensor. # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = { + # Multi-functional Sensor + # https://developer.tuya.com/en/docs/iot/categorydgnbj?id=Kaiuz3yorvzg3 + "dgnbj": ( + TuyaBinarySensorEntityDescription( + key=DPCode.GAS_SENSOR_STATE, + name="Gas", + icon="mdi:gas-cylinder", + device_class=BinarySensorDeviceClass.SAFETY, + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.CH4_SENSOR_STATE, + name="Methane", + device_class=BinarySensorDeviceClass.GAS, + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.VOC_STATE, + name="Volatile Organic Compound", + device_class=BinarySensorDeviceClass.SAFETY, + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.PM25_STATE, + name="Particulate Matter 2.5 µm", + device_class=BinarySensorDeviceClass.SAFETY, + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.CO_STATE, + name="Carbon Monoxide", + icon="mdi:molecule-co", + device_class=BinarySensorDeviceClass.SAFETY, + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.CO2_STATE, + icon="mdi:molecule-co2", + name="Carbon Dioxide", + device_class=BinarySensorDeviceClass.SAFETY, + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.CH2O_STATE, + name="Formaldehyde", + device_class=BinarySensorDeviceClass.SAFETY, + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.DOORCONTACT_STATE, + name="Door", + device_class=BinarySensorDeviceClass.DOOR, + ), + TuyaBinarySensorEntityDescription( + key=DPCode.WATERSENSOR_STATE, + name="Water Leak", + device_class=BinarySensorDeviceClass.MOISTURE, + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.PRESSURE_STATE, + name="Pressure", + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.SMOKE_SENSOR_STATE, + name="Smoke", + icon="mdi:smoke-detector", + device_class=BinarySensorDeviceClass.SMOKE, + on_value="alarm", + ), + TAMPER_BINARY_SENSOR, + ), # CO2 Detector # https://developer.tuya.com/en/docs/iot/categoryco2bj?id=Kaiuz3wes7yuy "co2bj": ( diff --git a/homeassistant/components/tuya/number.py b/homeassistant/components/tuya/number.py index d9cde61a276..35efd78871f 100644 --- a/homeassistant/components/tuya/number.py +++ b/homeassistant/components/tuya/number.py @@ -18,6 +18,15 @@ from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType # default instructions set of each category end up being a number. # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = { + # Multi-functional Sensor + # https://developer.tuya.com/en/docs/iot/categorydgnbj?id=Kaiuz3yorvzg3 + "dgnbj": ( + NumberEntityDescription( + key=DPCode.ALARM_TIME, + name="Time", + entity_category=EntityCategory.CONFIG, + ), + ), # Smart Kettle # https://developer.tuya.com/en/docs/iot/fbh?id=K9gf484m21yq7 "bh": ( diff --git a/homeassistant/components/tuya/select.py b/homeassistant/components/tuya/select.py index d9103b916f4..974268c109f 100644 --- a/homeassistant/components/tuya/select.py +++ b/homeassistant/components/tuya/select.py @@ -18,6 +18,15 @@ from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, DPType, TuyaDeviceClass # default instructions set of each category end up being a select. # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = { + # Multi-functional Sensor + # https://developer.tuya.com/en/docs/iot/categorydgnbj?id=Kaiuz3yorvzg3 + "dgnbj": ( + SelectEntityDescription( + key=DPCode.ALARM_VOLUME, + name="Volume", + entity_category=EntityCategory.CONFIG, + ), + ), # Coffee maker # https://developer.tuya.com/en/docs/iot/categorykfj?id=Kaiuz2p12pc7f "kfj": ( diff --git a/homeassistant/components/tuya/sensor.py b/homeassistant/components/tuya/sensor.py index 3ee88d2d57b..acb2ffe7987 100644 --- a/homeassistant/components/tuya/sensor.py +++ b/homeassistant/components/tuya/sensor.py @@ -82,6 +82,84 @@ BATTERY_SENSORS: tuple[TuyaSensorEntityDescription, ...] = ( # end up being a sensor. # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = { + # Multi-functional Sensor + # https://developer.tuya.com/en/docs/iot/categorydgnbj?id=Kaiuz3yorvzg3 + "dgnbj": ( + TuyaSensorEntityDescription( + key=DPCode.GAS_SENSOR_VALUE, + name="Gas", + icon="mdi:gas-cylinder", + device_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.CH4_SENSOR_VALUE, + name="Methane", + state_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.VOC_VALUE, + name="Volatile Organic Compound", + device_class=SensorDeviceClass.VOLATILE_ORGANIC_COMPOUNDS, + state_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.PM25_VALUE, + name="Particulate Matter 2.5 µm", + device_class=SensorDeviceClass.PM25, + state_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.CO_VALUE, + name="Carbon Monoxide", + icon="mdi:molecule-co", + device_class=SensorDeviceClass.CO, + state_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.CO2_VALUE, + name="Carbon Dioxide", + icon="mdi:molecule-co2", + device_class=SensorDeviceClass.CO2, + state_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.CH2O_VALUE, + name="Formaldehyde", + state_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.BRIGHT_STATE, + name="Luminosity", + icon="mdi:brightness-6", + ), + TuyaSensorEntityDescription( + key=DPCode.BRIGHT_VALUE, + name="Luminosity", + icon="mdi:brightness-6", + device_class=SensorDeviceClass.ILLUMINANCE, + state_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.TEMP_CURRENT, + name="Temperature", + device_class=SensorDeviceClass.TEMPERATURE, + state_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.HUMIDITY_VALUE, + name="Humidity", + device_class=SensorDeviceClass.HUMIDITY, + state_class=SensorStateClass.MEASUREMENT, + ), + TuyaSensorEntityDescription( + key=DPCode.SMOKE_SENSOR_VALUE, + name="Smoke Amount", + icon="mdi:smoke-detector", + entity_category=EntityCategory.DIAGNOSTIC, + device_class=SensorStateClass.MEASUREMENT, + ), + *BATTERY_SENSORS, + ), # Smart Kettle # https://developer.tuya.com/en/docs/iot/fbh?id=K9gf484m21yq7 "bh": ( diff --git a/homeassistant/components/tuya/siren.py b/homeassistant/components/tuya/siren.py index dcb26871bb2..a60e24eca86 100644 --- a/homeassistant/components/tuya/siren.py +++ b/homeassistant/components/tuya/siren.py @@ -22,6 +22,14 @@ from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode # All descriptions can be found here: # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq SIRENS: dict[str, tuple[SirenEntityDescription, ...]] = { + # Multi-functional Sensor + # https://developer.tuya.com/en/docs/iot/categorydgnbj?id=Kaiuz3yorvzg3 + "dgnbj": ( + SirenEntityDescription( + key=DPCode.ALARM_SWITCH, + name="Siren", + ), + ), # Siren Alarm # https://developer.tuya.com/en/docs/iot/categorysgbj?id=Kaiuz37tlpbnu "sgbj": (