From 6d898a631ccafe700dd86145ff25e99dd5bbb66b Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 19 Oct 2021 20:09:06 +0200 Subject: [PATCH] Add Water Detector (sj) device support to Tuya (#58049) --- homeassistant/components/tuya/binary_sensor.py | 16 ++++++++++++++++ homeassistant/components/tuya/const.py | 1 + homeassistant/components/tuya/sensor.py | 9 ++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tuya/binary_sensor.py b/homeassistant/components/tuya/binary_sensor.py index a083cfd73f5..22db498a1c4 100644 --- a/homeassistant/components/tuya/binary_sensor.py +++ b/homeassistant/components/tuya/binary_sensor.py @@ -7,6 +7,7 @@ from tuya_iot import TuyaDevice, TuyaDeviceManager from homeassistant.components.binary_sensor import ( DEVICE_CLASS_DOOR, + DEVICE_CLASS_MOISTURE, DEVICE_CLASS_MOTION, DEVICE_CLASS_SAFETY, DEVICE_CLASS_TAMPER, @@ -80,6 +81,21 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = { entity_category=ENTITY_CATEGORY_DIAGNOSTIC, ), ), + # Water Detector + # https://developer.tuya.com/en/docs/iot/categorysj?id=Kaiuz3iub2sli + "sj": ( + TuyaBinarySensorEntityDescription( + key=DPCode.WATERSENSOR_STATE, + device_class=DEVICE_CLASS_MOISTURE, + on_value="alarm", + ), + TuyaBinarySensorEntityDescription( + key=DPCode.TEMPER_ALARM, + name="Tamper", + device_class=DEVICE_CLASS_TAMPER, + entity_category=ENTITY_CATEGORY_DIAGNOSTIC, + ), + ), # Emergency Button # https://developer.tuya.com/en/docs/iot/categorysos?id=Kaiuz3oi6agjy "sos": ( diff --git a/homeassistant/components/tuya/const.py b/homeassistant/components/tuya/const.py index 233edeac445..6c6f84214d7 100644 --- a/homeassistant/components/tuya/const.py +++ b/homeassistant/components/tuya/const.py @@ -227,6 +227,7 @@ class DPCode(str, Enum): WARM_TIME = "warm_time" # Heat preservation time WATER_RESET = "water_reset" # Resetting of water usage days WATER_SET = "water_set" # Water level + WATERSENSOR_STATE = "watersensor_state" WET = "wet" # Humidification WORK_MODE = "work_mode" # Working mode diff --git a/homeassistant/components/tuya/sensor.py b/homeassistant/components/tuya/sensor.py index fc12b9b9ace..739ababfadd 100644 --- a/homeassistant/components/tuya/sensor.py +++ b/homeassistant/components/tuya/sensor.py @@ -127,12 +127,15 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { # PIR Detector # https://developer.tuya.com/en/docs/iot/categorypir?id=Kaiuz3ss11b80 "pir": BATTERY_SENSORS, - # Vibration Sensor - # https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno - "zd": BATTERY_SENSORS, + # Water Detector + # https://developer.tuya.com/en/docs/iot/categorysj?id=Kaiuz3iub2sli + "sj": BATTERY_SENSORS, # Emergency Button # https://developer.tuya.com/en/docs/iot/categorysos?id=Kaiuz3oi6agjy "sos": BATTERY_SENSORS, + # Vibration Sensor + # https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno + "zd": BATTERY_SENSORS, } # Socket (duplicate of `kg`)