test_gardenpac_heatpump.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 (
  8. STATE_UNAVAILABLE,
  9. TEMP_CELSIUS,
  10. TEMP_FAHRENHEIT,
  11. )
  12. from ..const import GARDENPAC_HEATPUMP_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from .base_device_tests import TuyaDeviceTestCase
  15. HVACMODE_DPS = "1"
  16. CURRENTTEMP_DPS = "102"
  17. UNITS_DPS = "103"
  18. POWERLEVEL_DPS = "104"
  19. OPMODE_DPS = "105"
  20. TEMPERATURE_DPS = "106"
  21. UNKNOWN107_DPS = "107"
  22. UNKNOWN108_DPS = "108"
  23. UNKNOWN115_DPS = "115"
  24. UNKNOWN116_DPS = "116"
  25. PRESET_DPS = "117"
  26. class TestGardenPACPoolHeatpump(TuyaDeviceTestCase):
  27. __test__ = True
  28. def setUp(self):
  29. self.setUpForConfig("gardenpac_heatpump.yaml", GARDENPAC_HEATPUMP_PAYLOAD)
  30. self.subject = self.entities.get("climate")
  31. def test_supported_features(self):
  32. self.assertEqual(
  33. self.subject.supported_features,
  34. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  35. )
  36. def test_icon(self):
  37. self.dps[HVACMODE_DPS] = True
  38. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  39. self.dps[HVACMODE_DPS] = False
  40. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  41. def test_temperature_unit(self):
  42. self.dps[UNITS_DPS] = False
  43. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  44. self.dps[UNITS_DPS] = True
  45. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  46. def test_target_temperature(self):
  47. self.dps[TEMPERATURE_DPS] = 25
  48. self.assertEqual(self.subject.target_temperature, 25)
  49. def test_target_temperature_step(self):
  50. self.assertEqual(self.subject.target_temperature_step, 1)
  51. def test_minimum_target_temperature(self):
  52. self.assertEqual(self.subject.min_temp, 18)
  53. def test_maximum_target_temperature(self):
  54. self.assertEqual(self.subject.max_temp, 45)
  55. def test_minimum_fahrenheit_temperature(self):
  56. self.dps[UNITS_DPS] = False
  57. self.assertEqual(self.subject.min_temp, 60)
  58. def test_maximum_fahrenheit_temperature(self):
  59. self.dps[UNITS_DPS] = False
  60. self.assertEqual(self.subject.max_temp, 115)
  61. async def test_legacy_set_temperature_with_temperature(self):
  62. async with assert_device_properties_set(
  63. self.subject._device, {TEMPERATURE_DPS: 25}
  64. ):
  65. await self.subject.async_set_temperature(temperature=25)
  66. async def test_legacy_set_temperature_with_no_valid_properties(self):
  67. await self.subject.async_set_temperature(something="else")
  68. self.subject._device.async_set_property.assert_not_called()
  69. async def test_set_target_temperature_succeeds_within_valid_range(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {TEMPERATURE_DPS: 25}
  72. ):
  73. await self.subject.async_set_target_temperature(25)
  74. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  75. async with assert_device_properties_set(
  76. self.subject._device,
  77. {TEMPERATURE_DPS: 25},
  78. ):
  79. await self.subject.async_set_target_temperature(24.6)
  80. async def test_set_target_temperature_fails_outside_valid_range(self):
  81. with self.assertRaisesRegex(
  82. ValueError, "temperature \\(14\\) must be between 18 and 45"
  83. ):
  84. await self.subject.async_set_target_temperature(14)
  85. with self.assertRaisesRegex(
  86. ValueError, "temperature \\(46\\) must be between 18 and 45"
  87. ):
  88. await self.subject.async_set_target_temperature(46)
  89. def test_current_temperature(self):
  90. self.dps[CURRENTTEMP_DPS] = 25
  91. self.assertEqual(self.subject.current_temperature, 25)
  92. def test_hvac_mode(self):
  93. self.dps[HVACMODE_DPS] = True
  94. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  95. self.dps[HVACMODE_DPS] = False
  96. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  97. self.dps[HVACMODE_DPS] = None
  98. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  99. def test_hvac_modes(self):
  100. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  101. async def test_turn_on(self):
  102. async with assert_device_properties_set(
  103. self.subject._device, {HVACMODE_DPS: True}
  104. ):
  105. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  106. async def test_turn_off(self):
  107. async with assert_device_properties_set(
  108. self.subject._device, {HVACMODE_DPS: False}
  109. ):
  110. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  111. def test_preset_mode(self):
  112. self.dps[PRESET_DPS] = False
  113. self.assertEqual(self.subject.preset_mode, "Silent")
  114. self.dps[PRESET_DPS] = True
  115. self.assertEqual(self.subject.preset_mode, "Smart")
  116. self.dps[PRESET_DPS] = None
  117. self.assertIs(self.subject.preset_mode, None)
  118. def test_preset_modes(self):
  119. self.assertCountEqual(self.subject.preset_modes, ["Silent", "Smart"])
  120. async def test_set_preset_mode_to_silent(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {PRESET_DPS: False},
  124. ):
  125. await self.subject.async_set_preset_mode("Silent")
  126. async def test_set_preset_mode_to_smart(self):
  127. async with assert_device_properties_set(
  128. self.subject._device,
  129. {PRESET_DPS: True},
  130. ):
  131. await self.subject.async_set_preset_mode("Smart")
  132. def test_device_state_attributes(self):
  133. self.dps[POWERLEVEL_DPS] = 50
  134. self.dps[OPMODE_DPS] = "cool"
  135. self.dps[UNKNOWN107_DPS] = 1
  136. self.dps[UNKNOWN108_DPS] = 2
  137. self.dps[UNKNOWN115_DPS] = 3
  138. self.dps[UNKNOWN116_DPS] = 4
  139. self.assertDictEqual(
  140. self.subject.device_state_attributes,
  141. {
  142. "power_level": 50,
  143. "operating_mode": "cool",
  144. "unknown_107": 1,
  145. "unknown_108": 2,
  146. "unknown_115": 3,
  147. "unknown_116": 4,
  148. },
  149. )