1
0

curtain.py 629 B

12345678910111213141516171819
  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. "battery": data[2] & 0b01111111,
  11. "inMotion": bool(data[3] & 0b10000000),
  12. "position": (100 - _position) if reverse else _position,
  13. "lightLevel": (data[4] >> 4) & 0b00001111,
  14. "deviceChain": data[4] & 0b00000111,
  15. }