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

This commit is contained in:
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_DOOR,
DEVICE_CLASS_MOTION, DEVICE_CLASS_MOTION,
DEVICE_CLASS_SAFETY, DEVICE_CLASS_SAFETY,
DEVICE_CLASS_TAMPER,
DEVICE_CLASS_VIBRATION, DEVICE_CLASS_VIBRATION,
BinarySensorEntity, BinarySensorEntity,
BinarySensorEntityDescription, BinarySensorEntityDescription,
@ -50,6 +51,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
TuyaBinarySensorEntityDescription( TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM, key=DPCode.TEMPER_ALARM,
name="Tamper", name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
), ),
@ -59,6 +61,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
TuyaBinarySensorEntityDescription( TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM, key=DPCode.TEMPER_ALARM,
name="Tamper", name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
), ),
@ -73,6 +76,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
TuyaBinarySensorEntityDescription( TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM, key=DPCode.TEMPER_ALARM,
name="Tamper", name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
), ),
@ -86,6 +90,7 @@ BINARY_SENSORS: dict[str, tuple[TuyaBinarySensorEntityDescription, ...]] = {
TuyaBinarySensorEntityDescription( TuyaBinarySensorEntityDescription(
key=DPCode.TEMPER_ALARM, key=DPCode.TEMPER_ALARM,
name="Tamper", name="Tamper",
device_class=DEVICE_CLASS_TAMPER,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
), ),
), ),

View file

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

View file

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

View file

@ -39,6 +39,24 @@ from .const import (
UnitOfMeasurement, 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 # 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) # default status set of each category (that don't have a set instruction)
# end up being a sensor. # end up being a sensor.
@ -46,22 +64,7 @@ from .const import (
SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = { SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
# Door Window Sensor # Door Window Sensor
# https://developer.tuya.com/en/docs/iot/s?id=K9gf48hm02l8m # https://developer.tuya.com/en/docs/iot/s?id=K9gf48hm02l8m
"mcs": ( "mcs": BATTERY_SENSORS,
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,
),
),
# Switch # Switch
# https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s # https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
"kg": ( "kg": (
@ -119,74 +122,17 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
device_class=DEVICE_CLASS_CO2, device_class=DEVICE_CLASS_CO2,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( *BATTERY_SENSORS,
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 Detector # PIR Detector
# https://developer.tuya.com/en/docs/iot/categorypir?id=Kaiuz3ss11b80 # https://developer.tuya.com/en/docs/iot/categorypir?id=Kaiuz3ss11b80
"pir": ( "pir": BATTERY_SENSORS,
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,
),
),
# Vibration Sensor # Vibration Sensor
# https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno # https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno
"zd": ( "zd": BATTERY_SENSORS,
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,
),
),
# Emergency Button # Emergency Button
# https://developer.tuya.com/en/docs/iot/categorysos?id=Kaiuz3oi6agjy # https://developer.tuya.com/en/docs/iot/categorysos?id=Kaiuz3oi6agjy
"sos": ( "sos": BATTERY_SENSORS,
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,
),
),
} }
# Socket (duplicate of `kg`) # Socket (duplicate of `kg`)

View file

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