1
0

plug.py 454 B

12345678910111213141516
  1. """Library to handle connection with Switchbot."""
  2. from __future__ import annotations
  3. def process_woplugmini(
  4. data: bytes | None, mfr_data: bytes | None
  5. ) -> dict[str, bool | int]:
  6. """Process plug mini."""
  7. if mfr_data is None:
  8. return {}
  9. return {
  10. "switchMode": True,
  11. "isOn": mfr_data[7] == 0x80,
  12. "wifi_rssi": -mfr_data[9],
  13. "power": (((mfr_data[10] << 8) + mfr_data[11]) & 0x7FFF) / 10, # W
  14. }