Add CO2 Detector (co2bj) device support to Tuya (#58093)

This commit is contained in:
Franck Nijhof 2021-10-20 14:20:24 +02:00 committed by GitHub
parent b3117ced75
commit c75346addc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 27 deletions

View file

@ -37,11 +37,30 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription):
on_value: bool | float | int | str = True
# Commonly used sensors
TAMPER_BINARY_SENSOR = TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
)
# All descriptions can be found here. Mostly the Boolean data types in the
# default status set of each category (that don't have a set instruction)
# end up being a binary sensor.
# https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq
BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
# CO2 Detector
# https://developer.tuya.com/en/docs/iot/categoryco2bj?id=Kaiuz3wes7yuy
"co2bj": (
TuyaBinarySensorEntityDescription(
key=DPCode.CO2_STATE,
device_class=DEVICE_CLASS_SAFETY,
on_value="alarm",
),
TAMPER_BINARY_SENSOR,
),
# Human Presence Sensor
# https://developer.tuya.com/en/docs/iot/categoryhps?id=Kaiuz42yhn1hs
"hps": (
@ -58,12 +77,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
key=DPCode.DOORCONTACT_STATE,
device_class=DEVICE_CLASS_DOOR,
),
TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
TAMPER_BINARY_SENSOR,
),
# Luminance Sensor
# https://developer.tuya.com/en/docs/iot/categoryldcg?id=Kaiuz3n7u69l8
@ -83,12 +97,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
device_class=DEVICE_CLASS_MOTION,
on_value="pir",
),
TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
TAMPER_BINARY_SENSOR,
),
# Water Detector
# https://developer.tuya.com/en/docs/iot/categorysj?id=Kaiuz3iub2sli
@ -98,12 +107,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
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,
),
TAMPER_BINARY_SENSOR,
),
# Emergency Button
# https://developer.tuya.com/en/docs/iot/categorysos?id=Kaiuz3oi6agjy
@ -112,12 +116,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
key=DPCode.SOS_STATE,
device_class=DEVICE_CLASS_SAFETY,
),
TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
TAMPER_BINARY_SENSOR,
),
# Vibration Sensor
# https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno

View file

@ -136,6 +136,7 @@ class DPCode(str, Enum):
BRIGHT_VALUE_V2 = "bright_value_v2"
C_F = "c_f" # Temperature unit switching
CHILD_LOCK = "child_lock" # Child lock
CO2_STATE = "co2_state"
CO2_VALUE = "co2_value" # CO2 concentration
COLOR_DATA_V2 = "color_data_v2"
COLOUR_DATA = "colour_data" # Colored light mode

View file

@ -62,9 +62,29 @@ BATTERY_SENSORS: tuple[SensorEntityDescription, ...] = (
# end up being a sensor.
# https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq
SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
# Door Window Sensor
# https://developer.tuya.com/en/docs/iot/s?id=K9gf48hm02l8m
"mcs": BATTERY_SENSORS,
# CO2 Detector
# https://developer.tuya.com/en/docs/iot/categoryco2bj?id=Kaiuz3wes7yuy
"co2bj": (
SensorEntityDescription(
key=DPCode.HUMIDITY_VALUE,
name="Humidity",
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=DPCode.TEMP_CURRENT,
name="Temperature",
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=DPCode.CO2_VALUE,
name="Carbon Dioxide (CO2)",
device_class=DEVICE_CLASS_CO2,
state_class=STATE_CLASS_MEASUREMENT,
),
*BATTERY_SENSORS,
),
# Switch
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
"kg": (
@ -124,6 +144,9 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
),
*BATTERY_SENSORS,
),
# Door Window Sensor
# https://developer.tuya.com/en/docs/iot/s?id=K9gf48hm02l8m
"mcs": BATTERY_SENSORS,
# PIR Detector
# https://developer.tuya.com/en/docs/iot/categorypir?id=Kaiuz3ss11b80
"pir": BATTERY_SENSORS,