test_bwt_heatpump.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 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=BinarySensorDeviceClass.PROBLEM,
  38. testdata=(1, 0),
  39. )
  40. self.mark_secondary(["binary_sensor_water_flow"])
  41. def test_supported_features(self):
  42. self.assertEqual(
  43. self.subject.supported_features,
  44. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  45. )
  46. def test_icon(self):
  47. self.dps[HVACMODE_DPS] = True
  48. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  49. self.dps[HVACMODE_DPS] = False
  50. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  51. def test_temperature_unit_returns_device_temperature_unit(self):
  52. self.assertEqual(
  53. self.subject.temperature_unit, self.subject._device.temperature_unit
  54. )
  55. async def test_legacy_set_temperature_with_preset_mode(self):
  56. async with assert_device_properties_set(
  57. self.subject._device, {PRESET_DPS: "cool"}
  58. ):
  59. await self.subject.async_set_temperature(preset_mode="Smart Cooling")
  60. async def test_legacy_set_temperature_with_both_properties(self):
  61. async with assert_device_properties_set(
  62. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "heat"}
  63. ):
  64. await self.subject.async_set_temperature(
  65. temperature=26, preset_mode="Smart Heating"
  66. )
  67. def test_current_temperature(self):
  68. self.dps[CURRENTTEMP_DPS] = 25
  69. self.assertEqual(self.subject.current_temperature, 25)
  70. def test_hvac_mode(self):
  71. self.dps[HVACMODE_DPS] = True
  72. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  73. self.dps[HVACMODE_DPS] = False
  74. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  75. self.dps[HVACMODE_DPS] = None
  76. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  77. def test_hvac_modes(self):
  78. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  79. async def test_turn_on(self):
  80. async with assert_device_properties_set(
  81. self.subject._device, {HVACMODE_DPS: True}
  82. ):
  83. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  84. async def test_turn_off(self):
  85. async with assert_device_properties_set(
  86. self.subject._device, {HVACMODE_DPS: False}
  87. ):
  88. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  89. def test_preset_mode(self):
  90. self.dps[PRESET_DPS] = "heat"
  91. self.assertEqual(self.subject.preset_mode, "Smart Heating")
  92. self.dps[PRESET_DPS] = "cool"
  93. self.assertEqual(self.subject.preset_mode, "Smart Cooling")
  94. self.dps[PRESET_DPS] = "quickheat"
  95. self.assertEqual(self.subject.preset_mode, "Boost Heating")
  96. self.dps[PRESET_DPS] = "quickcool"
  97. self.assertEqual(self.subject.preset_mode, "Boost Cooling")
  98. self.dps[PRESET_DPS] = "quietheat"
  99. self.assertEqual(self.subject.preset_mode, "Eco Heating")
  100. self.dps[PRESET_DPS] = "quietcool"
  101. self.assertEqual(self.subject.preset_mode, "Eco Cooling")
  102. self.dps[PRESET_DPS] = "auto"
  103. self.assertEqual(self.subject.preset_mode, "Auto")
  104. self.dps[PRESET_DPS] = None
  105. self.assertIs(self.subject.preset_mode, None)
  106. def test_preset_modes(self):
  107. self.assertCountEqual(
  108. self.subject.preset_modes,
  109. [
  110. "Smart Heating",
  111. "Boost Heating",
  112. "Eco Heating",
  113. "Smart Cooling",
  114. "Boost Cooling",
  115. "Eco Cooling",
  116. "Auto",
  117. ],
  118. )
  119. async def test_set_preset_mode_to_heat(self):
  120. async with assert_device_properties_set(
  121. self.subject._device,
  122. {PRESET_DPS: "heat"},
  123. ):
  124. await self.subject.async_set_preset_mode("Smart Heating")
  125. async def test_set_preset_mode_to_cool(self):
  126. async with assert_device_properties_set(
  127. self.subject._device,
  128. {PRESET_DPS: "cool"},
  129. ):
  130. await self.subject.async_set_preset_mode("Smart Cooling")
  131. async def test_set_preset_mode_to_quickheat(self):
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {PRESET_DPS: "quickheat"},
  135. ):
  136. await self.subject.async_set_preset_mode("Boost Heating")
  137. async def test_set_preset_mode_to_quickcool(self):
  138. async with assert_device_properties_set(
  139. self.subject._device,
  140. {PRESET_DPS: "quickcool"},
  141. ):
  142. await self.subject.async_set_preset_mode("Boost Cooling")
  143. async def test_set_preset_mode_to_quietheat(self):
  144. async with assert_device_properties_set(
  145. self.subject._device,
  146. {PRESET_DPS: "quietheat"},
  147. ):
  148. await self.subject.async_set_preset_mode("Eco Heating")
  149. async def test_set_preset_mode_to_quietcool(self):
  150. async with assert_device_properties_set(
  151. self.subject._device,
  152. {PRESET_DPS: "quietcool"},
  153. ):
  154. await self.subject.async_set_preset_mode("Eco Cooling")
  155. async def test_set_preset_mode_to_auto(self):
  156. async with assert_device_properties_set(
  157. self.subject._device,
  158. {PRESET_DPS: "auto"},
  159. ):
  160. await self.subject.async_set_preset_mode("Auto")
  161. def test_error_state(self):
  162. self.dps[ERROR_DPS] = 0
  163. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  164. self.dps[ERROR_DPS] = 1
  165. self.assertEqual(
  166. self.subject.extra_state_attributes,
  167. {"error": "Water Flow Protection"},
  168. )
  169. self.dps[ERROR_DPS] = 2
  170. self.assertEqual(
  171. self.subject.extra_state_attributes,
  172. {"error": 2},
  173. )