test_poolex_vertigo_heatpump.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.climate.const import (
  3. ClimateEntityFeature,
  4. HVACMode,
  5. )
  6. from ..const import POOLEX_VERTIGO_HEATPUMP_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.binary_sensor import BasicBinarySensorTests
  9. from ..mixins.climate import TargetTemperatureTests
  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(
  17. BasicBinarySensorTests,
  18. TargetTemperatureTests,
  19. TuyaDeviceTestCase,
  20. ):
  21. __test__ = True
  22. def setUp(self):
  23. self.setUpForConfig(
  24. "poolex_vertigo_heatpump.yaml", POOLEX_VERTIGO_HEATPUMP_PAYLOAD
  25. )
  26. self.subject = self.entities.get("climate")
  27. self.setUpTargetTemperature(
  28. TEMPERATURE_DPS,
  29. self.subject,
  30. min=8,
  31. max=40,
  32. )
  33. self.setUpBasicBinarySensor(
  34. ERROR_DPS,
  35. self.entities.get("binary_sensor_water_flow"),
  36. device_class=BinarySensorDeviceClass.PROBLEM,
  37. testdata=(4, 0),
  38. )
  39. self.mark_secondary(["binary_sensor_water_flow"])
  40. def test_supported_features(self):
  41. self.assertEqual(
  42. self.subject.supported_features,
  43. (
  44. ClimateEntityFeature.TARGET_TEMPERATURE
  45. | ClimateEntityFeature.PRESET_MODE
  46. ),
  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, HVACMode.HEAT)
  73. self.dps[HVACMODE_DPS] = False
  74. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  75. def test_hvac_modes(self):
  76. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  77. async def test_turn_on(self):
  78. async with assert_device_properties_set(
  79. self.subject._device, {HVACMODE_DPS: True}
  80. ):
  81. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  82. async def test_turn_off(self):
  83. async with assert_device_properties_set(
  84. self.subject._device, {HVACMODE_DPS: False}
  85. ):
  86. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  87. def test_preset_mode(self):
  88. self.dps[PRESET_DPS] = "heat"
  89. self.assertEqual(self.subject.preset_mode, "Heat")
  90. self.dps[PRESET_DPS] = "cool"
  91. self.assertEqual(self.subject.preset_mode, "Cool")
  92. self.dps[PRESET_DPS] = "silent"
  93. self.assertEqual(self.subject.preset_mode, "Silent")
  94. self.dps[PRESET_DPS] = None
  95. self.assertIs(self.subject.preset_mode, None)
  96. def test_preset_modes(self):
  97. self.assertCountEqual(
  98. self.subject.preset_modes,
  99. [
  100. "Heat",
  101. "Cool",
  102. "Silent",
  103. ],
  104. )
  105. async def test_set_preset_mode_to_heat(self):
  106. async with assert_device_properties_set(
  107. self.subject._device,
  108. {PRESET_DPS: "heat"},
  109. ):
  110. await self.subject.async_set_preset_mode("Heat")
  111. async def test_set_preset_mode_to_cool(self):
  112. async with assert_device_properties_set(
  113. self.subject._device,
  114. {PRESET_DPS: "cool"},
  115. ):
  116. await self.subject.async_set_preset_mode("Cool")
  117. async def test_set_preset_mode_to_silent(self):
  118. async with assert_device_properties_set(
  119. self.subject._device,
  120. {PRESET_DPS: "silent"},
  121. ):
  122. await self.subject.async_set_preset_mode("Silent")
  123. def test_error_state(self):
  124. self.dps[ERROR_DPS] = 0
  125. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  126. self.dps[ERROR_DPS] = 4
  127. self.assertEqual(
  128. self.subject.extra_state_attributes,
  129. {"error": "Water Flow Protection"},
  130. )
  131. self.dps[ERROR_DPS] = 2
  132. self.assertEqual(
  133. self.subject.extra_state_attributes,
  134. {"error": 2},
  135. )