test_bwt_heatpump.py 8.6 KB

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