test_bwt_heatpump.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.climate.const import (
  3. ClimateEntityFeature,
  4. HVACMode,
  5. )
  6. from ..const import BWT_HEATPUMP_PAYLOAD
  7. from ..helpers import assert_device_properties_set
  8. from ..mixins.binary_sensor import BasicBinarySensorTests
  9. from ..mixins.climate import TargetTemperatureTests
  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(
  17. BasicBinarySensorTests,
  18. TargetTemperatureTests,
  19. TuyaDeviceTestCase,
  20. ):
  21. __test__ = True
  22. def setUp(self):
  23. self.setUpForConfig("bwt_heatpump.yaml", BWT_HEATPUMP_PAYLOAD)
  24. self.subject = self.entities["climate"]
  25. self.setUpTargetTemperature(
  26. TEMPERATURE_DPS,
  27. self.subject,
  28. min=5,
  29. max=40,
  30. )
  31. self.setUpBasicBinarySensor(
  32. ERROR_DPS,
  33. self.entities.get("binary_sensor_water_flow"),
  34. device_class=BinarySensorDeviceClass.PROBLEM,
  35. testdata=(1, 0),
  36. )
  37. self.mark_secondary(["binary_sensor_water_flow"])
  38. def test_supported_features(self):
  39. self.assertEqual(
  40. self.subject.supported_features,
  41. (
  42. ClimateEntityFeature.TARGET_TEMPERATURE
  43. | ClimateEntityFeature.PRESET_MODE
  44. ),
  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, HVACMode.HEAT)
  73. self.dps[HVACMODE_DPS] = False
  74. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  75. def test_hvac_modes(self):
  76. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  77. async def test_turn_on(self):
  78. async with assert_device_properties_set(
  79. self.subject._device, {HVACMODE_DPS: True}
  80. ):
  81. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  82. async def test_turn_off(self):
  83. async with assert_device_properties_set(
  84. self.subject._device, {HVACMODE_DPS: False}
  85. ):
  86. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  87. def test_preset_mode(self):
  88. self.dps[PRESET_DPS] = "heat"
  89. self.assertEqual(self.subject.preset_mode, "Smart Heating")
  90. self.dps[PRESET_DPS] = "cool"
  91. self.assertEqual(self.subject.preset_mode, "Smart Cooling")
  92. self.dps[PRESET_DPS] = "quickheat"
  93. self.assertEqual(self.subject.preset_mode, "Boost Heating")
  94. self.dps[PRESET_DPS] = "quickcool"
  95. self.assertEqual(self.subject.preset_mode, "Boost Cooling")
  96. self.dps[PRESET_DPS] = "quietheat"
  97. self.assertEqual(self.subject.preset_mode, "Eco Heating")
  98. self.dps[PRESET_DPS] = "quietcool"
  99. self.assertEqual(self.subject.preset_mode, "Eco Cooling")
  100. self.dps[PRESET_DPS] = "auto"
  101. self.assertEqual(self.subject.preset_mode, "Auto")
  102. self.dps[PRESET_DPS] = None
  103. self.assertIs(self.subject.preset_mode, None)
  104. def test_preset_modes(self):
  105. self.assertCountEqual(
  106. self.subject.preset_modes,
  107. [
  108. "Smart Heating",
  109. "Boost Heating",
  110. "Eco Heating",
  111. "Smart Cooling",
  112. "Boost Cooling",
  113. "Eco Cooling",
  114. "Auto",
  115. ],
  116. )
  117. async def test_set_preset_mode_to_heat(self):
  118. async with assert_device_properties_set(
  119. self.subject._device,
  120. {PRESET_DPS: "heat"},
  121. ):
  122. await self.subject.async_set_preset_mode("Smart Heating")
  123. async def test_set_preset_mode_to_cool(self):
  124. async with assert_device_properties_set(
  125. self.subject._device,
  126. {PRESET_DPS: "cool"},
  127. ):
  128. await self.subject.async_set_preset_mode("Smart Cooling")
  129. async def test_set_preset_mode_to_quickheat(self):
  130. async with assert_device_properties_set(
  131. self.subject._device,
  132. {PRESET_DPS: "quickheat"},
  133. ):
  134. await self.subject.async_set_preset_mode("Boost Heating")
  135. async def test_set_preset_mode_to_quickcool(self):
  136. async with assert_device_properties_set(
  137. self.subject._device,
  138. {PRESET_DPS: "quickcool"},
  139. ):
  140. await self.subject.async_set_preset_mode("Boost Cooling")
  141. async def test_set_preset_mode_to_quietheat(self):
  142. async with assert_device_properties_set(
  143. self.subject._device,
  144. {PRESET_DPS: "quietheat"},
  145. ):
  146. await self.subject.async_set_preset_mode("Eco Heating")
  147. async def test_set_preset_mode_to_quietcool(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {PRESET_DPS: "quietcool"},
  151. ):
  152. await self.subject.async_set_preset_mode("Eco Cooling")
  153. async def test_set_preset_mode_to_auto(self):
  154. async with assert_device_properties_set(
  155. self.subject._device,
  156. {PRESET_DPS: "auto"},
  157. ):
  158. await self.subject.async_set_preset_mode("Auto")
  159. def test_error_state(self):
  160. self.dps[ERROR_DPS] = 0
  161. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  162. self.dps[ERROR_DPS] = 1
  163. self.assertEqual(
  164. self.subject.extra_state_attributes,
  165. {"error": "Water Flow Protection"},
  166. )
  167. self.dps[ERROR_DPS] = 2
  168. self.assertEqual(
  169. self.subject.extra_state_attributes,
  170. {"error": 2},
  171. )