@@ -212,33 +212,27 @@ def obj000b(xobj):
212
212
return {}
213
213
214
214
215
- def obj000f (xobj ):
215
+ def obj000f (xobj , device_type ):
216
216
# Moving with light
217
217
if len (xobj ) == 3 :
218
218
(value ,) = LIGHT_STRUCT .unpack (xobj + b'\x00 ' )
219
- # MJYD02YL: 1 - moving no light, 100 - moving with light
220
- # RTCGQ02LM: 0 - moving no light, 256 - moving with light
221
- # CGPR1: moving, value is illumination in lux
222
- return {"motion" : 1 , "motion timer" : 1 , "light" : int (value >= 100 ), "illuminance" : value }
219
+
220
+ if device_type in ["MJYD02YL" , "RTCGQ02LM" ]:
221
+ # MJYD02YL: 1 - moving no light, 100 - moving with light
222
+ # RTCGQ02LM: 0 - moving no light, 256 - moving with light
223
+ return {"motion" : 1 , "motion timer" : 1 , "light" : int (value >= 100 )}
224
+ elif device_type == "CGPR1" :
225
+ # CGPR1: moving, value is illumination in lux
226
+ return {"motion" : 1 , "motion timer" : 1 , "illuminance" : value }
227
+ else :
228
+ return {}
223
229
else :
224
230
return {}
225
231
226
232
227
- def obj1001 (xobj ):
228
- # Button
233
+ def obj1001 (xobj , device_type ):
229
234
if len (xobj ) == 3 :
230
235
(button_type , value , press ) = BUTTON_STRUCT .unpack (xobj )
231
- # RTCGQ02LM: button
232
- # YLAI003: button
233
- # YLYK01YL: remote_command and remote_binary
234
- # YLYK01YL-FANRC: fan_remote_command, button
235
- # YLYK01YL-VENFAN: ven_fan_remote_command, button
236
- # YLYB01YL-BHFRC: bathroom_remote_command, button
237
- # YLKG07YL/YLKG08YL: button, dimmer
238
- # JTYJGD03MI: button
239
- # K9B-1BTN 1_btn_switch
240
- # K9B-2BTN 2_btn_switch_left, 2_btn_switch_right
241
- # K9B-3BTN 3_btn_switch_left, 3_btn_switch_middle, 3_btn_switch_right
242
236
243
237
# remote command and remote binary
244
238
remote_command = None
@@ -353,28 +347,48 @@ def obj1001(xobj):
353
347
elif press == 6 :
354
348
button_press_type = "long press"
355
349
356
- result = {
357
- "remote" : remote_command ,
358
- "fan remote" : fan_remote_command ,
359
- "ventilator fan remote" : ven_fan_remote_command ,
360
- "bathroom heater remote" : bathroom_remote_command ,
361
- "one btn switch" : one_btn_switch ,
362
- "two btn switch left" : two_btn_switch_left ,
363
- "two btn switch right" : two_btn_switch_right ,
364
- "three btn switch left" : three_btn_switch_left ,
365
- "three btn switch middle" : three_btn_switch_middle ,
366
- "three btn switch right" : three_btn_switch_right ,
367
- "button" : button_press_type ,
368
- "button switch" : btn_switch_press_type ,
369
- "dimmer" : dimmer ,
370
- }
371
-
372
- if remote_binary is not None :
373
- if button_press_type == "single press" :
374
- result ["remote single press" ] = remote_binary
375
- else :
376
- result ["remote long press" ] = remote_binary
377
-
350
+ # return device specific output
351
+ result = {}
352
+ if device_type in ["RTCGQ02LM" , "YLAI003" , "JTYJGD03MI" ]:
353
+ result ["button" ] = button_press_type
354
+ elif device_type == "YLYK01YL" :
355
+ result ["remote" ] = remote_command
356
+ if remote_binary is not None :
357
+ if button_press_type == "single press" :
358
+ result ["remote single press" ] = remote_binary
359
+ else :
360
+ result ["remote long press" ] = remote_binary
361
+ elif device_type == "YLYK01YL-FANRC" :
362
+ result ["fan remote" ] = fan_remote_command
363
+ result ["button" ] = button_press_type
364
+ elif device_type == "YLYK01YL-VENFAN" :
365
+ result ["ventilator fan remote" ] = ven_fan_remote_command
366
+ result ["button" ] = button_press_type
367
+ elif device_type == "YLYB01YL-BHFRC" :
368
+ result ["bathroom heater remote" ] = bathroom_remote_command
369
+ result ["button" ] = button_press_type
370
+ elif device_type == "YLKG07YL/YLKG08YL" :
371
+ result ["dimmer" ] = dimmer
372
+ result ["button" ] = button_press_type
373
+ elif device_type == "K9B-1BTN" :
374
+ result ["button switch" ] = btn_switch_press_type
375
+ result ["1_btn_switch" ] = one_btn_switch
376
+ elif device_type == "K9B-2BTN" :
377
+ result ["button switch" ] = btn_switch_press_type
378
+ if two_btn_switch_left :
379
+ result ["2_btn_switch_left" ] = two_btn_switch_left
380
+ if two_btn_switch_right :
381
+ result ["2_btn_switch_right" ] = two_btn_switch_right
382
+ elif device_type == "K9B-3BTN" :
383
+ result ["button switch" ] = btn_switch_press_type
384
+ if three_btn_switch_left :
385
+ result ["3_btn_switch_left" ] = three_btn_switch_left
386
+ if three_btn_switch_middle :
387
+ result ["3_btn_switch_middle" ] = three_btn_switch_middle
388
+ if three_btn_switch_right :
389
+ result ["3_btn_switch_right" ] = three_btn_switch_right
390
+ else :
391
+ return None
378
392
return result
379
393
380
394
else :
@@ -743,7 +757,10 @@ def parse_xiaomi(self, data, source_mac, rssi):
743
757
if obj_length != 0 :
744
758
resfunc = xiaomi_dataobject_dict .get (obj_typecode , None )
745
759
if resfunc :
746
- result .update (resfunc (object ))
760
+ if hex (obj_typecode ) in ["0x1001" , "0x000F" ]:
761
+ result .update (resfunc (object , device_type ))
762
+ else :
763
+ result .update (resfunc (object ))
747
764
else :
748
765
if self .report_unknown == "Xiaomi" :
749
766
_LOGGER .info ("%s, UNKNOWN dataobject in payload! Adv: %s" , sinfo , data .hex ())
0 commit comments