test_poolex_silverline_heatpump.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_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=BinarySensorDeviceClass.PROBLEM,
  40. testdata=(256, 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] = "BoostHeat"
  95. self.assertEqual(self.subject.preset_mode, "BoostHeat")
  96. self.dps[PRESET_DPS] = "Auto"
  97. self.assertEqual(self.subject.preset_mode, "Auto")
  98. self.dps[PRESET_DPS] = None
  99. self.assertIs(self.subject.preset_mode, None)
  100. def test_preset_modes(self):
  101. self.assertCountEqual(
  102. self.subject.preset_modes,
  103. [
  104. "Auto",
  105. "Heat",
  106. "Cool",
  107. "BoostHeat",
  108. ],
  109. )
  110. async def test_set_preset_mode_to_heat(self):
  111. async with assert_device_properties_set(
  112. self.subject._device,
  113. {PRESET_DPS: "Heat"},
  114. ):
  115. await self.subject.async_set_preset_mode("Heat")
  116. async def test_set_preset_mode_to_cool(self):
  117. async with assert_device_properties_set(
  118. self.subject._device,
  119. {PRESET_DPS: "Cool"},
  120. ):
  121. await self.subject.async_set_preset_mode("Cool")
  122. async def test_set_preset_mode_to_boostheat(self):
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {PRESET_DPS: "BoostHeat"},
  126. ):
  127. await self.subject.async_set_preset_mode("BoostHeat")
  128. async def test_set_preset_mode_to_auto(self):
  129. async with assert_device_properties_set(
  130. self.subject._device,
  131. {PRESET_DPS: "Auto"},
  132. ):
  133. await self.subject.async_set_preset_mode("Auto")
  134. def test_error_state(self):
  135. self.dps[ERROR_DPS] = 0
  136. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  137. self.dps[ERROR_DPS] = 256
  138. self.assertEqual(
  139. self.subject.extra_state_attributes,
  140. {"error": "Water Flow Protection"},
  141. )
  142. self.dps[ERROR_DPS] = 2
  143. self.assertEqual(
  144. self.subject.extra_state_attributes,
  145. {"error": 2},
  146. )