Browse Source

Add parser tests (#66)

J. Nick Koston 1 week ago
parent
commit
96b56489e9
1 changed files with 36 additions and 0 deletions
  1. 36 0
      tests/test_adv_parser.py

+ 36 - 0
tests/test_adv_parser.py

@@ -0,0 +1,36 @@
+from switchbot.adv_parser import parse_advertisement_data
+from bleak.backends.scanner import AdvertisementData
+from bleak.backends.device import BLEDevice
+
+from switchbot.models import SwitchBotAdvertisement
+
+
+def test_parse_advertisement_data_curtain():
+    """Test parse_advertisement_data for curtain."""
+    ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any")
+    adv_data = AdvertisementData(
+        manufacturer_data={2409: b"\xe7\xabF\xac\x8f\x92|\x0f\x00\x11\x04"},
+        service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"c\xc0X\x00\x11\x04"},
+    )
+    result = parse_advertisement_data(ble_device, adv_data)
+    assert result == SwitchBotAdvertisement(
+        address="aa:bb:cc:dd:ee:ff",
+        data={
+            "address": "aa:bb:cc:dd:ee:ff",
+            "rawAdvData": b"c\xc0X\x00\x11\x04",
+            "data": {
+                "calibration": True,
+                "battery": 88,
+                "inMotion": False,
+                "position": 100,
+                "lightLevel": 1,
+                "deviceChain": 1,
+                "rssi": 0,
+            },
+            "isEncrypted": False,
+            "model": "c",
+            "model_friendly_name": "Curtain",
+            "modelName": "WoCurtain",
+        },
+        device=ble_device,
+    )