1
0

bulb.py 609 B

1234567891011121314151617
  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. assert mfr_data is not None
  6. return {
  7. "sequence_number": mfr_data[6],
  8. "isOn": bool(mfr_data[7] & 0b10000000),
  9. "brightness": mfr_data[7] & 0b01111111,
  10. "delay": bool(mfr_data[8] & 0b10000000),
  11. "preset": bool(mfr_data[8] & 0b00001000),
  12. "light_state": mfr_data[8] & 0b00000111,
  13. "speed": mfr_data[9] & 0b01111111,
  14. "loop_index": mfr_data[10] & 0b11111110,
  15. }