bulb.py 619 B

123456789101112131415161718
  1. """Bulb parser."""
  2. from __future__ import annotations
  3. def process_color_bulb(data: bytes, mfr_data: bytes | None) -> dict[str, bool | int]:
  4. """Process WoBulb services data."""
  5. if mfr_data is None:
  6. return {}
  7. return {
  8. "sequence_number": mfr_data[6],
  9. "isOn": bool(mfr_data[7] & 0b10000000),
  10. "brightness": mfr_data[7] & 0b01111111,
  11. "delay": bool(mfr_data[8] & 0b10000000),
  12. "preset": bool(mfr_data[8] & 0b00001000),
  13. "color_mode": mfr_data[8] & 0b00000111,
  14. "speed": mfr_data[9] & 0b01111111,
  15. "loop_index": mfr_data[10] & 0b11111110,
  16. }