test_poolex_silverline_heatpump.py 6.0 KB

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