Skip to content

Commit 0201972

Browse files
authored
Fix contact timeout never being set (#134)
1 parent f7ba9ae commit 0201972

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

switchbot/adv_parsers/contact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
def process_wocontact(data: bytes, mfr_data: bytes | None) -> dict[str, bool | int]:
66
"""Process woContact Sensor services data."""
7-
contact_timeout = data[3] & 0b00000110 == 0b00000110
7+
contact_timeout = data[3] & 0b00000100 == 0b00000100
88
contact_open = data[3] & 0b00000010 == 0b00000010
99
return {
1010
"tested": bool(data[1] & 0b10000000),

tests/test_adv_parser.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,38 @@ def test_parse_advertisement_data_curtain():
5656
)
5757

5858

59+
def test_parse_advertisement_data_contact():
60+
"""Test parse_advertisement_data for the contact sensor."""
61+
ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any")
62+
adv_data = generate_advertisement_data(
63+
manufacturer_data={2409: b"\xe7\xabF\xac\x8f\x92|\x0f\x00\x11\x04"},
64+
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b'd@d\x05\x00u\x00\xf8\x12'},
65+
rssi=-80,
66+
)
67+
result = parse_advertisement_data(ble_device, adv_data)
68+
assert result == SwitchBotAdvertisement(
69+
address="aa:bb:cc:dd:ee:ff",
70+
data={
71+
"rawAdvData": b'd@d\x05\x00u\x00\xf8\x12',
72+
"data": {
73+
"button_count": 2,
74+
'contact_open': True,
75+
'contact_timeout': True,
76+
"is_light": True,
77+
"battery": 100,
78+
'motion_detected': True,
79+
"tested": False
80+
},
81+
"isEncrypted": False,
82+
"model": "d",
83+
"modelFriendlyName": 'Contact Sensor',
84+
"modelName": SwitchbotModel.CONTACT_SENSOR,
85+
},
86+
device=ble_device,
87+
rssi=-80,
88+
)
89+
90+
5991
def test_parse_advertisement_data_empty():
6092
"""Test parse_advertisement_data with empty data does not blow up."""
6193
ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any")

0 commit comments

Comments
 (0)