1
0

meter.py 1001 B

123456789101112131415161718192021222324252627282930313233343536
  1. """Meter parser."""
  2. from __future__ import annotations
  3. from typing import Any
  4. def process_wosensorth(data: bytes | None, mfr_data: bytes | None) -> dict[str, Any]:
  5. """Process woSensorTH/Temp sensor services data."""
  6. if mfr_data:
  7. temp_data = mfr_data[8:11]
  8. battery = None
  9. if data:
  10. temp_data = data[3:6]
  11. battery = data[2] & 0b01111111
  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 = (_temp_c * 9 / 5) + 32
  19. _temp_f = (_temp_f * 10) / 10
  20. _wosensorth_data = {
  21. # Data should be flat, but we keep the original structure for now
  22. "temp": {"c": _temp_c, "f": _temp_f},
  23. "temperature": _temp_c,
  24. "fahrenheit": bool(temp_data[2] & 0b10000000),
  25. "humidity": temp_data[2] & 0b01111111,
  26. "battery": battery,
  27. }
  28. return _wosensorth_data