test_poolex_silverline_heatpump.py 5.8 KB

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