test_poolex_vertigo_heatpump.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  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=BinarySensorDeviceClass.PROBLEM,
  40. testdata=(4, 0),
  41. )
  42. self.mark_secondary(["binary_sensor_water_flow"])
  43. def test_supported_features(self):
  44. self.assertEqual(
  45. self.subject.supported_features,
  46. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  47. )
  48. def test_icon(self):
  49. self.dps[HVACMODE_DPS] = True
  50. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  51. self.dps[HVACMODE_DPS] = False
  52. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  53. def test_temperature_unit_returns_device_temperature_unit(self):
  54. self.assertEqual(
  55. self.subject.temperature_unit, self.subject._device.temperature_unit
  56. )
  57. async def test_legacy_set_temperature_with_preset_mode(self):
  58. async with assert_device_properties_set(
  59. self.subject._device, {PRESET_DPS: "cool"}
  60. ):
  61. await self.subject.async_set_temperature(preset_mode="Cool")
  62. async def test_legacy_set_temperature_with_both_properties(self):
  63. async with assert_device_properties_set(
  64. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "heat"}
  65. ):
  66. await self.subject.async_set_temperature(temperature=26, preset_mode="Heat")
  67. def test_current_temperature(self):
  68. self.dps[CURRENTTEMP_DPS] = 25
  69. self.assertEqual(self.subject.current_temperature, 25)
  70. def test_hvac_mode(self):
  71. self.dps[HVACMODE_DPS] = True
  72. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  73. self.dps[HVACMODE_DPS] = False
  74. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  75. self.dps[HVACMODE_DPS] = None
  76. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  77. def test_hvac_modes(self):
  78. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  79. async def test_turn_on(self):
  80. async with assert_device_properties_set(
  81. self.subject._device, {HVACMODE_DPS: True}
  82. ):
  83. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  84. async def test_turn_off(self):
  85. async with assert_device_properties_set(
  86. self.subject._device, {HVACMODE_DPS: False}
  87. ):
  88. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  89. def test_preset_mode(self):
  90. self.dps[PRESET_DPS] = "heat"
  91. self.assertEqual(self.subject.preset_mode, "Heat")
  92. self.dps[PRESET_DPS] = "cool"
  93. self.assertEqual(self.subject.preset_mode, "Cool")
  94. self.dps[PRESET_DPS] = "silent"
  95. self.assertEqual(self.subject.preset_mode, "Silent")
  96. self.dps[PRESET_DPS] = None
  97. self.assertIs(self.subject.preset_mode, None)
  98. def test_preset_modes(self):
  99. self.assertCountEqual(
  100. self.subject.preset_modes,
  101. [
  102. "Heat",
  103. "Cool",
  104. "Silent",
  105. ],
  106. )
  107. async def test_set_preset_mode_to_heat(self):
  108. async with assert_device_properties_set(
  109. self.subject._device,
  110. {PRESET_DPS: "heat"},
  111. ):
  112. await self.subject.async_set_preset_mode("Heat")
  113. async def test_set_preset_mode_to_cool(self):
  114. async with assert_device_properties_set(
  115. self.subject._device,
  116. {PRESET_DPS: "cool"},
  117. ):
  118. await self.subject.async_set_preset_mode("Cool")
  119. async def test_set_preset_mode_to_silent(self):
  120. async with assert_device_properties_set(
  121. self.subject._device,
  122. {PRESET_DPS: "silent"},
  123. ):
  124. await self.subject.async_set_preset_mode("Silent")
  125. def test_error_state(self):
  126. self.dps[ERROR_DPS] = 0
  127. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  128. self.dps[ERROR_DPS] = 4
  129. self.assertEqual(
  130. self.subject.extra_state_attributes,
  131. {"error": "Water Flow Protection"},
  132. )
  133. self.dps[ERROR_DPS] = 2
  134. self.assertEqual(
  135. self.subject.extra_state_attributes,
  136. {"error": 2},
  137. )