test_poolex_vertigo_heatpump.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. from homeassistant.components.binary_sensor import DEVICE_CLASS_PROBLEM
  2. from homeassistant.components.climate.const import (
  3. HVAC_MODE_HEAT,
  4. HVAC_MODE_OFF,
  5. SUPPORT_PRESET_MODE,
  6. SUPPORT_TARGET_TEMPERATURE,
  7. )
  8. from homeassistant.const import STATE_UNAVAILABLE
  9. from ..const import POOLEX_VERTIGO_HEATPUMP_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from ..mixins.binary_sensor import BasicBinarySensorTests
  12. from ..mixins.climate import TargetTemperatureTests
  13. from .base_device_tests import TuyaDeviceTestCase
  14. HVACMODE_DPS = "1"
  15. TEMPERATURE_DPS = "2"
  16. CURRENTTEMP_DPS = "3"
  17. PRESET_DPS = "4"
  18. ERROR_DPS = "9"
  19. class TestPoolexVertigoHeatpump(
  20. BasicBinarySensorTests,
  21. TargetTemperatureTests,
  22. TuyaDeviceTestCase,
  23. ):
  24. __test__ = True
  25. def setUp(self):
  26. self.setUpForConfig(
  27. "poolex_vertigo_heatpump.yaml", POOLEX_VERTIGO_HEATPUMP_PAYLOAD
  28. )
  29. self.subject = self.entities.get("climate")
  30. self.setUpTargetTemperature(
  31. TEMPERATURE_DPS,
  32. self.subject,
  33. min=8,
  34. max=40,
  35. )
  36. self.setUpBasicBinarySensor(
  37. ERROR_DPS,
  38. self.entities.get("binary_sensor_water_flow"),
  39. device_class=DEVICE_CLASS_PROBLEM,
  40. testdata=(4, 0),
  41. )
  42. def test_supported_features(self):
  43. self.assertEqual(
  44. self.subject.supported_features,
  45. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  46. )
  47. def test_icon(self):
  48. self.dps[HVACMODE_DPS] = True
  49. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  50. self.dps[HVACMODE_DPS] = False
  51. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  52. def test_temperature_unit_returns_device_temperature_unit(self):
  53. self.assertEqual(
  54. self.subject.temperature_unit, self.subject._device.temperature_unit
  55. )
  56. async def test_legacy_set_temperature_with_preset_mode(self):
  57. async with assert_device_properties_set(
  58. self.subject._device, {PRESET_DPS: "cool"}
  59. ):
  60. await self.subject.async_set_temperature(preset_mode="Cool")
  61. async def test_legacy_set_temperature_with_both_properties(self):
  62. async with assert_device_properties_set(
  63. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "heat"}
  64. ):
  65. await self.subject.async_set_temperature(temperature=26, preset_mode="Heat")
  66. def test_current_temperature(self):
  67. self.dps[CURRENTTEMP_DPS] = 25
  68. self.assertEqual(self.subject.current_temperature, 25)
  69. def test_hvac_mode(self):
  70. self.dps[HVACMODE_DPS] = True
  71. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  72. self.dps[HVACMODE_DPS] = False
  73. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  74. self.dps[HVACMODE_DPS] = None
  75. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  76. def test_hvac_modes(self):
  77. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  78. async def test_turn_on(self):
  79. async with assert_device_properties_set(
  80. self.subject._device, {HVACMODE_DPS: True}
  81. ):
  82. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  83. async def test_turn_off(self):
  84. async with assert_device_properties_set(
  85. self.subject._device, {HVACMODE_DPS: False}
  86. ):
  87. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  88. def test_preset_mode(self):
  89. self.dps[PRESET_DPS] = "heat"
  90. self.assertEqual(self.subject.preset_mode, "Heat")
  91. self.dps[PRESET_DPS] = "cool"
  92. self.assertEqual(self.subject.preset_mode, "Cool")
  93. self.dps[PRESET_DPS] = "silent"
  94. self.assertEqual(self.subject.preset_mode, "Silent")
  95. self.dps[PRESET_DPS] = None
  96. self.assertIs(self.subject.preset_mode, None)
  97. def test_preset_modes(self):
  98. self.assertCountEqual(
  99. self.subject.preset_modes,
  100. [
  101. "Heat",
  102. "Cool",
  103. "Silent",
  104. ],
  105. )
  106. async def test_set_preset_mode_to_heat(self):
  107. async with assert_device_properties_set(
  108. self.subject._device,
  109. {PRESET_DPS: "heat"},
  110. ):
  111. await self.subject.async_set_preset_mode("Heat")
  112. async def test_set_preset_mode_to_cool(self):
  113. async with assert_device_properties_set(
  114. self.subject._device,
  115. {PRESET_DPS: "cool"},
  116. ):
  117. await self.subject.async_set_preset_mode("Cool")
  118. async def test_set_preset_mode_to_silent(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {PRESET_DPS: "silent"},
  122. ):
  123. await self.subject.async_set_preset_mode("Silent")
  124. def test_error_state(self):
  125. self.dps[ERROR_DPS] = 0
  126. self.assertEqual(self.subject.device_state_attributes, {"error": "OK"})
  127. self.dps[ERROR_DPS] = 4
  128. self.assertEqual(
  129. self.subject.device_state_attributes,
  130. {"error": "Water Flow Protection"},
  131. )
  132. self.dps[ERROR_DPS] = 2
  133. self.assertEqual(
  134. self.subject.device_state_attributes,
  135. {"error": 2},
  136. )