test_remora_heatpump.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 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=BinarySensorDeviceClass.PROBLEM,
  36. testdata=(1, 0),
  37. )
  38. self.mark_secondary(["binary_sensor_water_flow"])
  39. def test_supported_features(self):
  40. self.assertEqual(
  41. self.subject.supported_features,
  42. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  43. )
  44. def test_icon(self):
  45. self.dps[HVACMODE_DPS] = True
  46. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  47. self.dps[HVACMODE_DPS] = False
  48. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  49. def test_temperature_unit_returns_device_temperature_unit(self):
  50. self.assertEqual(
  51. self.subject.temperature_unit, self.subject._device.temperature_unit
  52. )
  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="Smart Cooling")
  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(
  63. temperature=26, preset_mode="Smart Heating"
  64. )
  65. def test_current_temperature(self):
  66. self.dps[CURRENTTEMP_DPS] = 25
  67. self.assertEqual(self.subject.current_temperature, 25)
  68. def test_hvac_mode(self):
  69. self.dps[HVACMODE_DPS] = True
  70. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  71. self.dps[HVACMODE_DPS] = False
  72. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  73. self.dps[HVACMODE_DPS] = None
  74. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  75. def test_hvac_modes(self):
  76. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  77. async def test_turn_on(self):
  78. async with assert_device_properties_set(
  79. self.subject._device, {HVACMODE_DPS: True}
  80. ):
  81. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  82. async def test_turn_off(self):
  83. async with assert_device_properties_set(
  84. self.subject._device, {HVACMODE_DPS: False}
  85. ):
  86. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  87. def test_preset_mode(self):
  88. self.dps[PRESET_DPS] = "heat"
  89. self.assertEqual(self.subject.preset_mode, "Smart Heating")
  90. self.dps[PRESET_DPS] = "cool"
  91. self.assertEqual(self.subject.preset_mode, "Smart Cooling")
  92. self.dps[PRESET_DPS] = "h_powerful"
  93. self.assertEqual(self.subject.preset_mode, "Powerful Heating")
  94. self.dps[PRESET_DPS] = "c_powerful"
  95. self.assertEqual(self.subject.preset_mode, "Powerful Cooling")
  96. self.dps[PRESET_DPS] = "h_silent"
  97. self.assertEqual(self.subject.preset_mode, "Silent Heating")
  98. self.dps[PRESET_DPS] = "c_silent"
  99. self.assertEqual(self.subject.preset_mode, "Silent Cooling")
  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. "Smart Heating",
  107. "Powerful Heating",
  108. "Silent Heating",
  109. "Smart Cooling",
  110. "Powerful Cooling",
  111. "Silent Cooling",
  112. ],
  113. )
  114. async def test_set_preset_mode_to_heat(self):
  115. async with assert_device_properties_set(
  116. self.subject._device,
  117. {PRESET_DPS: "heat"},
  118. ):
  119. await self.subject.async_set_preset_mode("Smart Heating")
  120. async def test_set_preset_mode_to_cool(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {PRESET_DPS: "cool"},
  124. ):
  125. await self.subject.async_set_preset_mode("Smart Cooling")
  126. async def test_set_preset_mode_to_h_powerful(self):
  127. async with assert_device_properties_set(
  128. self.subject._device,
  129. {PRESET_DPS: "h_powerful"},
  130. ):
  131. await self.subject.async_set_preset_mode("Powerful Heating")
  132. async def test_set_preset_mode_to_c_powerful(self):
  133. async with assert_device_properties_set(
  134. self.subject._device,
  135. {PRESET_DPS: "c_powerful"},
  136. ):
  137. await self.subject.async_set_preset_mode("Powerful Cooling")
  138. async def test_set_preset_mode_to_h_silent(self):
  139. async with assert_device_properties_set(
  140. self.subject._device,
  141. {PRESET_DPS: "h_silent"},
  142. ):
  143. await self.subject.async_set_preset_mode("Silent Heating")
  144. async def test_set_preset_mode_to_c_silent(self):
  145. async with assert_device_properties_set(
  146. self.subject._device,
  147. {PRESET_DPS: "c_silent"},
  148. ):
  149. await self.subject.async_set_preset_mode("Silent Cooling")
  150. def test_error_state(self):
  151. self.dps[ERROR_DPS] = 0
  152. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  153. self.dps[ERROR_DPS] = 1
  154. self.assertEqual(
  155. self.subject.extra_state_attributes,
  156. {"error": "Water Flow Protection"},
  157. )
  158. self.dps[ERROR_DPS] = 2
  159. self.assertEqual(
  160. self.subject.extra_state_attributes,
  161. {"error": 2},
  162. )