climate_panel.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """Advertisement data parser for climate panel devices."""
  2. import logging
  3. _LOGGER = logging.getLogger(__name__)
  4. def process_climate_panel(
  5. data: bytes | None, mfr_data: bytes | None
  6. ) -> dict[str, bool | int | str]:
  7. """Process Climate Panel data."""
  8. if mfr_data is None:
  9. return {}
  10. seq_number = mfr_data[6]
  11. isOn = bool(mfr_data[7] & 0x80)
  12. battery = mfr_data[7] & 0x7F
  13. humidity_alarm = (mfr_data[8] >> 6) & 0x03
  14. temp_alarm = (mfr_data[8] >> 4) & 0x03
  15. temp_decimal = mfr_data[8] & 0x0F
  16. temp_sign = 1 if (mfr_data[9] & 0x80) else -1
  17. temp_int = mfr_data[9] & 0x7F
  18. temperature = temp_sign * (temp_int + temp_decimal / 10)
  19. humidity = mfr_data[10] & 0x7F
  20. pir_state = bool(mfr_data[15] & 0x80)
  21. is_light = ((mfr_data[15] >> 2) & 0x03) == 0x10
  22. result = {
  23. "sequence_number": seq_number,
  24. "isOn": isOn,
  25. "battery": battery,
  26. "temperature": temperature,
  27. "humidity": humidity,
  28. "temp_alarm": temp_alarm,
  29. "humidity_alarm": humidity_alarm,
  30. "motion_detected": pir_state,
  31. "is_light": is_light,
  32. }
  33. _LOGGER.debug(
  34. "Processed climate panel mfr data: %s, result: %s", mfr_data.hex(), result
  35. )
  36. return result