curtain.py 1.2 KB

1234567891011121314151617181920212223242526
  1. """Library to handle connection with Switchbot."""
  2. from __future__ import annotations
  3. def process_wocurtain(
  4. data: bytes, mfr_data: bytes | None, reverse: bool = True
  5. ) -> dict[str, bool | int]:
  6. """Process woCurtain/Curtain services data."""
  7. _position = max(min(data[3] & 0b01111111, 100), 0)
  8. return {
  9. "calibration": bool(data[1] & 0b01000000),
  10. "paired": not bool(data[1] & 0b00010000),
  11. "battery": data[2] & 0b01111111,
  12. "inMotion": bool(data[3] & 0b10000000),
  13. "position": (100 - _position) if reverse else _position,
  14. "lightLevel": (data[4] >> 4) & 0b00001111,
  15. "deviceChain": data[4] & 0b00000111,
  16. }
  17. # Paired Curtain
  18. # AdvertisementData(local_name='WoCurtain', manufacturer_data={89: b'\xd1K3\x1f\n\xfd'}, service_data={'00000d00-0000-1000-8000-00805f9b34fb': b'c@X\x00!\x04'}, service_uuids=['cba20d00-224d-11e6-9fb8-0002a5d5c51b']) connectable: True match: {'switchbot'} rssi: -40
  19. # Unpaired Curtain
  20. # AdvertisementData(local_name='WoCurtain', manufacturer_data={89: b'\xd1K3\x1f\n\xfd'}, service_data={'00000d00-0000-1000-8000-00805f9b34fb': b'c\xd0X\x00!\x04'}, service_uuids=['cba20d00-224d-11e6-9fb8-0002a5d5c51b']) connectable: True match: {'switchbot'} rssi: -40