humidifier.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. """Humidifier adv parser."""
  2. from __future__ import annotations
  3. import logging
  4. from datetime import timedelta
  5. from ..const.evaporative_humidifier import (
  6. OVER_HUMIDIFY_PROTECTION_MODES,
  7. TARGET_HUMIDITY_MODES,
  8. HumidifierMode,
  9. HumidifierWaterLevel,
  10. )
  11. _LOGGER = logging.getLogger(__name__)
  12. # mfr_data: 943cc68d3d2e
  13. # data: 650000cd802b6300
  14. # data: 650000cd802b6300
  15. # data: 658000c9802b6300
  16. # Low: 658000c5222b6300
  17. # Med: 658000c5432b6300
  18. # High: 658000c5642b6300
  19. def process_wohumidifier(
  20. data: bytes | None, mfr_data: bytes | None
  21. ) -> dict[str, bool | int]:
  22. """Process WoHumi services data."""
  23. if data is None:
  24. return {
  25. "isOn": None,
  26. "level": None,
  27. "switchMode": True,
  28. }
  29. return {
  30. "isOn": bool(data[1]),
  31. "level": data[4],
  32. "switchMode": True,
  33. }
  34. def process_evaporative_humidifier(
  35. data: bytes | None, mfr_data: bytes | None
  36. ) -> dict[str, bool | int]:
  37. """Process WoHumi services data."""
  38. if mfr_data is None:
  39. return {
  40. "isOn": None,
  41. "mode": None,
  42. "target_humidity": None,
  43. "child_lock": None,
  44. "over_humidify_protection": None,
  45. "tank_removed": None,
  46. "tilted_alert": None,
  47. "filter_missing": None,
  48. "humidity": None,
  49. "temperature": None,
  50. "filter_run_time": None,
  51. "filter_alert": None,
  52. "water_level": None,
  53. }
  54. is_on = bool(mfr_data[7] & 0b10000000)
  55. mode = HumidifierMode(mfr_data[7] & 0b00001111)
  56. filter_run_time = timedelta(hours=int.from_bytes(mfr_data[12:14], byteorder="big"))
  57. has_humidity = bool(mfr_data[9] & 0b10000000)
  58. has_temperature = bool(mfr_data[10] & 0b10000000)
  59. is_tank_removed = bool(mfr_data[8] & 0b00000100)
  60. return {
  61. "isOn": is_on,
  62. "mode": mode if is_on else None,
  63. "target_humidity": (mfr_data[16] & 0b01111111)
  64. if is_on and mode in TARGET_HUMIDITY_MODES
  65. else None,
  66. "child_lock": bool(mfr_data[8] & 0b00100000),
  67. "over_humidify_protection": bool(mfr_data[8] & 0b10000000)
  68. if is_on and mode in OVER_HUMIDIFY_PROTECTION_MODES
  69. else None,
  70. "tank_removed": is_tank_removed,
  71. "tilted_alert": bool(mfr_data[8] & 0b00000010),
  72. "filter_missing": bool(mfr_data[8] & 0b00000001),
  73. "humidity": (mfr_data[9] & 0b01111111) if has_humidity else None,
  74. "temperature": float(mfr_data[10] & 0b01111111) + float(mfr_data[11] >> 4) / 10
  75. if has_temperature
  76. else None,
  77. "filter_run_time": filter_run_time,
  78. "filter_alert": filter_run_time.days >= 10,
  79. "water_level": HumidifierWaterLevel(mfr_data[11] & 0b00000011)
  80. if not is_tank_removed
  81. else None,
  82. }