Skip to content
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

feat: add support for PTX_YK1_QMIMB / 090615.remote.btsw1 #72

Closed
wants to merge 1 commit into from

Conversation

likaci
Copy link

@likaci likaci commented Feb 21, 2024

A cheap wireless switch button from PTX
Spec and Introduction

Xiaomi Cloud Tokens Extractor info:

   NAME:     PTX wireless switch(bluetooth version)
   BLE KEY:  6fb3f0c214eef4f7ad78467d9aa5fc16
   MAC:      A4:C1:38:1A:6A:B2
   MODEL:    090615.remote.btsw1

Event and Service Data:

Press
5859bb380fb26a1a38c1a46756c02a0000e75ef84c
decrypt object 0C4A00

Double Press
5859bb3810b26a1a38c1a433ea1b2a0000bad2e4b6
decrypt object 0D4A00

Long Press
5859bb3811b26a1a38c1a4efb8ee2a0000604fc66f
decrypt object 0E4A00

BLE KEY: 6fb3f0c214eef4f7ad78467d9aa5fc16

Question:

As above, it seems that the data sent by this device is shorter than others,
which makes obj_length = 0, so the data could not be updated.
I removed this judgment, not sure if there are other implications, hopefully there is a better way to do it.

I tested it in the latest version of HA (2024.2.2), also simulated a XMWXKG01YL by esp32 and it works fine.

Thanks.

PTX wireless switch(bluetooth version) PTX_YK1_QMIMB / 090615.remote.btsw1
Copy link

codecov bot commented Feb 21, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (9918c70) 56.07% compared to head (949b9b7) 56.36%.
Report is 1 commits behind head on main.

Files Patch % Lines
src/xiaomi_ble/parser.py 68.75% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #72      +/-   ##
==========================================
+ Coverage   56.07%   56.36%   +0.28%     
==========================================
  Files           6        6              
  Lines         979      990      +11     
  Branches      210      212       +2     
==========================================
+ Hits          549      558       +9     
  Misses        332      332              
- Partials       98      100       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@likaci
Copy link
Author

likaci commented Feb 21, 2024

Attached PCB photos, PTX_WXAN_V1.12 TLSR8250

@likaci
Copy link
Author

likaci commented Feb 23, 2024

I found the similar judgment in ble_monitor,
It looks like XMWXKG01LM also sends the obj_length = 0 broadcast, but didn't found test cases.
Based on the broadcast data from ble_monitor/issues/1268, I add a test case, also failed.

test case
def test_Xiaomi_XMWXKG01LM():
    data_string = bytes.fromhex("58598723e90d692a3cc2181e13c1080000d2a24981")
    advertisement = bytes_to_service_info(data_string, address="18:C2:3C:2A:69:0D")
    bindkey = "c533a5ab361b0a24de4d21d1d9a3d8a1"

    device = XiaomiBluetoothDeviceData(bindkey=bytes.fromhex(bindkey))
    assert device.supported(advertisement)
    assert device.bindkey_verified
    assert device.update(advertisement) == SensorUpdate(
        title="Button 690D (XMWXKG01LM)",
        devices={
            None: SensorDeviceInfo(
                name="Button 690D",
                manufacturer="Xiaomi",
                model="XMWXKG01LM",
                hw_version=None,
                sw_version="Xiaomi (MiBeacon V5 encrypted)",
            )
        },
        entity_descriptions={
            KEY_SIGNAL_STRENGTH: SensorDescription(
                device_key=KEY_SIGNAL_STRENGTH,
                device_class=DeviceClass.SIGNAL_STRENGTH,
                native_unit_of_measurement="dBm",
            ),
        },
        entity_values={
            KEY_SIGNAL_STRENGTH: SensorValue(
                name="Signal Strength", device_key=KEY_SIGNAL_STRENGTH, native_value=-60
            ),
        },
        events={
            DeviceKey(key="button", device_id=None): Event(
                device_key=DeviceKey(key="button", device_id=None),
                name="Button",
                event_type="double_press",
                event_properties=None,
            ),
        },
    )

I'm wondering if it is necessary to check obj_length after checking payload and payload length.
Thanks.

@Ernst79
Copy link
Collaborator

Ernst79 commented Mar 10, 2024

Hi @likaci . Thanks for your contribution. You are right that XMWXKG01LM also has no data, other than the object. I was working on this device as well, and for some reason, I didn't receive an email when someone posts a PR here. So, we basically did the same 😄

I created a PR in #74 which is basically the same as your PR. The device also sends a battery low binary sensor state, so I added that one as well.

I'm closing your PR, not because I don't appreciate your contribution, but just because we did basically the same. I want to thank you anyways for your contribution. Keep an eye on #74

@Ernst79 Ernst79 closed this Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants