1
0

test_adv_parser.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from switchbot.adv_parser import parse_advertisement_data
  2. from bleak.backends.scanner import AdvertisementData
  3. from bleak.backends.device import BLEDevice
  4. from switchbot.models import SwitchBotAdvertisement
  5. def test_parse_advertisement_data_curtain():
  6. """Test parse_advertisement_data for curtain."""
  7. ble_device = BLEDevice("aa:bb:cc:dd:ee:ff", "any")
  8. adv_data = AdvertisementData(
  9. manufacturer_data={2409: b"\xe7\xabF\xac\x8f\x92|\x0f\x00\x11\x04"},
  10. service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"c\xc0X\x00\x11\x04"},
  11. )
  12. result = parse_advertisement_data(ble_device, adv_data)
  13. assert result == SwitchBotAdvertisement(
  14. address="aa:bb:cc:dd:ee:ff",
  15. data={
  16. "address": "aa:bb:cc:dd:ee:ff",
  17. "rawAdvData": b"c\xc0X\x00\x11\x04",
  18. "data": {
  19. "calibration": True,
  20. "battery": 88,
  21. "inMotion": False,
  22. "position": 100,
  23. "lightLevel": 1,
  24. "deviceChain": 1,
  25. "rssi": 0,
  26. },
  27. "isEncrypted": False,
  28. "model": "c",
  29. "model_friendly_name": "Curtain",
  30. "modelName": "WoCurtain",
  31. },
  32. device=ble_device,
  33. )