test_poolex_vertigo_heatpump.py 5.3 KB

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