1
0

meter.py 642 B

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