test_poolex_silverline_heatpump.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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_SILVERLINE_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 = "13"
  16. class TestPoolexSilverlineHeatpump(
  17. BasicBinarySensorTests,
  18. TargetTemperatureTests,
  19. TuyaDeviceTestCase,
  20. ):
  21. __test__ = True
  22. def setUp(self):
  23. self.setUpForConfig(
  24. "poolex_silverline_heatpump.yaml", POOLEX_SILVERLINE_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=(256, 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. ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE,
  44. )
  45. def test_icon(self):
  46. self.dps[HVACMODE_DPS] = True
  47. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  48. self.dps[HVACMODE_DPS] = False
  49. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  50. def test_temperature_unit_returns_device_temperature_unit(self):
  51. self.assertEqual(
  52. self.subject.temperature_unit, self.subject._device.temperature_unit
  53. )
  54. async def test_legacy_set_temperature_with_preset_mode(self):
  55. async with assert_device_properties_set(
  56. self.subject._device, {PRESET_DPS: "Cool"}
  57. ):
  58. await self.subject.async_set_temperature(preset_mode="Cool")
  59. async def test_legacy_set_temperature_with_both_properties(self):
  60. async with assert_device_properties_set(
  61. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "Heat"}
  62. ):
  63. await self.subject.async_set_temperature(temperature=26, preset_mode="Heat")
  64. def test_current_temperature(self):
  65. self.dps[CURRENTTEMP_DPS] = 25
  66. self.assertEqual(self.subject.current_temperature, 25)
  67. def test_hvac_mode(self):
  68. self.dps[HVACMODE_DPS] = True
  69. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  70. self.dps[HVACMODE_DPS] = False
  71. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  72. def test_hvac_modes(self):
  73. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  74. async def test_turn_on(self):
  75. async with assert_device_properties_set(
  76. self.subject._device, {HVACMODE_DPS: True}
  77. ):
  78. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  79. async def test_turn_off(self):
  80. async with assert_device_properties_set(
  81. self.subject._device, {HVACMODE_DPS: False}
  82. ):
  83. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  84. def test_preset_mode(self):
  85. self.dps[PRESET_DPS] = "Heat"
  86. self.assertEqual(self.subject.preset_mode, "Heat")
  87. self.dps[PRESET_DPS] = "Cool"
  88. self.assertEqual(self.subject.preset_mode, "Cool")
  89. self.dps[PRESET_DPS] = "BoostHeat"
  90. self.assertEqual(self.subject.preset_mode, "Boost Heat")
  91. self.dps[PRESET_DPS] = "SilentHeat"
  92. self.assertEqual(self.subject.preset_mode, "Silent Heat")
  93. self.dps[PRESET_DPS] = "Auto"
  94. self.assertEqual(self.subject.preset_mode, "Auto")
  95. self.dps[PRESET_DPS] = None
  96. self.assertIs(self.subject.preset_mode, None)
  97. def test_preset_modes(self):
  98. self.assertCountEqual(
  99. self.subject.preset_modes,
  100. [
  101. "Auto",
  102. "Heat",
  103. "Cool",
  104. "Boost Heat",
  105. "Silent Heat",
  106. ],
  107. )
  108. async def test_set_preset_mode_to_heat(self):
  109. async with assert_device_properties_set(
  110. self.subject._device,
  111. {PRESET_DPS: "Heat"},
  112. ):
  113. await self.subject.async_set_preset_mode("Heat")
  114. async def test_set_preset_mode_to_cool(self):
  115. async with assert_device_properties_set(
  116. self.subject._device,
  117. {PRESET_DPS: "Cool"},
  118. ):
  119. await self.subject.async_set_preset_mode("Cool")
  120. async def test_set_preset_mode_to_boostheat(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {PRESET_DPS: "BoostHeat"},
  124. ):
  125. await self.subject.async_set_preset_mode("Boost Heat")
  126. async def test_set_preset_mode_to_auto(self):
  127. async with assert_device_properties_set(
  128. self.subject._device,
  129. {PRESET_DPS: "Auto"},
  130. ):
  131. await self.subject.async_set_preset_mode("Auto")
  132. def test_error_state(self):
  133. self.dps[ERROR_DPS] = 0
  134. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  135. self.dps[ERROR_DPS] = 256
  136. self.assertEqual(
  137. self.subject.extra_state_attributes,
  138. {"error": "Water Flow Protection"},
  139. )
  140. self.dps[ERROR_DPS] = 2
  141. self.assertEqual(
  142. self.subject.extra_state_attributes,
  143. {"error": 2},
  144. )