diff --git a/custom_components/ble_monitor/ble_parser/xiaomi.py b/custom_components/ble_monitor/ble_parser/xiaomi.py index d257f82a..a8f3284a 100755 --- a/custom_components/ble_monitor/ble_parser/xiaomi.py +++ b/custom_components/ble_monitor/ble_parser/xiaomi.py @@ -75,6 +75,7 @@ 0x18E3: "ZX1", 0x11C2: "SV40", 0x3F0F: "RS1BB", + 0x38BB: "PTX", } # Structured objects for data conversions @@ -769,6 +770,30 @@ def obj4a08(xobj): return {"motion": 1, "motion timer": 1, "illuminance": illu} +def obj4a0c(xobj): + """Single click PTX""" + return { + "one btn switch": "toggle", + "button switch": "single press", + } + + +def obj4a0d(xobj): + """Double click PTX""" + return { + "one btn switch": "toggle", + "button switch": "double press", + } + + +def obj4a0e(xobj): + """Long click PTX""" + return { + "one btn switch": "toggle", + "button switch": "long press", + } + + def obj4a0f(xobj): """Door/window broken open""" dev_forced = xobj[0] @@ -852,6 +877,12 @@ def obj4c14(xobj): return {"mode": mode} +def obj4e01(xobj): + """Low Battery""" + low_batt = xobj[0] + return {"low battery": low_batt} + + def obj4e0c(xobj, device_type): """Click""" if device_type == "XMWXKG01YL": @@ -1065,6 +1096,9 @@ def obj5a16(xobj): 0x4818: obj4818, 0x4a01: obj4a01, 0x4a08: obj4a08, + 0x4a0c: obj4a0c, + 0x4a0d: obj4a0d, + 0x4a0e: obj4a0e, 0x4a0f: obj4a0f, 0x4a12: obj4a12, 0x4a13: obj4a13, @@ -1074,6 +1108,7 @@ def obj5a16(xobj): 0x4c03: obj4c03, 0x4c08: obj4c08, 0x4c14: obj4c14, + 0x4e01: obj4e01, 0x4e0c: obj4e0c, 0x4e0d: obj4e0d, 0x4e0e: obj4e0e, @@ -1267,7 +1302,9 @@ def parse_xiaomi(self, data: bytes, mac: str): _LOGGER.debug("Invalid payload data length, payload: %s", payload.hex()) break dobject = payload[payload_start + 3:next_start] - if dobject and obj_length != 0 or hex(obj_typecode) in ["0x4e0c", "0x4e0d", "0x4e0e"]: + if dobject and obj_length != 0 or hex(obj_typecode) in [ + "0x4a0c", "0x4a0d", "0x4a0e", "0x4e0c", "0x4e0d", "0x4e0e" + ]: resfunc = xiaomi_dataobject_dict.get(obj_typecode, None) if resfunc: if hex(obj_typecode) in ["0x8", "0x100e", "0x1001", "0xf", "0xb", "0x4e0c", "0x4e0d", "0x4e0e"]: diff --git a/custom_components/ble_monitor/const.py b/custom_components/ble_monitor/const.py index 7418b259..9baa83e2 100755 --- a/custom_components/ble_monitor/const.py +++ b/custom_components/ble_monitor/const.py @@ -1674,6 +1674,7 @@ class BLEMonitorBinarySensorEntityDescription( 'HS1BB(MI)' : [["illuminance", "battery", "rssi"], [], ["motion"]], 'XMWXKG01YL' : [["rssi"], ["two btn switch left", "two btn switch right"], []], 'XMWXKG01LM' : [["battery", "rssi"], ["one btn switch"], []], + 'PTX' : [["battery", "rssi"], ["one btn switch"], []], 'YLAI003' : [["rssi", "battery"], ["button"], []], 'YLYK01YL' : [["rssi"], ["remote"], ["remote single press", "remote long press"]], 'YLYK01YL-FANCL' : [["rssi"], ["fan remote"], []], @@ -1812,6 +1813,7 @@ class BLEMonitorBinarySensorEntityDescription( 'HS1BB(MI)' : 'Linptech', 'XMWXKG01YL' : 'Xiaomi', 'XMWXKG01LM' : 'Xiaomi', + 'PTX' : 'Xiaomi', 'SV40' : 'Lockin', 'SU001-T' : 'Petoneer', 'ATC' : 'ATC', diff --git a/custom_components/ble_monitor/manifest.json b/custom_components/ble_monitor/manifest.json index 6a149748..4b339646 100644 --- a/custom_components/ble_monitor/manifest.json +++ b/custom_components/ble_monitor/manifest.json @@ -14,5 +14,5 @@ "btsocket>=0.2.0", "pyric>=0.1.6.3" ], - "version": "12.9.2" + "version": "12.9.3" } diff --git a/custom_components/ble_monitor/test/test_xiaomi_parser.py b/custom_components/ble_monitor/test/test_xiaomi_parser.py index bf0c86e5..622478dd 100644 --- a/custom_components/ble_monitor/test/test_xiaomi_parser.py +++ b/custom_components/ble_monitor/test/test_xiaomi_parser.py @@ -1037,3 +1037,30 @@ def test_XMWXKG01LM_long_click(self): assert sensor_msg["one btn switch"] == "toggle" assert sensor_msg["button switch"] == "long press" assert sensor_msg["rssi"] == -64 + + def test_Xiaomi_PTX(self): + """Test Xiaomi parser for PTX BLE wireless switch.""" + self.aeskeys = {} + data_string = "043E2802010000adb9a538c1a41c020106181695fe5859bb3804adb9a538c1a4dc10b50400002c122fb6CC" + data = bytes(bytearray.fromhex(data_string)) + + aeskey = "a74510b40386d35ae6227a7451efc76e" + + is_ext_packet = True if data[3] == 0x0D else False + mac = (data[8 if is_ext_packet else 7:14 if is_ext_packet else 13])[::-1] + mac_address = mac.hex() + p_mac = bytes.fromhex(mac_address.replace(":", "").lower()) + p_key = bytes.fromhex(aeskey.lower()) + self.aeskeys[p_mac] = p_key + # pylint: disable=unused-variable + ble_parser = BleParser(aeskeys=self.aeskeys) + sensor_msg, tracker_msg = ble_parser.parse_raw_data(data) + + assert sensor_msg["firmware"] == "Xiaomi (MiBeacon V5 encrypted)" + assert sensor_msg["type"] == "PTX" + assert sensor_msg["mac"] == "A4C138A5B9AD" + assert sensor_msg["packet"] == 4 + assert sensor_msg["data"] + assert sensor_msg["one btn switch"] == "toggle" + assert sensor_msg["button switch"] == "single press" + assert sensor_msg["rssi"] == -52 diff --git a/docs/_devices/K9B-1BTN.md b/docs/_devices/Xiaomi_K9B-1BTN.md similarity index 100% rename from docs/_devices/K9B-1BTN.md rename to docs/_devices/Xiaomi_K9B-1BTN.md diff --git a/docs/_devices/K9B-2BTN.md b/docs/_devices/Xiaomi_K9B-2BTN.md similarity index 100% rename from docs/_devices/K9B-2BTN.md rename to docs/_devices/Xiaomi_K9B-2BTN.md diff --git a/docs/_devices/K9B-3BTN.md b/docs/_devices/Xiaomi_K9B-3BTN.md similarity index 100% rename from docs/_devices/K9B-3BTN.md rename to docs/_devices/Xiaomi_K9B-3BTN.md diff --git a/docs/_devices/K9BB-1BTN.md b/docs/_devices/Xiaomi_K9BB-1BTN.md similarity index 100% rename from docs/_devices/K9BB-1BTN.md rename to docs/_devices/Xiaomi_K9BB-1BTN.md diff --git a/docs/_devices/LYWSD02.md b/docs/_devices/Xiaomi_LYWSD02.md similarity index 100% rename from docs/_devices/LYWSD02.md rename to docs/_devices/Xiaomi_LYWSD02.md diff --git a/docs/_devices/LYWSD02MMC.md b/docs/_devices/Xiaomi_LYWSD02MMC.md similarity index 100% rename from docs/_devices/LYWSD02MMC.md rename to docs/_devices/Xiaomi_LYWSD02MMC.md diff --git a/docs/_devices/LYWSD03MMC.md b/docs/_devices/Xiaomi_LYWSD03MMC.md similarity index 100% rename from docs/_devices/LYWSD03MMC.md rename to docs/_devices/Xiaomi_LYWSD03MMC.md diff --git a/docs/_devices/LYWSDCGQ.md b/docs/_devices/Xiaomi_LYWSDCGQ.md similarity index 100% rename from docs/_devices/LYWSDCGQ.md rename to docs/_devices/Xiaomi_LYWSDCGQ.md diff --git a/docs/_devices/MCCGQ02HL.md b/docs/_devices/Xiaomi_MCCGQ02HL.md similarity index 100% rename from docs/_devices/MCCGQ02HL.md rename to docs/_devices/Xiaomi_MCCGQ02HL.md diff --git a/docs/_devices/MHO-C303.md b/docs/_devices/Xiaomi_MHO-C303.md similarity index 100% rename from docs/_devices/MHO-C303.md rename to docs/_devices/Xiaomi_MHO-C303.md diff --git a/docs/_devices/MHO-C401.md b/docs/_devices/Xiaomi_MHO-C401.md similarity index 100% rename from docs/_devices/MHO-C401.md rename to docs/_devices/Xiaomi_MHO-C401.md diff --git a/docs/_devices/MJWSD05MMC.md b/docs/_devices/Xiaomi_MJWSD05MMC.md similarity index 100% rename from docs/_devices/MJWSD05MMC.md rename to docs/_devices/Xiaomi_MJWSD05MMC.md diff --git a/docs/_devices/MJYD02YL.md b/docs/_devices/Xiaomi_MJYD02YL.md similarity index 100% rename from docs/_devices/MJYD02YL.md rename to docs/_devices/Xiaomi_MJYD02YL.md diff --git a/docs/_devices/MJZNMSQ01YD.md b/docs/_devices/Xiaomi_MJZNMSQ01YD.md similarity index 100% rename from docs/_devices/MJZNMSQ01YD.md rename to docs/_devices/Xiaomi_MJZNMSQ01YD.md diff --git a/docs/_devices/MUE4094RT.md b/docs/_devices/Xiaomi_MUE4094RT.md similarity index 100% rename from docs/_devices/MUE4094RT.md rename to docs/_devices/Xiaomi_MUE4094RT.md diff --git a/docs/_devices/Xiaomi_PTX.md b/docs/_devices/Xiaomi_PTX.md new file mode 100644 index 00000000..87c753d9 --- /dev/null +++ b/docs/_devices/Xiaomi_PTX.md @@ -0,0 +1,20 @@ +--- +manufacturer: Xiaomi +name: BLE wireless switch +model: PTX +image: PTX.png +physical_description: +broadcasted_properties: + - one btn switch + - battery + - rssi +broadcasted_property_notes: + - property: one btn switch + note: returns 'single press', 'double press' or 'long press' +broadcast_rate: +active_scan: false +encryption_key: Yes +custom_firmware: false +notes: + - The switch sensor state will return to `no press` after the time set with the [reset_timer](configuration_params#reset_timer) option. It is advised to change the reset time to 1 second (default = 35 seconds). +--- diff --git a/docs/_devices/RS1BB.md b/docs/_devices/Xiaomi_RS1BB.md similarity index 100% rename from docs/_devices/RS1BB.md rename to docs/_devices/Xiaomi_RS1BB.md diff --git a/docs/_devices/RTCGQ02LM.md b/docs/_devices/Xiaomi_RTCGQ02LM.md similarity index 100% rename from docs/_devices/RTCGQ02LM.md rename to docs/_devices/Xiaomi_RTCGQ02LM.md diff --git a/docs/_devices/WX08ZM.md b/docs/_devices/Xiaomi_WX08ZM.md similarity index 100% rename from docs/_devices/WX08ZM.md rename to docs/_devices/Xiaomi_WX08ZM.md diff --git a/docs/_devices/XMMF01JQD.md b/docs/_devices/Xiaomi_XMMF01JQD.md similarity index 100% rename from docs/_devices/XMMF01JQD.md rename to docs/_devices/Xiaomi_XMMF01JQD.md diff --git a/docs/_devices/XMTZC01HM_XMTZC04HM.md b/docs/_devices/Xiaomi_XMTZC01HM_XMTZC04HM.md similarity index 100% rename from docs/_devices/XMTZC01HM_XMTZC04HM.md rename to docs/_devices/Xiaomi_XMTZC01HM_XMTZC04HM.md diff --git a/docs/_devices/XMTZC02HM_XMTZC05HM_NUN4049CN.md b/docs/_devices/Xiaomi_XMTZC02HM_XMTZC05HM_NUN4049CN.md similarity index 100% rename from docs/_devices/XMTZC02HM_XMTZC05HM_NUN4049CN.md rename to docs/_devices/Xiaomi_XMTZC02HM_XMTZC05HM_NUN4049CN.md diff --git a/docs/_devices/XMWSDJ04MMC.md b/docs/_devices/Xiaomi_XMWSDJ04MMC.md similarity index 100% rename from docs/_devices/XMWSDJ04MMC.md rename to docs/_devices/Xiaomi_XMWSDJ04MMC.md diff --git a/docs/_devices/Xiaomi_XMWXKG01LM.md b/docs/_devices/Xiaomi_XMWXKG01LM.md new file mode 100644 index 00000000..bc0e207c --- /dev/null +++ b/docs/_devices/Xiaomi_XMWXKG01LM.md @@ -0,0 +1,20 @@ +--- +manufacturer: Xiaomi +name: Mijia wireless switch +model: XMWXKG01LM +image: XMWXKG01LM.png +physical_description: round switch +broadcasted_properties: + - one btn switch + - battery + - rssi +broadcasted_property_notes: + - property: one btn switch + note: returns 'single press', 'double press' or 'long press' +broadcast_rate: +active_scan: false +encryption_key: Yes +custom_firmware: false +notes: + - The switch sensor state will return to `no press` after the time set with the [reset_timer](configuration_params#reset_timer) option. It is advised to change the reset time to 1 second (default = 35 seconds). +--- diff --git a/docs/_devices/XMWXKG01YL.md b/docs/_devices/Xiaomi_XMWXKG01YL.md similarity index 100% rename from docs/_devices/XMWXKG01YL.md rename to docs/_devices/Xiaomi_XMWXKG01YL.md diff --git a/docs/_devices/XMZNMS04LM.md b/docs/_devices/Xiaomi_XMZNMS04LM.md similarity index 100% rename from docs/_devices/XMZNMS04LM.md rename to docs/_devices/Xiaomi_XMZNMS04LM.md diff --git a/docs/_devices/XMZNMS08LM.md b/docs/_devices/Xiaomi_XMZNMS08LM.md similarity index 100% rename from docs/_devices/XMZNMS08LM.md rename to docs/_devices/Xiaomi_XMZNMS08LM.md diff --git a/docs/_devices/XMZNMST02YD.md b/docs/_devices/Xiaomi_XMZNMST02YD.md similarity index 100% rename from docs/_devices/XMZNMST02YD.md rename to docs/_devices/Xiaomi_XMZNMST02YD.md diff --git a/docs/_devices/YLAI003.md b/docs/_devices/Xiaomi_YLAI003.md similarity index 100% rename from docs/_devices/YLAI003.md rename to docs/_devices/Xiaomi_YLAI003.md diff --git a/docs/_devices/YLKG07YL_YLKG08YL.md b/docs/_devices/Xiaomi_YLKG07YL_YLKG08YL.md similarity index 100% rename from docs/_devices/YLKG07YL_YLKG08YL.md rename to docs/_devices/Xiaomi_YLKG07YL_YLKG08YL.md diff --git a/docs/_devices/YLYB01YL-BHFRC.md b/docs/_devices/Xiaomi_YLYB01YL-BHFRC.md similarity index 100% rename from docs/_devices/YLYB01YL-BHFRC.md rename to docs/_devices/Xiaomi_YLYB01YL-BHFRC.md diff --git a/docs/_devices/YLYK01YL-FANCL.md b/docs/_devices/Xiaomi_YLYK01YL-FANCL.md similarity index 100% rename from docs/_devices/YLYK01YL-FANCL.md rename to docs/_devices/Xiaomi_YLYK01YL-FANCL.md diff --git a/docs/_devices/YLYK01YL-VENFAN.md b/docs/_devices/Xiaomi_YLYK01YL-VENFAN.md similarity index 100% rename from docs/_devices/YLYK01YL-VENFAN.md rename to docs/_devices/Xiaomi_YLYK01YL-VENFAN.md diff --git a/docs/_devices/YLYK01YL.md b/docs/_devices/Xiaomi_YLYK01YL.md similarity index 100% rename from docs/_devices/YLYK01YL.md rename to docs/_devices/Xiaomi_YLYK01YL.md diff --git a/docs/_devices/YM-K1501.md b/docs/_devices/Xiaomi_YM-K1501.md similarity index 100% rename from docs/_devices/YM-K1501.md rename to docs/_devices/Xiaomi_YM-K1501.md diff --git a/docs/_devices/ZNMS16LM.md b/docs/_devices/Xiaomi_ZNMS16LM.md similarity index 100% rename from docs/_devices/ZNMS16LM.md rename to docs/_devices/Xiaomi_ZNMS16LM.md diff --git a/docs/_devices/ZNMS17LM.md b/docs/_devices/Xiaomi_ZNMS17LM.md similarity index 100% rename from docs/_devices/ZNMS17LM.md rename to docs/_devices/Xiaomi_ZNMS17LM.md diff --git a/docs/assets/images/PTX.png b/docs/assets/images/PTX.png new file mode 100644 index 00000000..9c7e60fc Binary files /dev/null and b/docs/assets/images/PTX.png differ