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

@ -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`)