Browse Source

Fix missing id for motion sensors in adv parser (#159)

J. Nick Koston 1 year ago
parent
commit
b8667a10bc
2 changed files with 35 additions and 0 deletions
  1. 1 0
      switchbot/adv_parser.py
  2. 34 0
      tests/test_adv_parser.py

+ 1 - 0
switchbot/adv_parser.py

@@ -59,6 +59,7 @@ SUPPORTED_TYPES: dict[str, SwitchbotSupportedType] = {
         "modelName": SwitchbotModel.MOTION_SENSOR,
         "modelFriendlyName": "Motion Sensor",
         "func": process_wopresence,
+        "manufacturer_id": 2409,
         "manufacturer_data_length": 10,
     },
     "r": {

+ 34 - 0
tests/test_adv_parser.py

@@ -1020,3 +1020,37 @@ def test_motion_with_light_detected():
         device=ble_device,
         rssi=-84,
     )
+
+
+def test_motion_sensor_motion_passive():
+    """Test parsing motion sensor with motion data."""
+    ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any")
+    adv_data = generate_advertisement_data(
+        manufacturer_data={2409: b"\xc0!\x9a\xe8\xbcIi\\\x008"},
+        service_data={},
+        tx_power=-127,
+        rssi=-87,
+    )
+    result = parse_advertisement_data(ble_device, adv_data)
+    assert result == SwitchBotAdvertisement(
+        address="aa:bb:cc:dd:ee:ff",
+        data={
+            "data": {
+                "battery": None,
+                "iot": None,
+                "is_light": False,
+                "led": None,
+                "light_intensity": None,
+                "motion_detected": True,
+                "sense_distance": None,
+                "tested": None,
+            },
+            "isEncrypted": False,
+            "model": "s",
+            "modelFriendlyName": "Motion Sensor",
+            "modelName": SwitchbotModel.MOTION_SENSOR,
+            "rawAdvData": None,
+        },
+        device=ble_device,
+        rssi=-87,
+    )