meter.py 709 B

123456789101112131415161718192021222324
  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 data is None:
  7. return {}
  8. _temp_sign = 1 if data[4] & 0b10000000 else -1
  9. _temp_c = _temp_sign * ((data[4] & 0b01111111) + ((data[3] & 0b00001111) / 10))
  10. _temp_f = (_temp_c * 9 / 5) + 32
  11. _temp_f = (_temp_f * 10) / 10
  12. _wosensorth_data = {
  13. "temp": {"c": _temp_c, "f": _temp_f},
  14. "fahrenheit": bool(data[5] & 0b10000000),
  15. "humidity": data[5] & 0b01111111,
  16. "battery": data[2] & 0b01111111,
  17. }
  18. return _wosensorth_data