Use state/device/entity category enums in Tuya (#60788)

This commit is contained in:
Franck Nijhof 2021-12-02 03:19:24 +01:00 committed by GitHub
parent c875d726b1
commit 563b488739
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 332 additions and 383 deletions

View file

@ -6,21 +6,14 @@ from dataclasses import dataclass
from tuya_iot import TuyaDevice, TuyaDeviceManager
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_DOOR,
DEVICE_CLASS_GAS,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_SAFETY,
DEVICE_CLASS_SMOKE,
DEVICE_CLASS_TAMPER,
DEVICE_CLASS_VIBRATION,
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import HomeAssistantTuyaData
@ -43,8 +36,8 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription):
TAMPER_BINARY_SENSOR = TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
device_class=BinarySensorDeviceClass.TAMPER,
entity_category=EntityCategory.DIAGNOSTIC,
)
@ -58,7 +51,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"co2bj": (
TuyaBinarySensorEntityDescription(
key=DPCode.CO2_STATE,
device_class=DEVICE_CLASS_SAFETY,
device_class=BinarySensorDeviceClass.SAFETY,
on_value="alarm",
),
TAMPER_BINARY_SENSOR,
@ -68,12 +61,12 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"cobj": (
TuyaBinarySensorEntityDescription(
key=DPCode.CO_STATE,
device_class=DEVICE_CLASS_SAFETY,
device_class=BinarySensorDeviceClass.SAFETY,
on_value="1",
),
TuyaBinarySensorEntityDescription(
key=DPCode.CO_STATUS,
device_class=DEVICE_CLASS_SAFETY,
device_class=BinarySensorDeviceClass.SAFETY,
on_value="alarm",
),
TAMPER_BINARY_SENSOR,
@ -83,7 +76,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"hps": (
TuyaBinarySensorEntityDescription(
key=DPCode.PRESENCE_STATE,
device_class=DEVICE_CLASS_MOTION,
device_class=BinarySensorDeviceClass.MOTION,
on_value="presence",
),
),
@ -92,7 +85,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"jqbj": (
TuyaBinarySensorEntityDescription(
key=DPCode.CH2O_STATE,
device_class=DEVICE_CLASS_SAFETY,
device_class=BinarySensorDeviceClass.SAFETY,
on_value="alarm",
),
TAMPER_BINARY_SENSOR,
@ -102,7 +95,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"jwbj": (
TuyaBinarySensorEntityDescription(
key=DPCode.CH4_SENSOR_STATE,
device_class=DEVICE_CLASS_GAS,
device_class=BinarySensorDeviceClass.GAS,
on_value="alarm",
),
TAMPER_BINARY_SENSOR,
@ -112,7 +105,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"mcs": (
TuyaBinarySensorEntityDescription(
key=DPCode.DOORCONTACT_STATE,
device_class=DEVICE_CLASS_DOOR,
device_class=BinarySensorDeviceClass.DOOR,
),
TAMPER_BINARY_SENSOR,
),
@ -122,8 +115,8 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
device_class=BinarySensorDeviceClass.TAMPER,
entity_category=EntityCategory.DIAGNOSTIC,
),
TAMPER_BINARY_SENSOR,
),
@ -132,7 +125,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"pir": (
TuyaBinarySensorEntityDescription(
key=DPCode.PIR,
device_class=DEVICE_CLASS_MOTION,
device_class=BinarySensorDeviceClass.MOTION,
on_value="pir",
),
TAMPER_BINARY_SENSOR,
@ -142,7 +135,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"pm2.5": (
TuyaBinarySensorEntityDescription(
key=DPCode.PM25_STATE,
device_class=DEVICE_CLASS_SAFETY,
device_class=BinarySensorDeviceClass.SAFETY,
on_value="alarm",
),
TAMPER_BINARY_SENSOR,
@ -152,12 +145,12 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"rqbj": (
TuyaBinarySensorEntityDescription(
key=DPCode.GAS_SENSOR_STATUS,
device_class=DEVICE_CLASS_GAS,
device_class=BinarySensorDeviceClass.GAS,
on_value="alarm",
),
TuyaBinarySensorEntityDescription(
key=DPCode.GAS_SENSOR_STATE,
device_class=DEVICE_CLASS_GAS,
device_class=BinarySensorDeviceClass.GAS,
on_value="1",
),
TAMPER_BINARY_SENSOR,
@ -167,7 +160,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"sj": (
TuyaBinarySensorEntityDescription(
key=DPCode.WATERSENSOR_STATE,
device_class=DEVICE_CLASS_MOISTURE,
device_class=BinarySensorDeviceClass.MOISTURE,
on_value="alarm",
),
TAMPER_BINARY_SENSOR,
@ -177,7 +170,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"sos": (
TuyaBinarySensorEntityDescription(
key=DPCode.SOS_STATE,
device_class=DEVICE_CLASS_SAFETY,
device_class=BinarySensorDeviceClass.SAFETY,
),
TAMPER_BINARY_SENSOR,
),
@ -186,7 +179,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"voc": (
TuyaBinarySensorEntityDescription(
key=DPCode.VOC_STATE,
device_class=DEVICE_CLASS_SAFETY,
device_class=BinarySensorDeviceClass.SAFETY,
on_value="alarm",
),
TAMPER_BINARY_SENSOR,
@ -208,12 +201,12 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
"ywbj": (
TuyaBinarySensorEntityDescription(
key=DPCode.SMOKE_SENSOR_STATUS,
device_class=DEVICE_CLASS_SMOKE,
device_class=BinarySensorDeviceClass.SMOKE,
on_value="alarm",
),
TuyaBinarySensorEntityDescription(
key=DPCode.SMOKE_SENSOR_STATE,
device_class=DEVICE_CLASS_SMOKE,
device_class=BinarySensorDeviceClass.SMOKE,
on_value="1",
),
TAMPER_BINARY_SENSOR,
@ -225,7 +218,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
key=f"{DPCode.SHOCK_STATE}_vibration",
dpcode=DPCode.SHOCK_STATE,
name="Vibration",
device_class=DEVICE_CLASS_VIBRATION,
device_class=BinarySensorDeviceClass.VIBRATION,
on_value="vibration",
),
TuyaBinarySensorEntityDescription(