Skip to content

Commit 9d939f5

Browse files
Fix air purifier device type (#331)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 578b575 commit 9d939f5

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

switchbot/adv_parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ class SwitchbotSupportedType(TypedDict):
282282
"manufacturer_id": 2409,
283283
},
284284
"7": {
285-
"modelName": SwitchbotModel.AIR_PURIFIER,
286-
"modelFriendlyName": "Air Purifier",
285+
"modelName": SwitchbotModel.AIR_PURIFIER_TABLE,
286+
"modelFriendlyName": "Air Purifier Table",
287287
"func": process_air_purifier,
288288
"manufacturer_id": 2409,
289289
},
290290
"8": {
291-
"modelName": SwitchbotModel.AIR_PURIFIER,
292-
"modelFriendlyName": "Air Purifier",
291+
"modelName": SwitchbotModel.AIR_PURIFIER_TABLE,
292+
"modelFriendlyName": "Air Purifier Table",
293293
"func": process_air_purifier,
294294
"manufacturer_id": 2409,
295295
},

switchbot/const/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class SwitchbotModel(StrEnum):
7474
K10_PRO_VACUUM = "K10+ Pro Vacuum"
7575
K10_PRO_COMBO_VACUUM = "K10+ Pro Combo Vacuum"
7676
AIR_PURIFIER = "Air Purifier"
77+
AIR_PURIFIER_TABLE = "Air Purifier Table"
7778

7879

7980
__all__ = [

tests/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from dataclasses import dataclass
2+
3+
from switchbot import SwitchbotModel
4+
5+
6+
@dataclass
7+
class AirPurifierTestCase:
8+
manufacturer_data: bytes
9+
service_data: bytes
10+
data: dict
11+
model: str
12+
modelFriendlyName: str
13+
modelName: SwitchbotModel

tests/test_adv_parser.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from switchbot.const.lock import LockStatus
1212
from switchbot.models import SwitchBotAdvertisement
1313

14+
from . import AirPurifierTestCase
15+
1416
ADVERTISEMENT_DATA_DEFAULTS = {
1517
"local_name": "",
1618
"manufacturer_data": {},
@@ -2647,9 +2649,9 @@ def test_s10_with_empty_data() -> None:
26472649

26482650

26492651
@pytest.mark.parametrize(
2650-
("manufacturer_data", "service_data", "data", "model"),
2652+
"test_case",
26512653
[
2652-
(
2654+
AirPurifierTestCase(
26532655
b"\xf0\x9e\x9e\x96j\xd6\xa1\x81\x88\xe4\x00\x01\x95\x00\x00",
26542656
b"7\x00\x00\x95-\x00",
26552657
{
@@ -2664,8 +2666,10 @@ def test_s10_with_empty_data() -> None:
26642666
"sequence_number": 161,
26652667
},
26662668
"7",
2669+
"Air Purifier Table",
2670+
SwitchbotModel.AIR_PURIFIER_TABLE,
26672671
),
2668-
(
2672+
AirPurifierTestCase(
26692673
b'\xcc\x8d\xa2\xa7\x92>\t"\x80\x000\x00\x0f\x00\x00',
26702674
b"*\x00\x00\x15\x04\x00",
26712675
{
@@ -2680,8 +2684,10 @@ def test_s10_with_empty_data() -> None:
26802684
"sequence_number": 9,
26812685
},
26822686
"*",
2687+
"Air Purifier",
2688+
SwitchbotModel.AIR_PURIFIER,
26832689
),
2684-
(
2690+
AirPurifierTestCase(
26852691
b"\xcc\x8d\xa2\xa7\xe4\xa6\x0b\x83\x88d\x00\xea`\x00\x00",
26862692
b"+\x00\x00\x15\x04\x00",
26872693
{
@@ -2696,8 +2702,10 @@ def test_s10_with_empty_data() -> None:
26962702
"sequence_number": 11,
26972703
},
26982704
"+",
2705+
"Air Purifier",
2706+
SwitchbotModel.AIR_PURIFIER,
26992707
),
2700-
(
2708+
AirPurifierTestCase(
27012709
b"\xcc\x8d\xa2\xa7\xc1\xae\x9b\x81\x8c\xb2\x00\x01\x94\x00\x00",
27022710
b"8\x00\x00\x95-\x00",
27032711
{
@@ -2712,8 +2720,10 @@ def test_s10_with_empty_data() -> None:
27122720
"sequence_number": 155,
27132721
},
27142722
"8",
2723+
"Air Purifier Table",
2724+
SwitchbotModel.AIR_PURIFIER_TABLE,
27152725
),
2716-
(
2726+
AirPurifierTestCase(
27172727
b"\xcc\x8d\xa2\xa7\xc1\xae\x9e\xa1\x8c\x800\x01\x95\x00\x00",
27182728
b"8\x00\x00\x95-\x00",
27192729
{
@@ -2728,8 +2738,10 @@ def test_s10_with_empty_data() -> None:
27282738
"sequence_number": 158,
27292739
},
27302740
"8",
2741+
"Air Purifier Table",
2742+
SwitchbotModel.AIR_PURIFIER_TABLE,
27312743
),
2732-
(
2744+
AirPurifierTestCase(
27332745
b"\xcc\x8d\xa2\xa7\xc1\xae\x9e\x05\x8c\x800\x01\x95\x00\x00",
27342746
b"8\x00\x00\x95-\x00",
27352747
{
@@ -2744,26 +2756,28 @@ def test_s10_with_empty_data() -> None:
27442756
"sequence_number": 158,
27452757
},
27462758
"8",
2759+
"Air Purifier Table",
2760+
SwitchbotModel.AIR_PURIFIER_TABLE,
27472761
),
27482762
],
27492763
)
2750-
def test_air_purifier_active(manufacturer_data, service_data, data, model) -> None:
2764+
def test_air_purifier_active(test_case: AirPurifierTestCase) -> None:
27512765
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
27522766
adv_data = generate_advertisement_data(
2753-
manufacturer_data={2409: manufacturer_data},
2754-
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": service_data},
2767+
manufacturer_data={2409: test_case.manufacturer_data},
2768+
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": test_case.service_data},
27552769
rssi=-97,
27562770
)
27572771
result = parse_advertisement_data(ble_device, adv_data)
27582772
assert result == SwitchBotAdvertisement(
27592773
address="aa:bb:cc:dd:ee:ff",
27602774
data={
2761-
"rawAdvData": service_data,
2762-
"data": data,
2775+
"rawAdvData": test_case.service_data,
2776+
"data": test_case.data,
27632777
"isEncrypted": False,
2764-
"model": model,
2765-
"modelFriendlyName": "Air Purifier",
2766-
"modelName": SwitchbotModel.AIR_PURIFIER,
2778+
"model": test_case.model,
2779+
"modelFriendlyName": test_case.modelFriendlyName,
2780+
"modelName": test_case.modelName,
27672781
},
27682782
device=ble_device,
27692783
rssi=-97,
@@ -2796,7 +2810,7 @@ def test_air_purifier_passive() -> None:
27962810
"sequence_number": 161,
27972811
},
27982812
"isEncrypted": False,
2799-
"model": "8",
2813+
"model": "+",
28002814
"modelFriendlyName": "Air Purifier",
28012815
"modelName": SwitchbotModel.AIR_PURIFIER,
28022816
},

0 commit comments

Comments
 (0)