test_remora_heatpump.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.climate.const import (
  3. ClimateEntityFeature,
  4. HVACMode,
  5. )
  6. from ..const import REMORA_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 = "9"
  16. class TestRemoraHeatpump(
  17. BasicBinarySensorTests, TargetTemperatureTests, TuyaDeviceTestCase
  18. ):
  19. __test__ = True
  20. def setUp(self):
  21. self.setUpForConfig("remora_heatpump.yaml", REMORA_HEATPUMP_PAYLOAD)
  22. self.subject = self.entities.get("climate")
  23. self.setUpTargetTemperature(
  24. TEMPERATURE_DPS,
  25. self.subject,
  26. min=5,
  27. max=40,
  28. )
  29. self.setUpBasicBinarySensor(
  30. ERROR_DPS,
  31. self.entities.get("binary_sensor_water_flow"),
  32. device_class=BinarySensorDeviceClass.PROBLEM,
  33. testdata=(1, 0),
  34. )
  35. self.mark_secondary(["binary_sensor_water_flow"])
  36. def test_supported_features(self):
  37. self.assertEqual(
  38. self.subject.supported_features,
  39. (
  40. ClimateEntityFeature.TARGET_TEMPERATURE
  41. | ClimateEntityFeature.PRESET_MODE
  42. ),
  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, HVACMode.HEAT)
  71. self.dps[HVACMODE_DPS] = False
  72. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  73. def test_hvac_modes(self):
  74. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  75. async def test_turn_on(self):
  76. async with assert_device_properties_set(
  77. self.subject._device, {HVACMODE_DPS: True}
  78. ):
  79. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  80. async def test_turn_off(self):
  81. async with assert_device_properties_set(
  82. self.subject._device, {HVACMODE_DPS: False}
  83. ):
  84. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  85. def test_preset_mode(self):
  86. self.dps[PRESET_DPS] = "heat"
  87. self.assertEqual(self.subject.preset_mode, "Smart Heating")
  88. self.dps[PRESET_DPS] = "cool"
  89. self.assertEqual(self.subject.preset_mode, "Smart Cooling")
  90. self.dps[PRESET_DPS] = "h_powerful"
  91. self.assertEqual(self.subject.preset_mode, "Powerful Heating")
  92. self.dps[PRESET_DPS] = "c_powerful"
  93. self.assertEqual(self.subject.preset_mode, "Powerful Cooling")
  94. self.dps[PRESET_DPS] = "h_silent"
  95. self.assertEqual(self.subject.preset_mode, "Silent Heating")
  96. self.dps[PRESET_DPS] = "c_silent"
  97. self.assertEqual(self.subject.preset_mode, "Silent Cooling")
  98. self.dps[PRESET_DPS] = None
  99. self.assertIs(self.subject.preset_mode, None)
  100. def test_preset_modes(self):
  101. self.assertCountEqual(
  102. self.subject.preset_modes,
  103. [
  104. "Smart Heating",
  105. "Powerful Heating",
  106. "Silent Heating",
  107. "Smart Cooling",
  108. "Powerful Cooling",
  109. "Silent Cooling",
  110. ],
  111. )
  112. async def test_set_preset_mode_to_heat(self):
  113. async with assert_device_properties_set(
  114. self.subject._device,
  115. {PRESET_DPS: "heat"},
  116. ):
  117. await self.subject.async_set_preset_mode("Smart Heating")
  118. async def test_set_preset_mode_to_cool(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {PRESET_DPS: "cool"},
  122. ):
  123. await self.subject.async_set_preset_mode("Smart Cooling")
  124. async def test_set_preset_mode_to_h_powerful(self):
  125. async with assert_device_properties_set(
  126. self.subject._device,
  127. {PRESET_DPS: "h_powerful"},
  128. ):
  129. await self.subject.async_set_preset_mode("Powerful Heating")
  130. async def test_set_preset_mode_to_c_powerful(self):
  131. async with assert_device_properties_set(
  132. self.subject._device,
  133. {PRESET_DPS: "c_powerful"},
  134. ):
  135. await self.subject.async_set_preset_mode("Powerful Cooling")
  136. async def test_set_preset_mode_to_h_silent(self):
  137. async with assert_device_properties_set(
  138. self.subject._device,
  139. {PRESET_DPS: "h_silent"},
  140. ):
  141. await self.subject.async_set_preset_mode("Silent Heating")
  142. async def test_set_preset_mode_to_c_silent(self):
  143. async with assert_device_properties_set(
  144. self.subject._device,
  145. {PRESET_DPS: "c_silent"},
  146. ):
  147. await self.subject.async_set_preset_mode("Silent Cooling")
  148. def test_error_state(self):
  149. self.dps[ERROR_DPS] = 0
  150. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  151. self.dps[ERROR_DPS] = 1
  152. self.assertEqual(
  153. self.subject.extra_state_attributes,
  154. {"error": "Water Flow Protection"},
  155. )
  156. self.dps[ERROR_DPS] = 2
  157. self.assertEqual(
  158. self.subject.extra_state_attributes,
  159. {"error": 2},
  160. )