Skip to content

Commit a2f4073

Browse files
authored
Use DeviceCategory in Tuya more platforms (home-assistant#152885)
1 parent 2d01a99 commit a2f4073

File tree

10 files changed

+257
-321
lines changed

10 files changed

+257
-321
lines changed

homeassistant/components/tuya/const.py

Lines changed: 143 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ class DeviceCategory(StrEnum):
103103
BGL = "bgl"
104104
"""Wall-hung boiler"""
105105
BH = "bh"
106-
"""Smart kettle"""
106+
"""Smart kettle
107+
108+
https://developer.tuya.com/en/docs/iot/fbh?id=K9gf484m21yq7
109+
"""
107110
BX = "bx"
108111
"""Refrigerator"""
109112
BXX = "bxx"
@@ -163,34 +166,58 @@ class DeviceCategory(StrEnum):
163166
https://developer.tuya.com/en/docs/iot/f?id=Kacpeobojffop
164167
"""
165168
DC = "dc"
166-
"""String lights"""
169+
"""String lights
170+
171+
# https://developer.tuya.com/en/docs/iot/dc?id=Kaof7taxmvadu
172+
"""
167173
DCL = "dcl"
168174
"""Induction cooker"""
169175
DD = "dd"
170-
"""Strip lights"""
176+
"""Strip lights
177+
178+
https://developer.tuya.com/en/docs/iot/dd?id=Kaof804aibg2l
179+
"""
171180
DGNBJ = "dgnbj"
172181
"""Multi-functional alarm
173182
174183
https://developer.tuya.com/en/docs/iot/categorydgnbj?id=Kaiuz3yorvzg3
175184
"""
176185
DJ = "dj"
177-
"""Light"""
186+
"""Light
187+
188+
https://developer.tuya.com/en/docs/iot/categorydj?id=Kaiuyzy3eheyy
189+
"""
178190
DLQ = "dlq"
179191
"""Circuit breaker"""
180192
DR = "dr"
181-
"""Electric blanket"""
193+
"""Electric blanket
194+
195+
https://developer.tuya.com/en/docs/iot/categorydr?id=Kaiuz22dyc66p
196+
"""
182197
DS = "ds"
183198
"""TV set"""
184199
FS = "fs"
185-
"""Fan"""
200+
"""Fan
201+
202+
https://developer.tuya.com/en/docs/iot/categoryfs?id=Kaiuz1xweel1c
203+
"""
186204
FSD = "fsd"
187-
"""Ceiling fan light"""
205+
"""Ceiling fan light
206+
207+
https://developer.tuya.com/en/docs/iot/fsd?id=Kaof8eiei4c2v
208+
"""
188209
FWD = "fwd"
189-
"""Ambiance light"""
210+
"""Ambiance light
211+
212+
https://developer.tuya.com/en/docs/iot/ambient-light?id=Kaiuz06amhe6g
213+
"""
190214
GGQ = "ggq"
191215
"""Irrigator"""
192216
GYD = "gyd"
193-
"""Motion sensor light"""
217+
"""Motion sensor light
218+
219+
https://developer.tuya.com/en/docs/iot/gyd?id=Kaof8a8hycfmy
220+
"""
194221
GYMS = "gyms"
195222
"""Business lock"""
196223
HOTELMS = "hotelms"
@@ -203,7 +230,10 @@ class DeviceCategory(StrEnum):
203230
JS = "js"
204231
"""Water purifier"""
205232
JSQ = "jsq"
206-
"""Humidifier"""
233+
"""Humidifier
234+
235+
https://developer.tuya.com/en/docs/iot/categoryjsq?id=Kaiuz1smr440b
236+
"""
207237
JTMSBH = "jtmsbh"
208238
"""Smart lock (keep alive)"""
209239
JTMSPRO = "jtmspro"
@@ -214,11 +244,20 @@ class DeviceCategory(StrEnum):
214244
https://developer.tuya.com/en/docs/iot/categoryjwbj?id=Kaiuz40u98lkm
215245
"""
216246
KFJ = "kfj"
217-
"""Coffee maker"""
247+
"""Coffee maker
248+
249+
https://developer.tuya.com/en/docs/iot/categorykfj?id=Kaiuz2p12pc7f
250+
"""
218251
KG = "kg"
219-
"""Switch"""
252+
"""Switch
253+
254+
https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
255+
"""
220256
KJ = "kj"
221-
"""Air purifier"""
257+
"""Air purifier
258+
259+
https://developer.tuya.com/en/docs/iot/f?id=K9gf46h2s6dzm
260+
"""
222261
KQZG = "kqzg"
223262
"""Air fryer"""
224263
KT = "kt"
@@ -270,13 +309,19 @@ class DeviceCategory(StrEnum):
270309
MSP = "msp"
271310
"""Cat toilet"""
272311
MZJ = "mzj"
273-
"""Sous vide cooker"""
312+
"""Sous vide cooker
313+
314+
https://developer.tuya.com/en/docs/iot/categorymzj?id=Kaiuz2vy130ux
315+
"""
274316
NNQ = "nnq"
275317
"""Bottle warmer"""
276318
NTQ = "ntq"
277319
"""HVAC"""
278320
PC = "pc"
279-
"""Power strip"""
321+
"""Power strip
322+
323+
https://developer.tuya.com/en/docs/iot/s?id=K9gf7o5prgf7s
324+
"""
280325
PHOTOLOCK = "photolock"
281326
"""Audio and video lock"""
282327
PIR = "pir"
@@ -292,7 +337,7 @@ class DeviceCategory(StrEnum):
292337
QN = "qn"
293338
"""Heater
294339
295-
https://developer.tuya.com/en/docs/iot/f?id=K9gf46epy4j82
340+
https://developer.tuya.com/en/docs/iot/categoryqn?id=Kaiuz18kih0sm
296341
"""
297342
RQBJ = "rqbj"
298343
"""Gas alarm
@@ -331,22 +376,34 @@ class DeviceCategory(StrEnum):
331376
SP = "sp"
332377
"""Smart camera
333378
334-
https://developer.tuya.com/en/docs/iot/categorysgbj?id=Kaiuz37tlpbnu
379+
https://developer.tuya.com/en/docs/iot/categorysp?id=Kaiuz35leyo12
335380
"""
336381
SZ = "sz"
337-
"""Smart indoor garden"""
382+
"""Smart indoor garden
383+
384+
https://developer.tuya.com/en/docs/iot/categorysz?id=Kaiuz4e6h7up0
385+
"""
338386
TGKG = "tgkg"
339-
"""Dimmer switch"""
387+
"""Dimmer switch
388+
389+
https://developer.tuya.com/en/docs/iot/categorytgkg?id=Kaiuz0ktx7m0o
390+
"""
340391
TGQ = "tgq"
341-
"""Dimmer"""
392+
"""Dimmer
393+
394+
https://developer.tuya.com/en/docs/iot/categorytgkg?id=Kaiuz0ktx7m0o
395+
"""
342396
TNQ = "tnq"
343397
"""Smart milk kettle"""
344398
TRACKER = "tracker"
345399
"""Tracker"""
346400
TS = "ts"
347401
"""Smart jump rope"""
348402
TYNDJ = "tyndj"
349-
"""Solar light"""
403+
"""Solar light
404+
405+
https://developer.tuya.com/en/docs/iot/tynd?id=Kaof8j02e1t98
406+
"""
350407
TYY = "tyy"
351408
"""Projector"""
352409
TZC1 = "tzc1"
@@ -364,7 +421,10 @@ class DeviceCategory(StrEnum):
364421
https://developer.tuya.com/en/docs/iot/categorywsdcg?id=Kaiuz3hinij34
365422
"""
366423
XDD = "xdd"
367-
"""Ceiling light"""
424+
"""Ceiling light
425+
426+
https://developer.tuya.com/en/docs/iot/ceiling-light?id=Kaiuz03xxfc4r
427+
"""
368428
XFJ = "xfj"
369429
"""Ventilation system"""
370430
XXJ = "xxj"
@@ -376,7 +436,10 @@ class DeviceCategory(StrEnum):
376436
YG = "yg"
377437
"""Bathtub"""
378438
YKQ = "ykq"
379-
"""Remote control"""
439+
"""Remote control
440+
441+
https://developer.tuya.com/en/docs/iot/ykq?id=Kaof8ljn81aov
442+
"""
380443
YLCG = "ylcg"
381444
"""Pressure sensor
382445
@@ -402,22 +465,65 @@ class DeviceCategory(StrEnum):
402465
"""Smart pill box"""
403466

404467
# Undocumented
468+
BZYD = "bzyd"
469+
"""White noise machine (undocumented)"""
470+
CWJWQ = "cwjwq"
471+
"""Smart Odor Eliminator-Pro (undocumented)
472+
473+
see https://github.com/orgs/home-assistant/discussions/79
474+
"""
405475
DGHSXJ = "dghsxj"
406476
"""Smart Camera - Low power consumption camera (undocumented)
407477
408478
see https://github.com/home-assistant/core/issues/132844
409479
"""
480+
DSD = "dsd"
481+
"""Filament Light
482+
483+
Based on data from https://github.com/home-assistant/core/issues/106703
484+
Product category mentioned in https://developer.tuya.com/en/docs/iot/oemapp-light?id=Kb77kja5woao6
485+
As at 30/12/23 not documented in https://developer.tuya.com/en/docs/iot/lighting?id=Kaiuyzxq30wmc
486+
"""
487+
FSKG = "fskg"
488+
"""Fan wall switch (undocumented)"""
410489
HXD = "hxd"
411490
"""Wake Up Light II (undocumented)"""
412491
JDCLJQR = "jdcljqr"
413492
"""Curtain Robot (undocumented)"""
414493
JQBJ = "jqbj"
415494
"""Formaldehyde Detector (undocumented)"""
495+
KS = "ks"
496+
"""Tower fan (undocumented)
497+
498+
See https://github.com/orgs/home-assistant/discussions/329
499+
"""
500+
MBD = "mbd"
501+
"""Unknown light product
502+
503+
Found as VECINO RGBW as provided by diagnostics
504+
"""
505+
QJDCZ = "qjdcz"
506+
""" Unknown product with light capabilities
507+
508+
Found in some diffusers, plugs and PIR flood lights
509+
"""
416510
QXJ = "qxj"
417511
"""Temperature and Humidity Sensor with External Probe (undocumented)
418512
419513
see https://github.com/home-assistant/core/issues/136472
420514
"""
515+
SFKZQ = "sfkzq"
516+
"""Smart Water Timer (undocumented)"""
517+
SJZ = "sjz"
518+
"""Electric desk (undocumented)"""
519+
SZJQR = "szjqr"
520+
"""Fingerbot (undocumented)"""
521+
SWTZ = "swtz"
522+
"""Cooking thermometer (undocumented)"""
523+
TDQ = "tdq"
524+
"""Dimmer (undocumented)"""
525+
TYD = "tyd"
526+
"""Outdoor flood light (undocumented)"""
421527
VOC = "voc"
422528
"""Volatile Organic Compound Sensor (undocumented)"""
423529
WG2 = "wg2" # Documented, but not in official list
@@ -427,6 +533,20 @@ class DeviceCategory(StrEnum):
427533
"""
428534
WKF = "wkf"
429535
"""Thermostatic Radiator Valve (undocumented)"""
536+
WXKG = "wxkg" # Documented, but not in official list
537+
"""Wireless Switch
538+
539+
https://developer.tuya.com/en/docs/iot/s?id=Kbeoa9fkv6brp
540+
"""
541+
XNYJCN = "xnyjcn"
542+
"""Micro Storage Inverter
543+
544+
Energy storage and solar PV inverter system with monitoring capabilities
545+
"""
546+
YWCGQ = "ywcgq"
547+
"""Tank Level Sensor (undocumented)"""
548+
ZNRB = "znrb"
549+
"""Pool HeatPump"""
430550

431551

432552
class DPCode(StrEnum):

homeassistant/components/tuya/event.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
1515

1616
from . import TuyaConfigEntry
17-
from .const import TUYA_DISCOVERY_NEW, DPCode, DPType
17+
from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode, DPType
1818
from .entity import TuyaEntity
1919

2020
# All descriptions can be found here. Mostly the Enum data types in the
2121
# default status set of each category (that don't have a set instruction)
2222
# end up being events.
23-
# https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq
24-
EVENTS: dict[str, tuple[EventEntityDescription, ...]] = {
25-
# Wireless Switch
26-
# https://developer.tuya.com/en/docs/iot/s?id=Kbeoa9fkv6brp
27-
"wxkg": (
23+
EVENTS: dict[DeviceCategory, tuple[EventEntityDescription, ...]] = {
24+
DeviceCategory.WXKG: (
2825
EventEntityDescription(
2926
key=DPCode.SWITCH_MODE1,
3027
device_class=EventDeviceClass.BUTTON,

homeassistant/components/tuya/fan.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222

2323
from . import TuyaConfigEntry
24-
from .const import TUYA_DISCOVERY_NEW, DPCode, DPType
24+
from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode, DPType
2525
from .entity import TuyaEntity
2626
from .models import EnumTypeData, IntegerTypeData
2727
from .util import get_dpcode
@@ -36,24 +36,13 @@
3636
)
3737
_SWITCH_DPCODES = (DPCode.SWITCH_FAN, DPCode.FAN_SWITCH, DPCode.SWITCH)
3838

39-
TUYA_SUPPORT_TYPE = {
40-
# Dehumidifier
41-
# https://developer.tuya.com/en/docs/iot/categorycs?id=Kaiuz1vcz4dha
42-
"cs",
43-
# Fan
44-
# https://developer.tuya.com/en/docs/iot/categoryfs?id=Kaiuz1xweel1c
45-
"fs",
46-
# Ceiling Fan Light
47-
# https://developer.tuya.com/en/docs/iot/fsd?id=Kaof8eiei4c2v
48-
"fsd",
49-
# Fan wall switch
50-
"fskg",
51-
# Air Purifier
52-
# https://developer.tuya.com/en/docs/iot/f?id=K9gf46h2s6dzm
53-
"kj",
54-
# Undocumented tower fan
55-
# https://github.com/orgs/home-assistant/discussions/329
56-
"ks",
39+
TUYA_SUPPORT_TYPE: set[DeviceCategory] = {
40+
DeviceCategory.CS,
41+
DeviceCategory.FS,
42+
DeviceCategory.FSD,
43+
DeviceCategory.FSKG,
44+
DeviceCategory.KJ,
45+
DeviceCategory.KS,
5746
}
5847

5948

homeassistant/components/tuya/humidifier.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
1919

2020
from . import TuyaConfigEntry
21-
from .const import TUYA_DISCOVERY_NEW, DPCode, DPType
21+
from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode, DPType
2222
from .entity import TuyaEntity
2323
from .models import IntegerTypeData
2424
from .util import ActionDPCodeNotFoundError, get_dpcode
@@ -49,19 +49,15 @@ def _has_a_valid_dpcode(
4949
return any(get_dpcode(device, code) for code in properties_to_check)
5050

5151

52-
HUMIDIFIERS: dict[str, TuyaHumidifierEntityDescription] = {
53-
# Dehumidifier
54-
# https://developer.tuya.com/en/docs/iot/categorycs?id=Kaiuz1vcz4dha
55-
"cs": TuyaHumidifierEntityDescription(
52+
HUMIDIFIERS: dict[DeviceCategory, TuyaHumidifierEntityDescription] = {
53+
DeviceCategory.CS: TuyaHumidifierEntityDescription(
5654
key=DPCode.SWITCH,
5755
dpcode=(DPCode.SWITCH, DPCode.SWITCH_SPRAY),
5856
current_humidity=DPCode.HUMIDITY_INDOOR,
5957
humidity=DPCode.DEHUMIDITY_SET_VALUE,
6058
device_class=HumidifierDeviceClass.DEHUMIDIFIER,
6159
),
62-
# Humidifier
63-
# https://developer.tuya.com/en/docs/iot/categoryjsq?id=Kaiuz1smr440b
64-
"jsq": TuyaHumidifierEntityDescription(
60+
DeviceCategory.JSQ: TuyaHumidifierEntityDescription(
6561
key=DPCode.SWITCH,
6662
dpcode=(DPCode.SWITCH, DPCode.SWITCH_SPRAY),
6763
current_humidity=DPCode.HUMIDITY_CURRENT,

0 commit comments

Comments
 (0)