curtain.py 675 B

123456789101112131415161718192021
  1. """Library to handle connection with Switchbot."""
  2. from __future__ import annotations
  3. def process_wocurtain(
  4. data: bytes | None, mfr_data: bytes | None, reverse: bool = True
  5. ) -> dict[str, bool | int]:
  6. """Process woCurtain/Curtain services data."""
  7. if data is None:
  8. return {}
  9. _position = max(min(data[3] & 0b01111111, 100), 0)
  10. return {
  11. "calibration": bool(data[1] & 0b01000000),
  12. "battery": data[2] & 0b01111111,
  13. "inMotion": bool(data[3] & 0b10000000),
  14. "position": (100 - _position) if reverse else _position,
  15. "lightLevel": (data[4] >> 4) & 0b00001111,
  16. "deviceChain": data[4] & 0b00000111,
  17. }