1
0

bot.py 636 B

1234567891011121314151617181920212223
  1. """Library to handle connection with Switchbot."""
  2. from __future__ import annotations
  3. def process_wohand(data: bytes | None, mfr_data: bytes | None) -> dict[str, bool | int]:
  4. """Process woHand/Bot services data."""
  5. if data is None and mfr_data is None:
  6. return {}
  7. if data is None:
  8. return {
  9. "switchMode": None,
  10. "isOn": None,
  11. "battery": None,
  12. }
  13. _switch_mode = bool(data[1] & 0b10000000)
  14. return {
  15. "switchMode": _switch_mode,
  16. "isOn": not bool(data[1] & 0b01000000) if _switch_mode else False,
  17. "battery": data[2] & 0b01111111,
  18. }