Skip to content

Commit 7102b54

Browse files
authored
Add passive data mapping for more devices (#163)
1 parent c1c4ad5 commit 7102b54

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

switchbot/adv_parser.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"0000fd3d-0000-1000-8000-00805f9b34fb",
3030
"00000d00-0000-1000-8000-00805f9b34fb",
3131
)
32-
MFR_DATA_ORDER = (2409, 89)
32+
MFR_DATA_ORDER = (2409, 741, 89)
3333

3434

3535
class SwitchbotSupportedType(TypedDict):
@@ -93,11 +93,14 @@ class SwitchbotSupportedType(TypedDict):
9393
"modelName": SwitchbotModel.PLUG_MINI,
9494
"modelFriendlyName": "Plug Mini",
9595
"func": process_woplugmini,
96+
"manufacturer_data_length": 12,
97+
"manufacturer_id": 2409,
9698
},
9799
"j": {
98100
"modelName": SwitchbotModel.PLUG_MINI,
99101
"modelFriendlyName": "Plug Mini (JP)",
100102
"func": process_woplugmini,
103+
"manufacturer_id": 2409,
101104
},
102105
"u": {
103106
"modelName": SwitchbotModel.COLOR_BULB,
@@ -109,11 +112,14 @@ class SwitchbotSupportedType(TypedDict):
109112
"modelName": SwitchbotModel.CEILING_LIGHT,
110113
"modelFriendlyName": "Ceiling Light",
111114
"func": process_woceiling,
115+
"manufacturer_id": 2409,
112116
},
113117
"e": {
114118
"modelName": SwitchbotModel.HUMIDIFIER,
115119
"modelFriendlyName": "Humidifier",
116120
"func": process_wohumidifier,
121+
"manufacturer_id": 741,
122+
"manufacturer_data_length": 6,
117123
},
118124
"o": {
119125
"modelName": SwitchbotModel.LOCK,

switchbot/adv_parsers/humidifier.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ def process_wohumidifier(
1818
) -> dict[str, bool | int]:
1919
"""Process WoHumi services data."""
2020
if data is None:
21-
return {}
22-
_LOGGER.debug("mfr_data: %s", mfr_data.hex())
23-
_LOGGER.debug("data: %s", data.hex())
21+
return {
22+
"isOn": None,
23+
"level": None,
24+
"switchMode": True,
25+
}
2426

2527
return {
2628
"isOn": bool(data[1]),

tests/test_adv_parser.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_parse_advertisement_data_curtain():
5454
},
5555
device=ble_device,
5656
rssi=-80,
57+
active=True,
5758
)
5859

5960

@@ -85,8 +86,10 @@ def test_parse_advertisement_data_curtain_passive():
8586
},
8687
device=ble_device,
8788
rssi=-80,
89+
active=False,
8890
)
8991

92+
9093
def test_parse_advertisement_data_curtain_position_zero():
9194
"""Test parse_advertisement_data for curtain position zero."""
9295
ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any")
@@ -121,6 +124,7 @@ def test_parse_advertisement_data_curtain_position_zero():
121124
},
122125
device=ble_device,
123126
rssi=-52,
127+
active=True,
124128
)
125129

126130

@@ -164,6 +168,7 @@ def test_parse_advertisement_data_curtain_firmware_six_position_100():
164168
},
165169
device=ble_device,
166170
rssi=-62,
171+
active=True,
167172
)
168173

169174

@@ -207,6 +212,7 @@ def test_parse_advertisement_data_curtain_firmware_six_position_100_other_rssi()
207212
},
208213
device=ble_device,
209214
rssi=-67,
215+
active=True,
210216
)
211217

212218

@@ -244,6 +250,7 @@ def test_parse_advertisement_data_curtain_fully_closed():
244250
},
245251
device=ble_device,
246252
rssi=1,
253+
active=True,
247254
)
248255

249256

@@ -281,6 +288,7 @@ def test_parse_advertisement_data_curtain_fully_open():
281288
},
282289
device=ble_device,
283290
rssi=1,
291+
active=True,
284292
)
285293

286294

@@ -315,6 +323,7 @@ def test_parse_advertisement_data_contact():
315323
},
316324
device=ble_device,
317325
rssi=-80,
326+
active=True,
318327
)
319328

320329

@@ -351,6 +360,7 @@ def test_new_bot_firmware():
351360
},
352361
device=ble_device,
353362
rssi=-90,
363+
active=True,
354364
)
355365

356366

@@ -394,6 +404,7 @@ def test_parse_advertisement_data_curtain_firmware_six_fully_closed():
394404
},
395405
device=ble_device,
396406
rssi=-2,
407+
active=True,
397408
)
398409

399410

@@ -437,6 +448,7 @@ def test_parse_advertisement_data_curtain_firmware_six_fully_open():
437448
},
438449
device=ble_device,
439450
rssi=-2,
451+
active=True,
440452
)
441453

442454

@@ -472,6 +484,7 @@ def test_contact_sensor_mfr():
472484
},
473485
device=ble_device,
474486
rssi=-70,
487+
active=True,
475488
)
476489

477490

@@ -505,6 +518,7 @@ def test_contact_sensor_mfr_no_service_data():
505518
},
506519
device=ble_device,
507520
rssi=-70,
521+
active=False,
508522
)
509523

510524

@@ -539,6 +553,7 @@ def test_contact_sensor_srv():
539553
},
540554
device=ble_device,
541555
rssi=-70,
556+
active=True,
542557
)
543558

544559

@@ -574,6 +589,7 @@ def test_contact_sensor_open():
574589
},
575590
device=ble_device,
576591
rssi=-59,
592+
active=True,
577593
)
578594

579595

@@ -609,6 +625,7 @@ def test_contact_sensor_closed():
609625
},
610626
device=ble_device,
611627
rssi=-50,
628+
active=True,
612629
)
613630

614631

@@ -638,6 +655,7 @@ def test_switchbot_passive():
638655
},
639656
device=ble_device,
640657
rssi=-50,
658+
active=False,
641659
)
642660

643661

@@ -672,6 +690,7 @@ def test_bulb_active():
672690
},
673691
device=ble_device,
674692
rssi=-50,
693+
active=True,
675694
)
676695

677696

@@ -708,6 +727,7 @@ def test_lightstrip_passive():
708727
},
709728
device=ble_device,
710729
rssi=-50,
730+
active=False,
711731
)
712732

713733

@@ -729,6 +749,7 @@ def test_wosensor_passive_and_active():
729749
"fahrenheit": False,
730750
"humidity": 53,
731751
"temp": {"c": 24.6, "f": 76.28},
752+
"temperature": 24.6,
732753
},
733754
"isEncrypted": False,
734755
"model": "T",
@@ -738,6 +759,7 @@ def test_wosensor_passive_and_active():
738759
},
739760
device=ble_device,
740761
rssi=-50,
762+
active=True,
741763
)
742764

743765

@@ -759,6 +781,7 @@ def test_wosensor_active():
759781
"fahrenheit": False,
760782
"humidity": 53,
761783
"temp": {"c": 24.6, "f": 76.28},
784+
"temperature": 24.6,
762785
},
763786
"isEncrypted": False,
764787
"model": "T",
@@ -768,6 +791,7 @@ def test_wosensor_active():
768791
},
769792
device=ble_device,
770793
rssi=-50,
794+
active=True,
771795
)
772796

773797

@@ -789,6 +813,7 @@ def test_wosensor_passive_only():
789813
"fahrenheit": False,
790814
"humidity": 53,
791815
"temp": {"c": 24.6, "f": 76.28},
816+
"temperature": 24.6,
792817
},
793818
"isEncrypted": False,
794819
"model": "T",
@@ -798,6 +823,7 @@ def test_wosensor_passive_only():
798823
},
799824
device=ble_device,
800825
rssi=-50,
826+
active=False,
801827
)
802828

803829

@@ -834,6 +860,7 @@ def test_motion_sensor_clear():
834860
},
835861
device=ble_device,
836862
rssi=-87,
863+
active=True,
837864
)
838865

839866

@@ -870,6 +897,7 @@ def test_motion_sensor_clear_passive():
870897
},
871898
device=ble_device,
872899
rssi=-87,
900+
active=False,
873901
)
874902

875903

@@ -906,6 +934,7 @@ def test_motion_sensor_motion():
906934
},
907935
device=ble_device,
908936
rssi=-87,
937+
active=True,
909938
)
910939

911940

@@ -942,6 +971,7 @@ def test_motion_sensor_motion_passive():
942971
},
943972
device=ble_device,
944973
rssi=-87,
974+
active=False,
945975
)
946976

947977

@@ -978,6 +1008,7 @@ def test_motion_sensor_is_light_passive():
9781008
},
9791009
device=ble_device,
9801010
rssi=-93,
1011+
active=True,
9811012
)
9821013

9831014

@@ -1014,6 +1045,7 @@ def test_motion_sensor_is_light_active():
10141045
},
10151046
device=ble_device,
10161047
rssi=-93,
1048+
active=True,
10171049
)
10181050

10191051

@@ -1049,6 +1081,7 @@ def test_motion_with_light_detected():
10491081
},
10501082
device=ble_device,
10511083
rssi=-84,
1084+
active=True,
10521085
)
10531086

10541087

@@ -1083,4 +1116,5 @@ def test_motion_sensor_motion_passive():
10831116
},
10841117
device=ble_device,
10851118
rssi=-87,
1119+
active=False,
10861120
)

0 commit comments

Comments
 (0)