Skip to content

Commit 4e83a81

Browse files
committed
Merge branch 'refs/heads/master' into support_evaporative_humidifer
2 parents 4763ab2 + 3479998 commit 4e83a81

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ci:
99

1010
repos:
1111
- repo: https://github.com/commitizen-tools/commitizen
12-
rev: v4.2.1
12+
rev: v4.2.2
1313
hooks:
1414
- id: commitizen
1515
stages: [commit-msg]
@@ -38,7 +38,7 @@ repos:
3838
- id: pyupgrade
3939
args: [--py311-plus]
4040
- repo: https://github.com/astral-sh/ruff-pre-commit
41-
rev: v0.9.6
41+
rev: v0.9.7
4242
hooks:
4343
- id: ruff
4444
args: [--fix]

setup.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77

88
setup(
99
name="PySwitchbot",
10-
packages=["switchbot", "switchbot.devices", "switchbot.adv_parsers"],
10+
packages=[
11+
"switchbot",
12+
"switchbot.devices",
13+
"switchbot.const",
14+
"switchbot.adv_parsers",
15+
],
1116
install_requires=[
1217
"aiohttp>=3.9.5",
1318
"bleak>=0.19.0",
1419
"bleak-retry-connector>=3.4.0",
1520
"cryptography>=39.0.0",
1621
"pyOpenSSL>=23.0.0",
1722
],
18-
version="0.56.0",
23+
version="0.56.1",
1924
description="A library to communicate with Switchbot",
2025
long_description=long_description,
2126
long_description_content_type="text/markdown",

switchbot/adv_parser.py

+8-2
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."""
@@ -248,10 +250,14 @@ def parse_advertisement_data(
248250

249251
_mfr_data = None
250252
_mfr_id = None
253+
manufacturer_data = advertisement_data.manufacturer_data
254+
if APPLE_MANUFACTURER_ID in manufacturer_data:
255+
return None
256+
251257
for mfr_id in MFR_DATA_ORDER:
252-
if mfr_id in advertisement_data.manufacturer_data:
258+
if mfr_id in manufacturer_data:
253259
_mfr_id = mfr_id
254-
_mfr_data = advertisement_data.manufacturer_data[mfr_id]
260+
_mfr_data = manufacturer_data[mfr_id]
255261
break
256262

257263
if _mfr_data is None and _service_data is None:

tests/test_adv_parser.py

+25
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)