meter.py 607 B

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