4
0

test_poolex_silverline_heatpump.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 .base_device_tests import TuyaDeviceTestCase
  13. HVACMODE_DPS = "1"
  14. TEMPERATURE_DPS = "2"
  15. CURRENTTEMP_DPS = "3"
  16. PRESET_DPS = "4"
  17. ERROR_DPS = "13"
  18. class TestPoolexSilverlineHeatpump(BasicBinarySensorTests, TuyaDeviceTestCase):
  19. __test__ = True
  20. def setUp(self):
  21. self.setUpForConfig(
  22. "poolex_silverline_heatpump.yaml", POOLEX_SILVERLINE_HEATPUMP_PAYLOAD
  23. )
  24. self.subject = self.entities.get("climate")
  25. self.setUpBasicBinarySensor(
  26. ERROR_DPS,
  27. self.entities.get("binary_sensor_water_flow"),
  28. device_class=DEVICE_CLASS_PROBLEM,
  29. testdata=(256, 0),
  30. )
  31. def test_supported_features(self):
  32. self.assertEqual(
  33. self.subject.supported_features,
  34. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  35. )
  36. def test_icon(self):
  37. self.dps[HVACMODE_DPS] = True
  38. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  39. self.dps[HVACMODE_DPS] = False
  40. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  41. def test_temperature_unit_returns_device_temperature_unit(self):
  42. self.assertEqual(
  43. self.subject.temperature_unit, self.subject._device.temperature_unit
  44. )
  45. def test_target_temperature(self):
  46. self.dps[TEMPERATURE_DPS] = 25
  47. self.assertEqual(self.subject.target_temperature, 25)
  48. def test_target_temperature_step(self):
  49. self.assertEqual(self.subject.target_temperature_step, 1)
  50. def test_minimum_target_temperature(self):
  51. self.assertEqual(self.subject.min_temp, 8)
  52. def test_maximum_target_temperature(self):
  53. self.assertEqual(self.subject.max_temp, 40)
  54. async def test_legacy_set_temperature_with_temperature(self):
  55. async with assert_device_properties_set(
  56. self.subject._device, {TEMPERATURE_DPS: 24}
  57. ):
  58. await self.subject.async_set_temperature(temperature=24)
  59. async def test_legacy_set_temperature_with_preset_mode(self):
  60. async with assert_device_properties_set(
  61. self.subject._device, {PRESET_DPS: "Cool"}
  62. ):
  63. await self.subject.async_set_temperature(preset_mode="Cool")
  64. async def test_legacy_set_temperature_with_both_properties(self):
  65. async with assert_device_properties_set(
  66. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "Heat"}
  67. ):
  68. await self.subject.async_set_temperature(temperature=26, preset_mode="Heat")
  69. async def test_legacy_set_temperature_with_no_valid_properties(self):
  70. await self.subject.async_set_temperature(something="else")
  71. self.subject._device.async_set_property.assert_not_called()
  72. async def test_set_target_temperature_succeeds_within_valid_range(self):
  73. async with assert_device_properties_set(
  74. self.subject._device,
  75. {TEMPERATURE_DPS: 25},
  76. ):
  77. await self.subject.async_set_target_temperature(25)
  78. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  79. async with assert_device_properties_set(
  80. self.subject._device, {TEMPERATURE_DPS: 23}
  81. ):
  82. await self.subject.async_set_target_temperature(22.6)
  83. async def test_set_target_temperature_fails_outside_valid_range(self):
  84. with self.assertRaisesRegex(
  85. ValueError, "temperature \\(7\\) must be between 8 and 40"
  86. ):
  87. await self.subject.async_set_target_temperature(7)
  88. with self.assertRaisesRegex(
  89. ValueError, "temperature \\(41\\) must be between 8 and 40"
  90. ):
  91. await self.subject.async_set_target_temperature(41)
  92. def test_current_temperature(self):
  93. self.dps[CURRENTTEMP_DPS] = 25
  94. self.assertEqual(self.subject.current_temperature, 25)
  95. def test_hvac_mode(self):
  96. self.dps[HVACMODE_DPS] = True
  97. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  98. self.dps[HVACMODE_DPS] = False
  99. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  100. self.dps[HVACMODE_DPS] = None
  101. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  102. def test_hvac_modes(self):
  103. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  104. async def test_turn_on(self):
  105. async with assert_device_properties_set(
  106. self.subject._device, {HVACMODE_DPS: True}
  107. ):
  108. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  109. async def test_turn_off(self):
  110. async with assert_device_properties_set(
  111. self.subject._device, {HVACMODE_DPS: False}
  112. ):
  113. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  114. def test_preset_mode(self):
  115. self.dps[PRESET_DPS] = "Heat"
  116. self.assertEqual(self.subject.preset_mode, "Heat")
  117. self.dps[PRESET_DPS] = "Cool"
  118. self.assertEqual(self.subject.preset_mode, "Cool")
  119. self.dps[PRESET_DPS] = "BoostHeat"
  120. self.assertEqual(self.subject.preset_mode, "BoostHeat")
  121. self.dps[PRESET_DPS] = "Auto"
  122. self.assertEqual(self.subject.preset_mode, "Auto")
  123. self.dps[PRESET_DPS] = None
  124. self.assertIs(self.subject.preset_mode, None)
  125. def test_preset_modes(self):
  126. self.assertCountEqual(
  127. self.subject.preset_modes,
  128. [
  129. "Auto",
  130. "Heat",
  131. "Cool",
  132. "BoostHeat",
  133. ],
  134. )
  135. async def test_set_preset_mode_to_heat(self):
  136. async with assert_device_properties_set(
  137. self.subject._device,
  138. {PRESET_DPS: "Heat"},
  139. ):
  140. await self.subject.async_set_preset_mode("Heat")
  141. async def test_set_preset_mode_to_cool(self):
  142. async with assert_device_properties_set(
  143. self.subject._device,
  144. {PRESET_DPS: "Cool"},
  145. ):
  146. await self.subject.async_set_preset_mode("Cool")
  147. async def test_set_preset_mode_to_boostheat(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {PRESET_DPS: "BoostHeat"},
  151. ):
  152. await self.subject.async_set_preset_mode("BoostHeat")
  153. async def test_set_preset_mode_to_auto(self):
  154. async with assert_device_properties_set(
  155. self.subject._device,
  156. {PRESET_DPS: "Auto"},
  157. ):
  158. await self.subject.async_set_preset_mode("Auto")
  159. def test_error_state(self):
  160. self.dps[ERROR_DPS] = 0
  161. self.assertEqual(self.subject.device_state_attributes, {"error": "OK"})
  162. self.dps[ERROR_DPS] = 256
  163. self.assertEqual(
  164. self.subject.device_state_attributes,
  165. {"error": "Water Flow Protection"},
  166. )
  167. self.dps[ERROR_DPS] = 2
  168. self.assertEqual(
  169. self.subject.device_state_attributes,
  170. {"error": 2},
  171. )