test_remora_heatpump.py 6.6 KB

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