Skip to content

Commit 6208b78

Browse files
authored
Ignore advertisments from devices with apple manufacturer id (#306)
* Ignore advertisments from devices with apple manufacturer id These do not appear to be valid devices and should not show up in discovery * Ignore advertisments from devices with apple manufacturer id These do not appear to be valid devices and should not show up in discovery
1 parent e91083e commit 6208b78

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

switchbot/adv_parser.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
)
4242
MFR_DATA_ORDER = (2409, 741, 89)
4343

44+
APPLE_MANUFACTURER_ID = 76
45+
4446

4547
class SwitchbotSupportedType(TypedDict):
4648
"""Supported type of Switchbot."""
@@ -242,10 +244,14 @@ def parse_advertisement_data(
242244

243245
_mfr_data = None
244246
_mfr_id = None
247+
manufacturer_data = advertisement_data.manufacturer_data
248+
if APPLE_MANUFACTURER_ID in manufacturer_data:
249+
return None
250+
245251
for mfr_id in MFR_DATA_ORDER:
246-
if mfr_id in advertisement_data.manufacturer_data:
252+
if mfr_id in manufacturer_data:
247253
_mfr_id = mfr_id
248-
_mfr_data = advertisement_data.manufacturer_data[mfr_id]
254+
_mfr_data = manufacturer_data[mfr_id]
249255
break
250256

251257
if _mfr_data is None and _service_data is None:

tests/test_adv_parser.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,3 +1970,28 @@ def test_remote_passive() -> None:
19701970
rssi=-97,
19711971
active=False,
19721972
)
1973+
1974+
1975+
def test_parse_advertisement_ignores_devices_with_apple_manufacturer_id():
1976+
"""Test parse_advertisement_data ignores devices with apple manufacturer id."""
1977+
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
1978+
adv_data = generate_advertisement_data(
1979+
local_name="WoCurtain",
1980+
manufacturer_data={
1981+
89: b"\xcc\xf4\xc4\xf9\xacl",
1982+
2409: b"\xcc\xf4\xc4\xf9\xacl\xe2\x0f\x00\x12\x04",
1983+
76: b"\x10",
1984+
},
1985+
service_data={
1986+
"00000d00-0000-1000-8000-00805f9b34fb": b"c\xd0Yd\x11\x04",
1987+
"0000fd3d-0000-1000-8000-00805f9b34fb": b"c\xc0d\x00\x12\x04",
1988+
},
1989+
service_uuids=[
1990+
"00001800-0000-1000-8000-00805f9b34fb",
1991+
"00001801-0000-1000-8000-00805f9b34fb",
1992+
"cba20d00-224d-11e6-9fb8-0002a5d5c51b",
1993+
],
1994+
rssi=-2,
1995+
)
1996+
result = parse_advertisement_data(ble_device, adv_data)
1997+
assert result is None

0 commit comments

Comments
 (0)