hubmini_matter.py 933 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. """Hubmini matter parser."""
  2. from __future__ import annotations
  3. from typing import Any
  4. from ..helpers import celsius_to_fahrenheit
  5. def process_hubmini_matter(
  6. data: bytes | None, mfr_data: bytes | None
  7. ) -> dict[str, Any]:
  8. """Process Hubmini matter sensor manufacturer data."""
  9. temp_data = None
  10. if mfr_data:
  11. temp_data = mfr_data[13:16]
  12. if not temp_data:
  13. return {}
  14. _temp_sign = 1 if temp_data[1] & 0b10000000 else -1
  15. _temp_c = _temp_sign * (
  16. (temp_data[1] & 0b01111111) + ((temp_data[0] & 0b00001111) / 10)
  17. )
  18. _temp_f = celsius_to_fahrenheit(_temp_c)
  19. _temp_f = (_temp_f * 10) / 10
  20. humidity = temp_data[2] & 0b01111111
  21. if _temp_c == 0 and humidity == 0:
  22. return {}
  23. return {
  24. "temp": {"c": _temp_c, "f": _temp_f},
  25. "temperature": _temp_c,
  26. "fahrenheit": bool(temp_data[2] & 0b10000000),
  27. "humidity": humidity,
  28. }