-
-
Notifications
You must be signed in to change notification settings - Fork 277
Add support for PTX-F1-Display and enhance debugging tools #1533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
M1k0t0
wants to merge
13
commits into
custom-components:master
Choose a base branch
from
M1k0t0:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
caae392
Add PTX-F1-Display (090615.remote.x1swd) support and debug logs
M1k0t0 c279925
Revert "Add PTX-F1-Display (090615.remote.x1swd) support and debug logs"
M1k0t0 c7462dc
Add Xiaomi PTX F1 (Display) device docs and image
M1k0t0 d4de440
Update test_xiaomi_parser.py
M1k0t0 15847a5
Add Xiaomi MiBeacon V4/V5 anonymizer
M1k0t0 ef4bb7e
Update Xiaomi_PTX_F1_Display.md
M1k0t0 9f9e498
Revert "Add Xiaomi MiBeacon V4/V5 anonymizer"
M1k0t0 8c2f12f
Reapply "Add Xiaomi MiBeacon V4/V5 anonymizer"
M1k0t0 fb3815f
Merge branch 'custom-components:master' into master
M1k0t0 ed1efe8
Address PTX-F1-Display review feedback
Copilot 59687de
Merge pull request #1 from M1k0t0/copilot/fix-issue-from-pull-request…
M1k0t0 dc98cfc
Update custom_components/ble_monitor/ble_parser/xiaomi.py
M1k0t0 a4a0536
Update docs/_devices/Xiaomi_PTX_F1_Display.md
M1k0t0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1215,6 +1215,90 @@ def test_Xiaomi_PTX(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["button switch"] == "single press" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["rssi"] == -52 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_Xiaomi_PTX_F1_Display_single_press(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Test Xiaomi parser for PTX-F1-Display single press on switch 4.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.aeskeys = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data_string = "043E3E0201000066554433221132020106191695FE5859C5642D6655443322112D9475BB270100AB9CBFA914093039303631352E72656D6F74652E7831737764C6".replace(" ", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data = bytes(bytearray.fromhex(data_string)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aeskey = "00112233445566778899aabbccddeeff" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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-F1-Display" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["mac"] == "112233445566" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["packet"] == 45 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["data"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["four btn switch 4"] == "toggle" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["button switch"] == "single press" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["rssi"] == -58 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["local_name"] == "090615.remote.x1swd" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_Xiaomi_PTX_F1_Display_temperature(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Test Xiaomi parser for PTX-F1-Display temperature.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.aeskeys = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data_string = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "043E29020100006655443322111D020106191695FE5859C56433665544332211997B546B0C01009089C35AC4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ).replace(" ", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data = bytes(bytearray.fromhex(data_string)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aeskey = "00112233445566778899aabbccddeeff" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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-F1-Display" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["mac"] == "112233445566" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["packet"] == 51 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["data"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["temperature"] == 25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["rssi"] == -60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["local_name"] == "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_Xiaomi_PTX_F1_Display_humidity(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Test Xiaomi parser for PTX-F1-Display humidity.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.aeskeys = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data_string = "043E29020100006655443322111D020106191695FE5859C56433665544332211D67B54550C01001D8F98BBC4".replace(" ", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data = bytes(bytearray.fromhex(data_string)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| aeskey = "00112233445566778899aabbccddeeff" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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-F1-Display" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["mac"] == "112233445566" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["packet"] == 51 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["data"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["humidity"] == 39 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["rssi"] == -60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert sensor_msg["local_name"] == "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_Xiaomi_PTX_F1_Display_temperature(self): | |
| """Test Xiaomi parser for PTX-F1-Display temperature.""" | |
| self.aeskeys = {} | |
| data_string = "043E29020100006655443322111D020106191695FE5859C56433665544332211D67B54550C01001D8F98BBC4".replace(" ", "") | |
| data = bytes(bytearray.fromhex(data_string)) | |
| aeskey = "00112233445566778899aabbccddeeff" | |
| 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-F1-Display" | |
| assert sensor_msg["mac"] == "112233445566" | |
| assert sensor_msg["packet"] == 51 | |
| assert sensor_msg["data"] | |
| # Validate that temperature is decoded and numeric; exact value depends on obj605d payload. | |
| assert "temperature" in sensor_msg | |
| assert isinstance(sensor_msg["temperature"], (int, float)) | |
| assert sensor_msg["rssi"] == -60 | |
| assert sensor_msg["local_name"] == "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- | ||
| manufacturer: Xiaomi | ||
| name: PTX F1 4-Button Wireless Switch (Display Version) | ||
| model: F1 | ||
| image: PTX_F1_Display.webp | ||
| physical_description: | ||
| broadcasted_properties: | ||
| - temperature | ||
| - humidity | ||
| - four btn switch 1 | ||
| - four btn switch 2 | ||
| - four btn switch 3 | ||
| - four btn switch 4 | ||
|
M1k0t0 marked this conversation as resolved.
|
||
| - button switch | ||
| - rssi | ||
| broadcasted_property_notes: | ||
| - property: four btn switch 1 | ||
| note: always "toggle"; actual press type ('short press', 'double press', 'long press') is reported via the 'button switch' property | ||
| - property: four btn switch 2 | ||
| note: always "toggle"; actual press type ('short press', 'double press', 'long press') is reported via the 'button switch' property | ||
| - property: four btn switch 3 | ||
| note: always "toggle"; actual press type ('short press', 'double press', 'long press') is reported via the 'button switch' property | ||
| - property: four btn switch 4 | ||
| note: always "toggle"; actual press type ('short press', 'double press', 'long press') is reported via the 'button switch' property | ||
| broadcast_rate: | ||
| active_scan: | ||
| encryption_key: true | ||
| custom_firmware: | ||
| notes: | ||
| - Unable to retrieve the battery percentage right now. (need help!) | ||
| - 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). | ||
| --- | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new debug log computes
data.hex()unconditionally;.hex()is evaluated even when debug logging is disabled, which can add measurable overhead in a hot path (duplicate filtering). Consider guarding with_LOGGER.isEnabledFor(logging.DEBUG)(or equivalent) before building the hex string; same applies to the other newly added debug statements below.