meter.py 895 B

12345678910111213141516171819202122232425262728293031323334
  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. "temp": {"c": _temp_c, "f": _temp_f},
  22. "fahrenheit": bool(temp_data[2] & 0b10000000),
  23. "humidity": temp_data[2] & 0b01111111,
  24. "battery": battery,
  25. }
  26. return _wosensorth_data