test_poolex_vertigo_heatpump.py 6.6 KB

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