test_bwt_heatpump.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 BWT_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 TestBWTHeatpump(
  20. BasicBinarySensorTests,
  21. TargetTemperatureTests,
  22. TuyaDeviceTestCase,
  23. ):
  24. __test__ = True
  25. def setUp(self):
  26. self.setUpForConfig("bwt_heatpump.yaml", BWT_HEATPUMP_PAYLOAD)
  27. self.subject = self.entities["climate"]
  28. self.setUpTargetTemperature(
  29. TEMPERATURE_DPS,
  30. self.subject,
  31. min=5,
  32. max=40,
  33. )
  34. self.setUpBasicBinarySensor(
  35. ERROR_DPS,
  36. self.entities.get("binary_sensor_water_flow"),
  37. device_class=DEVICE_CLASS_PROBLEM,
  38. testdata=(1, 0),
  39. )
  40. def test_supported_features(self):
  41. self.assertEqual(
  42. self.subject.supported_features,
  43. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  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_device_temperature_unit(self):
  51. self.assertEqual(
  52. self.subject.temperature_unit, self.subject._device.temperature_unit
  53. )
  54. async def test_legacy_set_temperature_with_preset_mode(self):
  55. async with assert_device_properties_set(
  56. self.subject._device, {PRESET_DPS: "cool"}
  57. ):
  58. await self.subject.async_set_temperature(preset_mode="Smart Cooling")
  59. async def test_legacy_set_temperature_with_both_properties(self):
  60. async with assert_device_properties_set(
  61. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "heat"}
  62. ):
  63. await self.subject.async_set_temperature(
  64. temperature=26, preset_mode="Smart Heating"
  65. )
  66. def test_current_temperature(self):
  67. self.dps[CURRENTTEMP_DPS] = 25
  68. self.assertEqual(self.subject.current_temperature, 25)
  69. def test_hvac_mode(self):
  70. self.dps[HVACMODE_DPS] = True
  71. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  72. self.dps[HVACMODE_DPS] = False
  73. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  74. self.dps[HVACMODE_DPS] = None
  75. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  76. def test_hvac_modes(self):
  77. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  78. async def test_turn_on(self):
  79. async with assert_device_properties_set(
  80. self.subject._device, {HVACMODE_DPS: True}
  81. ):
  82. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  83. async def test_turn_off(self):
  84. async with assert_device_properties_set(
  85. self.subject._device, {HVACMODE_DPS: False}
  86. ):
  87. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  88. def test_preset_mode(self):
  89. self.dps[PRESET_DPS] = "heat"
  90. self.assertEqual(self.subject.preset_mode, "Smart Heating")
  91. self.dps[PRESET_DPS] = "cool"
  92. self.assertEqual(self.subject.preset_mode, "Smart Cooling")
  93. self.dps[PRESET_DPS] = "quickheat"
  94. self.assertEqual(self.subject.preset_mode, "Boost Heating")
  95. self.dps[PRESET_DPS] = "quickcool"
  96. self.assertEqual(self.subject.preset_mode, "Boost Cooling")
  97. self.dps[PRESET_DPS] = "quietheat"
  98. self.assertEqual(self.subject.preset_mode, "Eco Heating")
  99. self.dps[PRESET_DPS] = "quietcool"
  100. self.assertEqual(self.subject.preset_mode, "Eco Cooling")
  101. self.dps[PRESET_DPS] = "auto"
  102. self.assertEqual(self.subject.preset_mode, "Auto")
  103. self.dps[PRESET_DPS] = None
  104. self.assertIs(self.subject.preset_mode, None)
  105. def test_preset_modes(self):
  106. self.assertCountEqual(
  107. self.subject.preset_modes,
  108. [
  109. "Smart Heating",
  110. "Boost Heating",
  111. "Eco Heating",
  112. "Smart Cooling",
  113. "Boost Cooling",
  114. "Eco Cooling",
  115. "Auto",
  116. ],
  117. )
  118. async def test_set_preset_mode_to_heat(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {PRESET_DPS: "heat"},
  122. ):
  123. await self.subject.async_set_preset_mode("Smart Heating")
  124. async def test_set_preset_mode_to_cool(self):
  125. async with assert_device_properties_set(
  126. self.subject._device,
  127. {PRESET_DPS: "cool"},
  128. ):
  129. await self.subject.async_set_preset_mode("Smart Cooling")
  130. async def test_set_preset_mode_to_quickheat(self):
  131. async with assert_device_properties_set(
  132. self.subject._device,
  133. {PRESET_DPS: "quickheat"},
  134. ):
  135. await self.subject.async_set_preset_mode("Boost Heating")
  136. async def test_set_preset_mode_to_quickcool(self):
  137. async with assert_device_properties_set(
  138. self.subject._device,
  139. {PRESET_DPS: "quickcool"},
  140. ):
  141. await self.subject.async_set_preset_mode("Boost Cooling")
  142. async def test_set_preset_mode_to_quietheat(self):
  143. async with assert_device_properties_set(
  144. self.subject._device,
  145. {PRESET_DPS: "quietheat"},
  146. ):
  147. await self.subject.async_set_preset_mode("Eco Heating")
  148. async def test_set_preset_mode_to_quietcool(self):
  149. async with assert_device_properties_set(
  150. self.subject._device,
  151. {PRESET_DPS: "quietcool"},
  152. ):
  153. await self.subject.async_set_preset_mode("Eco Cooling")
  154. async def test_set_preset_mode_to_auto(self):
  155. async with assert_device_properties_set(
  156. self.subject._device,
  157. {PRESET_DPS: "auto"},
  158. ):
  159. await self.subject.async_set_preset_mode("Auto")
  160. def test_error_state(self):
  161. self.dps[ERROR_DPS] = 0
  162. self.assertEqual(self.subject.device_state_attributes, {"error": "OK"})
  163. self.dps[ERROR_DPS] = 1
  164. self.assertEqual(
  165. self.subject.device_state_attributes,
  166. {"error": "Water Flow Protection"},
  167. )
  168. self.dps[ERROR_DPS] = 2
  169. self.assertEqual(
  170. self.subject.device_state_attributes,
  171. {"error": 2},
  172. )