1818from homeassistant .util .json import json_loads
1919
2020from . import TuyaConfigEntry
21- from .const import TUYA_DISCOVERY_NEW , DPCode , DPType
21+ from .const import TUYA_DISCOVERY_NEW , DeviceCategory , DPCode , DPType
2222from .entity import TuyaEntity
2323
2424
@@ -48,21 +48,16 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription):
4848# All descriptions can be found here. Mostly the Boolean data types in the
4949# default status set of each category (that don't have a set instruction)
5050# end up being a binary sensor.
51- # https://developer.tuya.com/en/docs/iot/standarddescription?id=K9i5ql6waswzq
52- BINARY_SENSORS : dict [str , tuple [TuyaBinarySensorEntityDescription , ...]] = {
53- # CO2 Detector
54- # https://developer.tuya.com/en/docs/iot/categoryco2bj?id=Kaiuz3wes7yuy
55- "co2bj" : (
51+ BINARY_SENSORS : dict [DeviceCategory , tuple [TuyaBinarySensorEntityDescription , ...]] = {
52+ DeviceCategory .CO2BJ : (
5653 TuyaBinarySensorEntityDescription (
5754 key = DPCode .CO2_STATE ,
5855 device_class = BinarySensorDeviceClass .SAFETY ,
5956 on_value = "alarm" ,
6057 ),
6158 TAMPER_BINARY_SENSOR ,
6259 ),
63- # CO Detector
64- # https://developer.tuya.com/en/docs/iot/categorycobj?id=Kaiuz3u1j6q1v
65- "cobj" : (
60+ DeviceCategory .COBJ : (
6661 TuyaBinarySensorEntityDescription (
6762 key = DPCode .CO_STATE ,
6863 device_class = BinarySensorDeviceClass .SAFETY ,
@@ -75,9 +70,7 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription):
7570 ),
7671 TAMPER_BINARY_SENSOR ,
7772 ),
78- # Dehumidifier
79- # https://developer.tuya.com/en/docs/iot/categorycs?id=Kaiuz1vcz4dha
80- "cs" : (
73+ DeviceCategory .CS : (
8174 TuyaBinarySensorEntityDescription (
8275 key = "tankfull" ,
8376 dpcode = DPCode .FAULT ,
@@ -103,18 +96,14 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription):
10396 translation_key = "wet" ,
10497 ),
10598 ),
106- # Smart Pet Feeder
107- # https://developer.tuya.com/en/docs/iot/categorycwwsq?id=Kaiuz2b6vydld
108- "cwwsq" : (
99+ DeviceCategory .CWWSQ : (
109100 TuyaBinarySensorEntityDescription (
110101 key = DPCode .FEED_STATE ,
111102 translation_key = "feeding" ,
112103 on_value = "feeding" ,
113104 ),
114105 ),
115- # Multi-functional Sensor
116- # https://developer.tuya.com/en/docs/iot/categorydgnbj?id=Kaiuz3yorvzg3
117- "dgnbj" : (
106+ DeviceCategory .DGNBJ : (
118107 TuyaBinarySensorEntityDescription (
119108 key = DPCode .GAS_SENSOR_STATE ,
120109 device_class = BinarySensorDeviceClass .GAS ,
@@ -177,57 +166,45 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription):
177166 ),
178167 TAMPER_BINARY_SENSOR ,
179168 ),
180- # Human Presence Sensor
181- # https://developer.tuya.com/en/docs/iot/categoryhps?id=Kaiuz42yhn1hs
182- "hps" : (
169+ DeviceCategory .HPS : (
183170 TuyaBinarySensorEntityDescription (
184171 key = DPCode .PRESENCE_STATE ,
185172 device_class = BinarySensorDeviceClass .OCCUPANCY ,
186173 on_value = {"presence" , "small_move" , "large_move" , "peaceful" },
187174 ),
188175 ),
189- # Formaldehyde Detector
190- # Note: Not documented
191- "jqbj" : (
176+ DeviceCategory .JQBJ : (
192177 TuyaBinarySensorEntityDescription (
193178 key = DPCode .CH2O_STATE ,
194179 device_class = BinarySensorDeviceClass .SAFETY ,
195180 on_value = "alarm" ,
196181 ),
197182 TAMPER_BINARY_SENSOR ,
198183 ),
199- # Methane Detector
200- # https://developer.tuya.com/en/docs/iot/categoryjwbj?id=Kaiuz40u98lkm
201- "jwbj" : (
184+ DeviceCategory .JWBJ : (
202185 TuyaBinarySensorEntityDescription (
203186 key = DPCode .CH4_SENSOR_STATE ,
204187 device_class = BinarySensorDeviceClass .GAS ,
205188 on_value = "alarm" ,
206189 ),
207190 TAMPER_BINARY_SENSOR ,
208191 ),
209- # Luminance Sensor
210- # https://developer.tuya.com/en/docs/iot/categoryldcg?id=Kaiuz3n7u69l8
211- "ldcg" : (
192+ DeviceCategory .LDCG : (
212193 TuyaBinarySensorEntityDescription (
213194 key = DPCode .TEMPER_ALARM ,
214195 device_class = BinarySensorDeviceClass .TAMPER ,
215196 entity_category = EntityCategory .DIAGNOSTIC ,
216197 ),
217198 TAMPER_BINARY_SENSOR ,
218199 ),
219- # Door and Window Controller
220- # https://developer.tuya.com/en/docs/iot/s?id=K9gf48r5zjsy9
221- "mc" : (
200+ DeviceCategory .MC : (
222201 TuyaBinarySensorEntityDescription (
223202 key = DPCode .STATUS ,
224203 device_class = BinarySensorDeviceClass .DOOR ,
225204 on_value = {"open" , "opened" },
226205 ),
227206 ),
228- # Door Window Sensor
229- # https://developer.tuya.com/en/docs/iot/s?id=K9gf48hm02l8m
230- "mcs" : (
207+ DeviceCategory .MCS : (
231208 TuyaBinarySensorEntityDescription (
232209 key = DPCode .DOORCONTACT_STATE ,
233210 device_class = BinarySensorDeviceClass .DOOR ,
@@ -238,41 +215,31 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription):
238215 ),
239216 TAMPER_BINARY_SENSOR ,
240217 ),
241- # Access Control
242- # https://developer.tuya.com/en/docs/iot/s?id=Kb0o2xhlkxbet
243- "mk" : (
218+ DeviceCategory .MK : (
244219 TuyaBinarySensorEntityDescription (
245220 key = DPCode .CLOSED_OPENED_KIT ,
246221 device_class = BinarySensorDeviceClass .LOCK ,
247222 on_value = {"AQAB" },
248223 ),
249224 ),
250- # PIR Detector
251- # https://developer.tuya.com/en/docs/iot/categorypir?id=Kaiuz3ss11b80
252- "pir" : (
225+ DeviceCategory .PIR : (
253226 TuyaBinarySensorEntityDescription (
254227 key = DPCode .PIR ,
255228 device_class = BinarySensorDeviceClass .MOTION ,
256229 on_value = "pir" ,
257230 ),
258231 TAMPER_BINARY_SENSOR ,
259232 ),
260- # PM2.5 Sensor
261- # https://developer.tuya.com/en/docs/iot/categorypm25?id=Kaiuz3qof3yfu
262- "pm2.5" : (
233+ DeviceCategory .PM2_5 : (
263234 TuyaBinarySensorEntityDescription (
264235 key = DPCode .PM25_STATE ,
265236 device_class = BinarySensorDeviceClass .SAFETY ,
266237 on_value = "alarm" ,
267238 ),
268239 TAMPER_BINARY_SENSOR ,
269240 ),
270- # Temperature and Humidity Sensor with External Probe
271- # New undocumented category qxj, see https://github.com/home-assistant/core/issues/136472
272- "qxj" : (TAMPER_BINARY_SENSOR ,),
273- # Gas Detector
274- # https://developer.tuya.com/en/docs/iot/categoryrqbj?id=Kaiuz3d162ubw
275- "rqbj" : (
241+ DeviceCategory .QXJ : (TAMPER_BINARY_SENSOR ,),
242+ DeviceCategory .RQBJ : (
276243 TuyaBinarySensorEntityDescription (
277244 key = DPCode .GAS_SENSOR_STATUS ,
278245 device_class = BinarySensorDeviceClass .GAS ,
@@ -285,87 +252,67 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription):
285252 ),
286253 TAMPER_BINARY_SENSOR ,
287254 ),
288- # Siren Alarm
289- # https://developer.tuya.com/en/docs/iot/categorysgbj?id=Kaiuz37tlpbnu
290- "sgbj" : (
255+ DeviceCategory .SGBJ : (
291256 TuyaBinarySensorEntityDescription (
292257 key = DPCode .CHARGE_STATE ,
293258 device_class = BinarySensorDeviceClass .BATTERY_CHARGING ,
294259 ),
295260 TAMPER_BINARY_SENSOR ,
296261 ),
297- # Water Detector
298- # https://developer.tuya.com/en/docs/iot/categorysj?id=Kaiuz3iub2sli
299- "sj" : (
262+ DeviceCategory .SJ : (
300263 TuyaBinarySensorEntityDescription (
301264 key = DPCode .WATERSENSOR_STATE ,
302265 device_class = BinarySensorDeviceClass .MOISTURE ,
303266 on_value = {"1" , "alarm" },
304267 ),
305268 TAMPER_BINARY_SENSOR ,
306269 ),
307- # Emergency Button
308- # https://developer.tuya.com/en/docs/iot/categorysos?id=Kaiuz3oi6agjy
309- "sos" : (
270+ DeviceCategory .SOS : (
310271 TuyaBinarySensorEntityDescription (
311272 key = DPCode .SOS_STATE ,
312273 device_class = BinarySensorDeviceClass .SAFETY ,
313274 ),
314275 TAMPER_BINARY_SENSOR ,
315276 ),
316- # Volatile Organic Compound Sensor
317- # Note: Undocumented in cloud API docs, based on test device
318- "voc" : (
277+ DeviceCategory .VOC : (
319278 TuyaBinarySensorEntityDescription (
320279 key = DPCode .VOC_STATE ,
321280 device_class = BinarySensorDeviceClass .SAFETY ,
322281 on_value = "alarm" ,
323282 ),
324283 TAMPER_BINARY_SENSOR ,
325284 ),
326- # Gateway control
327- # https://developer.tuya.com/en/docs/iot/wg?id=Kbcdadk79ejok
328- "wg2" : (
285+ DeviceCategory .WG2 : (
329286 TuyaBinarySensorEntityDescription (
330287 key = DPCode .MASTER_STATE ,
331288 device_class = BinarySensorDeviceClass .PROBLEM ,
332289 entity_category = EntityCategory .DIAGNOSTIC ,
333290 on_value = "alarm" ,
334291 ),
335292 ),
336- # Thermostat
337- # https://developer.tuya.com/en/docs/iot/f?id=K9gf45ld5l0t9
338- "wk" : (
293+ DeviceCategory .WK : (
339294 TuyaBinarySensorEntityDescription (
340295 key = DPCode .VALVE_STATE ,
341296 translation_key = "valve" ,
342297 on_value = "open" ,
343298 ),
344299 ),
345- # Thermostatic Radiator Valve
346- # Not documented
347- "wkf" : (
300+ DeviceCategory .WKF : (
348301 TuyaBinarySensorEntityDescription (
349302 key = DPCode .WINDOW_STATE ,
350303 device_class = BinarySensorDeviceClass .WINDOW ,
351304 on_value = "opened" ,
352305 ),
353306 ),
354- # Temperature and Humidity Sensor
355- # https://developer.tuya.com/en/docs/iot/categorywsdcg?id=Kaiuz3hinij34
356- "wsdcg" : (TAMPER_BINARY_SENSOR ,),
357- # Pressure Sensor
358- # https://developer.tuya.com/en/docs/iot/categoryylcg?id=Kaiuz3kc2e4gm
359- "ylcg" : (
307+ DeviceCategory .WSDCG : (TAMPER_BINARY_SENSOR ,),
308+ DeviceCategory .YLCG : (
360309 TuyaBinarySensorEntityDescription (
361310 key = DPCode .PRESSURE_STATE ,
362311 on_value = "alarm" ,
363312 ),
364313 TAMPER_BINARY_SENSOR ,
365314 ),
366- # Smoke Detector
367- # https://developer.tuya.com/en/docs/iot/categoryywbj?id=Kaiuz3f6sf952
368- "ywbj" : (
315+ DeviceCategory .YWBJ : (
369316 TuyaBinarySensorEntityDescription (
370317 key = DPCode .SMOKE_SENSOR_STATUS ,
371318 device_class = BinarySensorDeviceClass .SMOKE ,
@@ -378,9 +325,7 @@ class TuyaBinarySensorEntityDescription(BinarySensorEntityDescription):
378325 ),
379326 TAMPER_BINARY_SENSOR ,
380327 ),
381- # Vibration Sensor
382- # https://developer.tuya.com/en/docs/iot/categoryzd?id=Kaiuz3a5vrzno
383- "zd" : (
328+ DeviceCategory .ZD : (
384329 TuyaBinarySensorEntityDescription (
385330 key = f"{ DPCode .SHOCK_STATE } _vibration" ,
386331 dpcode = DPCode .SHOCK_STATE ,
0 commit comments