test_bwt_heatpump.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT,
  3. HVAC_MODE_OFF,
  4. SUPPORT_PRESET_MODE,
  5. SUPPORT_TARGET_TEMPERATURE,
  6. )
  7. from homeassistant.const import STATE_UNAVAILABLE
  8. from ..const import BWT_HEATPUMP_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  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 TestBWTHeatpump(TuyaDeviceTestCase):
  17. __test__ = True
  18. def setUp(self):
  19. self.setUpForConfig("bwt_heatpump.yaml", BWT_HEATPUMP_PAYLOAD)
  20. self.subject = self.entities["climate"]
  21. def test_supported_features(self):
  22. self.assertEqual(
  23. self.subject.supported_features,
  24. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  25. )
  26. def test_icon(self):
  27. self.dps[HVACMODE_DPS] = True
  28. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  29. self.dps[HVACMODE_DPS] = False
  30. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  31. def test_temperature_unit_returns_device_temperature_unit(self):
  32. self.assertEqual(
  33. self.subject.temperature_unit, self.subject._device.temperature_unit
  34. )
  35. def test_target_temperature(self):
  36. self.dps[TEMPERATURE_DPS] = 25
  37. self.assertEqual(self.subject.target_temperature, 25)
  38. def test_target_temperature_step(self):
  39. self.assertEqual(self.subject.target_temperature_step, 1)
  40. def test_minimum_target_temperature(self):
  41. self.assertEqual(self.subject.min_temp, 5)
  42. def test_maximum_target_temperature(self):
  43. self.assertEqual(self.subject.max_temp, 40)
  44. async def test_legacy_set_temperature_with_temperature(self):
  45. async with assert_device_properties_set(
  46. self.subject._device, {TEMPERATURE_DPS: 24}
  47. ):
  48. await self.subject.async_set_temperature(temperature=24)
  49. async def test_legacy_set_temperature_with_preset_mode(self):
  50. async with assert_device_properties_set(
  51. self.subject._device, {PRESET_DPS: "cool"}
  52. ):
  53. await self.subject.async_set_temperature(preset_mode="Smart Cooling")
  54. async def test_legacy_set_temperature_with_both_properties(self):
  55. async with assert_device_properties_set(
  56. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "heat"}
  57. ):
  58. await self.subject.async_set_temperature(
  59. temperature=26, preset_mode="Smart Heating"
  60. )
  61. async def test_legacy_set_temperature_with_no_valid_properties(self):
  62. await self.subject.async_set_temperature(something="else")
  63. self.subject._device.async_set_property.assert_not_called()
  64. async def test_set_target_temperature_succeeds_within_valid_range(self):
  65. async with assert_device_properties_set(
  66. self.subject._device,
  67. {TEMPERATURE_DPS: 25},
  68. ):
  69. await self.subject.async_set_target_temperature(25)
  70. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  71. async with assert_device_properties_set(
  72. self.subject._device, {TEMPERATURE_DPS: 23}
  73. ):
  74. await self.subject.async_set_target_temperature(22.6)
  75. async def test_set_target_temperature_fails_outside_valid_range(self):
  76. with self.assertRaisesRegex(
  77. ValueError, "temperature \\(4\\) must be between 5 and 40"
  78. ):
  79. await self.subject.async_set_target_temperature(4)
  80. with self.assertRaisesRegex(
  81. ValueError, "temperature \\(41\\) must be between 5 and 40"
  82. ):
  83. await self.subject.async_set_target_temperature(41)
  84. def test_current_temperature(self):
  85. self.dps[CURRENTTEMP_DPS] = 25
  86. self.assertEqual(self.subject.current_temperature, 25)
  87. def test_hvac_mode(self):
  88. self.dps[HVACMODE_DPS] = True
  89. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  90. self.dps[HVACMODE_DPS] = False
  91. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  92. self.dps[HVACMODE_DPS] = None
  93. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  94. def test_hvac_modes(self):
  95. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  96. async def test_turn_on(self):
  97. async with assert_device_properties_set(
  98. self.subject._device, {HVACMODE_DPS: True}
  99. ):
  100. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  101. async def test_turn_off(self):
  102. async with assert_device_properties_set(
  103. self.subject._device, {HVACMODE_DPS: False}
  104. ):
  105. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  106. def test_preset_mode(self):
  107. self.dps[PRESET_DPS] = "heat"
  108. self.assertEqual(self.subject.preset_mode, "Smart Heating")
  109. self.dps[PRESET_DPS] = "cool"
  110. self.assertEqual(self.subject.preset_mode, "Smart Cooling")
  111. self.dps[PRESET_DPS] = "quickheat"
  112. self.assertEqual(self.subject.preset_mode, "Boost Heating")
  113. self.dps[PRESET_DPS] = "quickcool"
  114. self.assertEqual(self.subject.preset_mode, "Boost Cooling")
  115. self.dps[PRESET_DPS] = "quietheat"
  116. self.assertEqual(self.subject.preset_mode, "Eco Heating")
  117. self.dps[PRESET_DPS] = "quietcool"
  118. self.assertEqual(self.subject.preset_mode, "Eco Cooling")
  119. self.dps[PRESET_DPS] = "auto"
  120. self.assertEqual(self.subject.preset_mode, "Auto")
  121. self.dps[PRESET_DPS] = None
  122. self.assertIs(self.subject.preset_mode, None)
  123. def test_preset_modes(self):
  124. self.assertCountEqual(
  125. self.subject.preset_modes,
  126. [
  127. "Smart Heating",
  128. "Boost Heating",
  129. "Eco Heating",
  130. "Smart Cooling",
  131. "Boost Cooling",
  132. "Eco Cooling",
  133. "Auto",
  134. ],
  135. )
  136. async def test_set_preset_mode_to_heat(self):
  137. async with assert_device_properties_set(
  138. self.subject._device,
  139. {PRESET_DPS: "heat"},
  140. ):
  141. await self.subject.async_set_preset_mode("Smart Heating")
  142. async def test_set_preset_mode_to_cool(self):
  143. async with assert_device_properties_set(
  144. self.subject._device,
  145. {PRESET_DPS: "cool"},
  146. ):
  147. await self.subject.async_set_preset_mode("Smart Cooling")
  148. async def test_set_preset_mode_to_quickheat(self):
  149. async with assert_device_properties_set(
  150. self.subject._device,
  151. {PRESET_DPS: "quickheat"},
  152. ):
  153. await self.subject.async_set_preset_mode("Boost Heating")
  154. async def test_set_preset_mode_to_quickcool(self):
  155. async with assert_device_properties_set(
  156. self.subject._device,
  157. {PRESET_DPS: "quickcool"},
  158. ):
  159. await self.subject.async_set_preset_mode("Boost Cooling")
  160. async def test_set_preset_mode_to_quietheat(self):
  161. async with assert_device_properties_set(
  162. self.subject._device,
  163. {PRESET_DPS: "quietheat"},
  164. ):
  165. await self.subject.async_set_preset_mode("Eco Heating")
  166. async def test_set_preset_mode_to_quietcool(self):
  167. async with assert_device_properties_set(
  168. self.subject._device,
  169. {PRESET_DPS: "quietcool"},
  170. ):
  171. await self.subject.async_set_preset_mode("Eco Cooling")
  172. async def test_set_preset_mode_to_auto(self):
  173. async with assert_device_properties_set(
  174. self.subject._device,
  175. {PRESET_DPS: "auto"},
  176. ):
  177. await self.subject.async_set_preset_mode("Auto")
  178. def test_error_state(self):
  179. self.dps[ERROR_DPS] = 0
  180. self.assertEqual(self.subject.device_state_attributes, {"error": "OK"})
  181. self.dps[ERROR_DPS] = 1
  182. self.assertEqual(
  183. self.subject.device_state_attributes,
  184. {"error": "Water Flow Protection"},
  185. )
  186. self.dps[ERROR_DPS] = 2
  187. self.assertEqual(
  188. self.subject.device_state_attributes,
  189. {"error": 2},
  190. )