Skip to content

Commit 2404c27

Browse files
authored
Merge pull request #505 from custom-components/device_specific_parser
Device specific output from parser
2 parents 63bd976 + 74f93db commit 2404c27

File tree

2 files changed

+59
-42
lines changed

2 files changed

+59
-42
lines changed

custom_components/ble_monitor/ble_parser/xiaomi.py

+58-41
Original file line numberDiff line numberDiff line change
@@ -212,33 +212,27 @@ def obj000b(xobj):
212212
return {}
213213

214214

215-
def obj000f(xobj):
215+
def obj000f(xobj, device_type):
216216
# Moving with light
217217
if len(xobj) == 3:
218218
(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 {}
223229
else:
224230
return {}
225231

226232

227-
def obj1001(xobj):
228-
# Button
233+
def obj1001(xobj, device_type):
229234
if len(xobj) == 3:
230235
(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
242236

243237
# remote command and remote binary
244238
remote_command = None
@@ -353,28 +347,48 @@ def obj1001(xobj):
353347
elif press == 6:
354348
button_press_type = "long press"
355349

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
378392
return result
379393

380394
else:
@@ -743,7 +757,10 @@ def parse_xiaomi(self, data, source_mac, rssi):
743757
if obj_length != 0:
744758
resfunc = xiaomi_dataobject_dict.get(obj_typecode, None)
745759
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))
747764
else:
748765
if self.report_unknown == "Xiaomi":
749766
_LOGGER.info("%s, UNKNOWN dataobject in payload! Adv: %s", sinfo, data.hex())

custom_components/ble_monitor/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
],
1212
"dependencies": [],
1313
"codeowners": ["@Ernst79", "@Magalex2x14", "@Thrilleratplay"],
14-
"version": "5.2.1",
14+
"version": "5.3.0",
1515
"iot_class": "local_polling"
1616
}

0 commit comments

Comments
 (0)