test_remora_heatpump.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 REMORA_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 = "9"
  19. class TestRemoraHeatpump(
  20. BasicBinarySensorTests, TargetTemperatureTests, TuyaDeviceTestCase
  21. ):
  22. __test__ = True
  23. def setUp(self):
  24. self.setUpForConfig("remora_heatpump.yaml", REMORA_HEATPUMP_PAYLOAD)
  25. self.subject = self.entities.get("climate")
  26. self.setUpTargetTemperature(
  27. TEMPERATURE_DPS,
  28. self.subject,
  29. min=5,
  30. max=40,
  31. )
  32. self.setUpBasicBinarySensor(
  33. ERROR_DPS,
  34. self.entities.get("binary_sensor_water_flow"),
  35. device_class=DEVICE_CLASS_PROBLEM,
  36. testdata=(1, 0),
  37. )
  38. def test_supported_features(self):
  39. self.assertEqual(
  40. self.subject.supported_features,
  41. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  42. )
  43. def test_icon(self):
  44. self.dps[HVACMODE_DPS] = True
  45. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  46. self.dps[HVACMODE_DPS] = False
  47. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  48. def test_temperature_unit_returns_device_temperature_unit(self):
  49. self.assertEqual(
  50. self.subject.temperature_unit, self.subject._device.temperature_unit
  51. )
  52. async def test_legacy_set_temperature_with_preset_mode(self):
  53. async with assert_device_properties_set(
  54. self.subject._device, {PRESET_DPS: "cool"}
  55. ):
  56. await self.subject.async_set_temperature(preset_mode="Smart Cooling")
  57. async def test_legacy_set_temperature_with_both_properties(self):
  58. async with assert_device_properties_set(
  59. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "heat"}
  60. ):
  61. await self.subject.async_set_temperature(
  62. temperature=26, preset_mode="Smart Heating"
  63. )
  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, HVAC_MODE_HEAT)
  70. self.dps[HVACMODE_DPS] = False
  71. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  72. self.dps[HVACMODE_DPS] = None
  73. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  74. def test_hvac_modes(self):
  75. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  76. async def test_turn_on(self):
  77. async with assert_device_properties_set(
  78. self.subject._device, {HVACMODE_DPS: True}
  79. ):
  80. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  81. async def test_turn_off(self):
  82. async with assert_device_properties_set(
  83. self.subject._device, {HVACMODE_DPS: False}
  84. ):
  85. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  86. def test_preset_mode(self):
  87. self.dps[PRESET_DPS] = "heat"
  88. self.assertEqual(self.subject.preset_mode, "Smart Heating")
  89. self.dps[PRESET_DPS] = "cool"
  90. self.assertEqual(self.subject.preset_mode, "Smart Cooling")
  91. self.dps[PRESET_DPS] = "h_powerful"
  92. self.assertEqual(self.subject.preset_mode, "Powerful Heating")
  93. self.dps[PRESET_DPS] = "c_powerful"
  94. self.assertEqual(self.subject.preset_mode, "Powerful Cooling")
  95. self.dps[PRESET_DPS] = "h_silent"
  96. self.assertEqual(self.subject.preset_mode, "Silent Heating")
  97. self.dps[PRESET_DPS] = "c_silent"
  98. self.assertEqual(self.subject.preset_mode, "Silent Cooling")
  99. self.dps[PRESET_DPS] = None
  100. self.assertIs(self.subject.preset_mode, None)
  101. def test_preset_modes(self):
  102. self.assertCountEqual(
  103. self.subject.preset_modes,
  104. [
  105. "Smart Heating",
  106. "Powerful Heating",
  107. "Silent Heating",
  108. "Smart Cooling",
  109. "Powerful Cooling",
  110. "Silent Cooling",
  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("Smart Heating")
  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("Smart Cooling")
  125. async def test_set_preset_mode_to_h_powerful(self):
  126. async with assert_device_properties_set(
  127. self.subject._device,
  128. {PRESET_DPS: "h_powerful"},
  129. ):
  130. await self.subject.async_set_preset_mode("Powerful Heating")
  131. async def test_set_preset_mode_to_c_powerful(self):
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {PRESET_DPS: "c_powerful"},
  135. ):
  136. await self.subject.async_set_preset_mode("Powerful Cooling")
  137. async def test_set_preset_mode_to_h_silent(self):
  138. async with assert_device_properties_set(
  139. self.subject._device,
  140. {PRESET_DPS: "h_silent"},
  141. ):
  142. await self.subject.async_set_preset_mode("Silent Heating")
  143. async def test_set_preset_mode_to_c_silent(self):
  144. async with assert_device_properties_set(
  145. self.subject._device,
  146. {PRESET_DPS: "c_silent"},
  147. ):
  148. await self.subject.async_set_preset_mode("Silent Cooling")
  149. def test_error_state(self):
  150. self.dps[ERROR_DPS] = 0
  151. self.assertEqual(self.subject.device_state_attributes, {"error": "OK"})
  152. self.dps[ERROR_DPS] = 1
  153. self.assertEqual(
  154. self.subject.device_state_attributes,
  155. {"error": "Water Flow Protection"},
  156. )
  157. self.dps[ERROR_DPS] = 2
  158. self.assertEqual(
  159. self.subject.device_state_attributes,
  160. {"error": 2},
  161. )