Skip to content

Commit

Permalink
feat: add support for Linptech RS1BB(MI) (#77)
Browse files Browse the repository at this point in the history
* feat: add support for RS1BB
  • Loading branch information
kvakulo authored May 5, 2024
1 parent f861a2f commit 57d070c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/xiaomi_ble/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class DeviceEntry:
name="Motion Sensor",
model="HS1BB(MI)",
),
0x3F0F: DeviceEntry(name="Flood and Rain Sensor", model="RS1BB(MI)"),
0x01AA: DeviceEntry(
name="Temperature/Humidity Sensor",
model="LYWSDCGQ",
Expand Down
13 changes: 12 additions & 1 deletion src/xiaomi_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,16 @@ def obj4805(
return {}


def obj4806(
xobj: bytes, device: XiaomiBluetoothDeviceData, device_type: str
) -> dict[str, Any]:
"""Moisture"""
device.update_predefined_binary_sensor(
BinarySensorDeviceClass.MOISTURE, xobj[0] > 0
)
return {}


def obj4818(
xobj: bytes, device: XiaomiBluetoothDeviceData, device_type: str
) -> dict[str, Any]:
Expand Down Expand Up @@ -1428,6 +1438,7 @@ def obj4e1c(
0x4803: obj4803,
0x4804: obj4804,
0x4805: obj4805,
0x4806: obj4806,
0x4818: obj4818,
0x4A01: obj4a01,
0x4A08: obj4a08,
Expand Down Expand Up @@ -1620,7 +1631,7 @@ def _parse_xiaomi(
xiaomi_mac = xiaomi_mac_reversed[::-1]
if xiaomi_mac != source_mac:
_LOGGER.debug(
"MAC address doesn't match data frame. Expected: %s, Got: %s)",
"MAC address doesn't match data frame. Expected: %s, Got: %s",
to_mac(xiaomi_mac),
to_mac(source_mac),
)
Expand Down
46 changes: 46 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,52 @@ def test_Xiaomi_MS1BB_MI_obj4a13():
)


def test_Xiaomi_RS1BB_MI_obj4806():
"""Test Xiaomi parser for Linptech RS1BB(MI) with obj4806."""
data_string = b"XY\x0f?JgL\xb98\xc1\xa4\xd6\xe5{\x83\x04\x00\x00\xd0\x1e\x0bK"
advertisement = bytes_to_service_info(data_string, address="A4:C1:38:B9:4C:67")
bindkey = "33ede53321bc73c790a8daae4581f3d5"

device = XiaomiBluetoothDeviceData(bindkey=bytes.fromhex(bindkey))
assert device.supported(advertisement)
assert device.bindkey_verified
assert device.update(advertisement) == SensorUpdate(
title="Flood and Rain Sensor 4C67 (RS1BB(MI))",
devices={
None: SensorDeviceInfo(
name="Flood and Rain Sensor 4C67",
manufacturer="Xiaomi",
model="RS1BB(MI)",
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
),
},
binary_entity_descriptions={
KEY_MOISTURE: BinarySensorDescription(
device_key=KEY_MOISTURE,
device_class=BinarySensorDeviceClass.MOISTURE,
),
},
binary_entity_values={
KEY_MOISTURE: BinarySensorValue(
name="Moisture", device_key=KEY_MOISTURE, native_value=False
),
},
)


def test_Xiaomi_XMWXKG01YL():
"""Test Xiaomi parser for XMWXKG01YL Switch (double button)."""
data_string = b"XYI\x19Os\x12\x87\x83\xed\xdc\x0b48\n\x02\x00\x00\x8dI\xae("
Expand Down

0 comments on commit 57d070c

Please sign in to comment.