test_poolex_silverline_heatpump.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_SILVERLINE_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 = "13"
  19. class TestPoolexSilverlineHeatpump(
  20. BasicBinarySensorTests,
  21. TargetTemperatureTests,
  22. TuyaDeviceTestCase,
  23. ):
  24. __test__ = True
  25. def setUp(self):
  26. self.setUpForConfig(
  27. "poolex_silverline_heatpump.yaml", POOLEX_SILVERLINE_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=(256, 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] = "BoostHeat"
  94. self.assertEqual(self.subject.preset_mode, "BoostHeat")
  95. self.dps[PRESET_DPS] = "Auto"
  96. self.assertEqual(self.subject.preset_mode, "Auto")
  97. self.dps[PRESET_DPS] = None
  98. self.assertIs(self.subject.preset_mode, None)
  99. def test_preset_modes(self):
  100. self.assertCountEqual(
  101. self.subject.preset_modes,
  102. [
  103. "Auto",
  104. "Heat",
  105. "Cool",
  106. "BoostHeat",
  107. ],
  108. )
  109. async def test_set_preset_mode_to_heat(self):
  110. async with assert_device_properties_set(
  111. self.subject._device,
  112. {PRESET_DPS: "Heat"},
  113. ):
  114. await self.subject.async_set_preset_mode("Heat")
  115. async def test_set_preset_mode_to_cool(self):
  116. async with assert_device_properties_set(
  117. self.subject._device,
  118. {PRESET_DPS: "Cool"},
  119. ):
  120. await self.subject.async_set_preset_mode("Cool")
  121. async def test_set_preset_mode_to_boostheat(self):
  122. async with assert_device_properties_set(
  123. self.subject._device,
  124. {PRESET_DPS: "BoostHeat"},
  125. ):
  126. await self.subject.async_set_preset_mode("BoostHeat")
  127. async def test_set_preset_mode_to_auto(self):
  128. async with assert_device_properties_set(
  129. self.subject._device,
  130. {PRESET_DPS: "Auto"},
  131. ):
  132. await self.subject.async_set_preset_mode("Auto")
  133. def test_error_state(self):
  134. self.dps[ERROR_DPS] = 0
  135. self.assertEqual(self.subject.device_state_attributes, {"error": "OK"})
  136. self.dps[ERROR_DPS] = 256
  137. self.assertEqual(
  138. self.subject.device_state_attributes,
  139. {"error": "Water Flow Protection"},
  140. )
  141. self.dps[ERROR_DPS] = 2
  142. self.assertEqual(
  143. self.subject.device_state_attributes,
  144. {"error": 2},
  145. )