meter.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. temp_data = None
  7. battery = None
  8. if mfr_data:
  9. temp_data = mfr_data[8:11]
  10. if data:
  11. if not temp_data:
  12. temp_data = data[3:6]
  13. battery = data[2] & 0b01111111
  14. if not temp_data:
  15. return {}
  16. _temp_sign = 1 if temp_data[1] & 0b10000000 else -1
  17. _temp_c = _temp_sign * (
  18. (temp_data[1] & 0b01111111) + ((temp_data[0] & 0b00001111) / 10)
  19. )
  20. _temp_f = (_temp_c * 9 / 5) + 32
  21. _temp_f = (_temp_f * 10) / 10
  22. _wosensorth_data = {
  23. # Data should be flat, but we keep the original structure for now
  24. "temp": {"c": _temp_c, "f": _temp_f},
  25. "temperature": _temp_c,
  26. "fahrenheit": bool(temp_data[2] & 0b10000000),
  27. "humidity": temp_data[2] & 0b01111111,
  28. "battery": battery,
  29. }
  30. return _wosensorth_data