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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/xiaomi_ble/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ class DeviceEntry:
name="Button",
model="XMWXKG01LM",
),
0x38BB: DeviceEntry(
name="Button",
model="PTX_YK1_QMIMB",
),
0x098C: DeviceEntry(
name="Door Lock",
model="XMZNMST02YD",
Expand Down
58 changes: 48 additions & 10 deletions src/xiaomi_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,42 @@
return {}


def obj4a0c(
xobj: bytes, device: XiaomiBluetoothDeviceData, device_type: str
) -> dict[str, Any]:
if device_type == "PTX_YK1_QMIMB":
device.fire_event(
key=EventDeviceKeys.BUTTON,
event_type="press",
event_properties=None,
)
return {}


def obj4a0d(
xobj: bytes, device: XiaomiBluetoothDeviceData, device_type: str
) -> dict[str, Any]:
if device_type == "PTX_YK1_QMIMB":
device.fire_event(
key=EventDeviceKeys.BUTTON,
event_type="double_press",
event_properties=None,
)
return {}


def obj4a0e(
xobj: bytes, device: XiaomiBluetoothDeviceData, device_type: str
) -> dict[str, Any]:
if device_type == "PTX_YK1_QMIMB":
device.fire_event(
key=EventDeviceKeys.BUTTON,
event_type="long_press",
event_properties=None,
)
return {}


def obj4a0f(
xobj: bytes, device: XiaomiBluetoothDeviceData, device_type: str
) -> dict[str, Any]:
Expand Down Expand Up @@ -1376,6 +1412,9 @@
0x4818: obj4818,
0x4A01: obj4a01,
0x4A08: obj4a08,
0x4A0C: obj4a0c,
0x4A0D: obj4a0d,
0x4A0E: obj4a0e,
0x4A0F: obj4a0f,
0x4A12: obj4a12,
0x4A13: obj4a13,
Expand Down Expand Up @@ -1713,16 +1752,15 @@
break
this_start = payload_start + 3
dobject = payload[this_start:next_start]
if obj_length != 0:
resfunc = xiaomi_dataobject_dict.get(obj_typecode, None)
if resfunc:
self.unhandled.update(resfunc(dobject, self, device_type))
else:
_LOGGER.info(
"%s, UNKNOWN dataobject in payload! Adv: %s",
sinfo,
data.hex(),
)
resfunc = xiaomi_dataobject_dict.get(obj_typecode, None)
if resfunc:
self.unhandled.update(resfunc(dobject, self, device_type))
else:
_LOGGER.info(

Check warning on line 1759 in src/xiaomi_ble/parser.py

View check run for this annotation

Codecov / codecov/patch

src/xiaomi_ble/parser.py#L1759

Added line #L1759 was not covered by tests
"%s, UNKNOWN dataobject in payload! Adv: %s",
sinfo,
data.hex(),
)
payload_start = next_start

return True
Expand Down
116 changes: 116 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2505,6 +2505,122 @@ def test_Xiaomi_XMWXKG01YL():
)


def test_Xiaomi_PTX_YK1_QMIMB():
"""Test Xiaomi parser for PTX_YK1_QMIMB / 090615.remote.btsw1."""
# press
data_string = bytes.fromhex("5859bb380fb26a1a38c1a46756c02a0000e75ef84c")
advertisement = bytes_to_service_info(data_string, address="A4:C1:38:1A:6A:B2")
bindkey = "6fb3f0c214eef4f7ad78467d9aa5fc16"

device = XiaomiBluetoothDeviceData(bindkey=bytes.fromhex(bindkey))
assert device.supported(advertisement)
assert device.bindkey_verified
assert device.update(advertisement) == SensorUpdate(
title="Button 6AB2 (PTX_YK1_QMIMB)",
devices={
None: SensorDeviceInfo(
name="Button 6AB2",
manufacturer="Xiaomi",
model="PTX_YK1_QMIMB",
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="press",
event_properties=None,
),
},
)

# double press
data_string = bytes.fromhex("5859bb3810b26a1a38c1a433ea1b2a0000bad2e4b6")
advertisement = bytes_to_service_info(data_string, address="A4:C1:38:1A:6A:B2")
assert device.update(advertisement) == SensorUpdate(
title="Button 6AB2 (PTX_YK1_QMIMB)",
devices={
None: SensorDeviceInfo(
name="Button 6AB2",
manufacturer="Xiaomi",
model="PTX_YK1_QMIMB",
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,
),
},
)

# long press
data_string = bytes.fromhex("5859bb3811b26a1a38c1a4efb8ee2a0000604fc66f")
advertisement = bytes_to_service_info(data_string, address="A4:C1:38:1A:6A:B2")
assert device.update(advertisement) == SensorUpdate(
title="Button 6AB2 (PTX_YK1_QMIMB)",
devices={
None: SensorDeviceInfo(
name="Button 6AB2",
manufacturer="Xiaomi",
model="PTX_YK1_QMIMB",
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="long_press",
event_properties=None,
),
},
)


def test_Xiaomi_XMZNMS08LM_door():
"""Test Xiaomi parser for XMZNMS08LM."""
bindkey = "2c3795afa33019a8afdc17ba99e6f217"
Expand Down
Loading