meter.py 663 B

12345678910111213141516171819202122
  1. """Meter parser."""
  2. from __future__ import annotations
  3. from typing import Any
  4. def process_wosensorth(data: bytes, mfr_data: bytes | None) -> dict[str, Any]:
  5. """Process woSensorTH/Temp sensor services data."""
  6. _temp_sign = 1 if data[4] & 0b10000000 else -1
  7. _temp_c = _temp_sign * ((data[4] & 0b01111111) + ((data[3] & 0b00001111) / 10))
  8. _temp_f = (_temp_c * 9 / 5) + 32
  9. _temp_f = (_temp_f * 10) / 10
  10. _wosensorth_data = {
  11. "temp": {"c": _temp_c, "f": _temp_f},
  12. "fahrenheit": bool(data[5] & 0b10000000),
  13. "humidity": data[5] & 0b01111111,
  14. "battery": data[2] & 0b01111111,
  15. }
  16. return _wosensorth_data