Tuya tweaks to entity category, registry enabled, icons & device classes (#57949)

pull/57954/head
Franck Nijhof 2021-10-18 09:24:59 +02:00 committed by GitHub
parent 81efdb2df2
commit 55c80b4093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 85 deletions

View File

@ -9,6 +9,7 @@ from homeassistant.components.binary_sensor import (
DEVICE_CLASS_DOOR,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_SAFETY,
DEVICE_CLASS_TAMPER,
DEVICE_CLASS_VIBRATION,
BinarySensorEntity,
BinarySensorEntityDescription,
@ -50,6 +51,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
),
@ -59,6 +61,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
),
@ -73,6 +76,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
),
@ -86,6 +90,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM,
name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
),

View File

@ -28,24 +28,24 @@ NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = {
key=DPCode.WATER_SET,
name="Water Level",
icon="mdi:cup-water",
entity_registry_enabled_default=False,
entity_category=ENTITY_CATEGORY_CONFIG,
),
NumberEntityDescription(
key=DPCode.TEMP_SET,
name="Temperature",
icon="mdi:thermometer",
entity_registry_enabled_default=False,
entity_category=ENTITY_CATEGORY_CONFIG,
),
NumberEntityDescription(
key=DPCode.WARM_TIME,
name="Heat Preservation Time",
icon="mdi:timer",
entity_registry_enabled_default=False,
entity_category=ENTITY_CATEGORY_CONFIG,
),
NumberEntityDescription(
key=DPCode.POWDER_SET,
name="Powder",
entity_registry_enabled_default=False,
entity_category=ENTITY_CATEGORY_CONFIG,
),
),
# Siren Alarm

View File

@ -33,14 +33,17 @@ SELECTS: dict[str, tuple[SelectEntityDescription, ...]] = {
key=DPCode.CONCENTRATION_SET,
name="Concentration",
icon="mdi:altimeter",
entity_category=ENTITY_CATEGORY_CONFIG,
),
SelectEntityDescription(
key=DPCode.MATERIAL,
name="Material",
entity_category=ENTITY_CATEGORY_CONFIG,
),
SelectEntityDescription(
key=DPCode.MODE,
name="Mode",
icon="mdi:coffee",
),
),
# Siren Alarm

View File

@ -39,6 +39,24 @@ from .const import (
UnitOfMeasurement,
)
# Commonly used battery sensors, that are re-used in the sensors down below.
BATTERY_SENSORS: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key=DPCode.BATTERY_PERCENTAGE,
name="Battery",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
SensorEntityDescription(
key=DPCode.BATTERY_STATE,
name="Battery State",
icon="mdi:battery",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
)
# All descriptions can be found here. Mostly the Integer data types in the
# default status set of each category (that don't have a set instruction)
# end up being a sensor.
@ -46,22 +64,7 @@ from .const import (
SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
# Door Window Sensor
# https://developer.tuya.com/en/docs/iot/s?id=K9gf48hm02l8m
"mcs": (
SensorEntityDescription(
key=DPCode.BATTERY_PERCENTAGE,
name="Battery",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
SensorEntityDescription(
key=DPCode.BATTERY_STATE,
name="Battery State",
icon="mdi:battery",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
),
"mcs": BATTERY_SENSORS,
# Switch
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
"kg": (
@ -119,74 +122,17 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
device_class=DEVICE_CLASS_CO2,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=DPCode.BATTERY_PERCENTAGE,
name="Battery",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
SensorEntityDescription(
key=DPCode.BATTERY_STATE,
name="Battery State",
icon="mdi:battery",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
*BATTERY_SENSORS,
),
# PIR Detector
# https://developer.tuya.com/en/docs/iot/categorypir?id=Kaiuz3ss11b80
"pir": (
SensorEntityDescription(
key=DPCode.BATTERY_PERCENTAGE,
name="Battery",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
SensorEntityDescription(
key=DPCode.BATTERY_STATE,
name="Battery State",
icon="mdi:battery",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
),
"pir": BATTERY_SENSORS,
# Vibration Sensor
# https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno
"zd": (
SensorEntityDescription(
key=DPCode.BATTERY_PERCENTAGE,
name="Battery",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
SensorEntityDescription(
key=DPCode.BATTERY_STATE,
name="Battery State",
icon="mdi:battery",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
),
"zd": BATTERY_SENSORS,
# Emergency Button
# https://developer.tuya.com/en/docs/iot/categorysos?id=Kaiuz3oi6agjy
"sos": (
SensorEntityDescription(
key=DPCode.BATTERY_PERCENTAGE,
name="Battery",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
SensorEntityDescription(
key=DPCode.BATTERY_STATE,
name="Battery State",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
),
"sos": BATTERY_SENSORS,
}
# Socket (duplicate of `kg`)

View File

@ -35,6 +35,7 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
SwitchEntityDescription(
key=DPCode.WARM,
name="Heat preservation",
entity_category=ENTITY_CATEGORY_CONFIG,
),
),
# Pet Water Feeder
@ -44,11 +45,13 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
key=DPCode.FILTER_RESET,
name="Filter reset",
icon="mdi:filter",
entity_category=ENTITY_CATEGORY_CONFIG,
),
SwitchEntityDescription(
key=DPCode.PUMP_RESET,
name="Water pump reset",
icon="mdi:pump",
entity_category=ENTITY_CATEGORY_CONFIG,
),
SwitchEntityDescription(
key=DPCode.SWITCH,
@ -58,7 +61,7 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
key=DPCode.WATER_RESET,
name="Reset of water usage days",
icon="mdi:water-sync",
entity_registry_enabled_default=False,
entity_category=ENTITY_CATEGORY_CONFIG,
),
),
# Cirquit Breaker
@ -67,6 +70,7 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
key=DPCode.CHILD_LOCK,
name="Child Lock",
icon="mdi:account-lock",
entity_category=ENTITY_CATEGORY_CONFIG,
),
SwitchEntityDescription(
key=DPCode.SWITCH_1,
@ -80,6 +84,7 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
key=DPCode.CHILD_LOCK,
name="Child Lock",
icon="mdi:account-lock",
entity_category=ENTITY_CATEGORY_CONFIG,
),
SwitchEntityDescription(
key=DPCode.SWITCH_1,
@ -148,17 +153,19 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
key=DPCode.ANION,
name="Ionizer",
icon="mdi:minus-circle-outline",
entity_category=ENTITY_CATEGORY_CONFIG,
),
SwitchEntityDescription(
key=DPCode.FILTER_RESET,
name="Filter cartridge reset",
icon="mdi:filter",
entity_registry_enabled_default=False,
entity_category=ENTITY_CATEGORY_CONFIG,
),
SwitchEntityDescription(
key=DPCode.LOCK,
name="Child lock",
icon="mdi:account-lock",
entity_category=ENTITY_CATEGORY_CONFIG,
),
SwitchEntityDescription(
key=DPCode.SWITCH,
@ -168,6 +175,7 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
key=DPCode.WET,
name="Humidification",
icon="mdi:water-percent",
entity_category=ENTITY_CATEGORY_CONFIG,
),
),
# Power Socket
@ -177,6 +185,7 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
key=DPCode.CHILD_LOCK,
name="Child Lock",
icon="mdi:account-lock",
entity_category=ENTITY_CATEGORY_CONFIG,
),
SwitchEntityDescription(
key=DPCode.SWITCH_1,
@ -243,11 +252,12 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
"sgbj": (
SwitchEntityDescription(
key=DPCode.MUFFLING,
name="Muffling",
name="Mute",
entity_category=ENTITY_CATEGORY_CONFIG,
),
),
# Diffuser
# https://developer.tuya.com/en/docs/iot/categoryxxj?id=Kaiuz1f9mo6bl
"xxj": (
SwitchEntityDescription(
key=DPCode.SWITCH,
@ -262,7 +272,7 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
key=DPCode.SWITCH_VOICE,
name="Voice",
icon="mdi:account-voice",
entity_registry_enabled_default=False,
entity_category=ENTITY_CATEGORY_CONFIG,
),
),
}