4
0

test_gardenpac_heatpump.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT,
  3. HVAC_MODE_OFF,
  4. CURRENT_HVAC_HEAT,
  5. CURRENT_HVAC_IDLE,
  6. CURRENT_HVAC_OFF,
  7. SUPPORT_PRESET_MODE,
  8. SUPPORT_TARGET_TEMPERATURE,
  9. )
  10. from homeassistant.const import (
  11. DEVICE_CLASS_POWER_FACTOR,
  12. PERCENTAGE,
  13. STATE_UNAVAILABLE,
  14. TEMP_CELSIUS,
  15. TEMP_FAHRENHEIT,
  16. )
  17. from ..const import GARDENPAC_HEATPUMP_PAYLOAD
  18. from ..helpers import assert_device_properties_set
  19. from ..mixins.climate import TargetTemperatureTests
  20. from ..mixins.sensor import BasicSensorTests
  21. from .base_device_tests import TuyaDeviceTestCase
  22. HVACMODE_DPS = "1"
  23. CURRENTTEMP_DPS = "102"
  24. UNITS_DPS = "103"
  25. POWERLEVEL_DPS = "104"
  26. OPMODE_DPS = "105"
  27. TEMPERATURE_DPS = "106"
  28. UNKNOWN107_DPS = "107"
  29. UNKNOWN108_DPS = "108"
  30. UNKNOWN115_DPS = "115"
  31. UNKNOWN116_DPS = "116"
  32. PRESET_DPS = "117"
  33. class TestGardenPACPoolHeatpump(
  34. BasicSensorTests,
  35. TargetTemperatureTests,
  36. TuyaDeviceTestCase,
  37. ):
  38. __test__ = True
  39. def setUp(self):
  40. self.setUpForConfig("gardenpac_heatpump.yaml", GARDENPAC_HEATPUMP_PAYLOAD)
  41. self.subject = self.entities.get("climate")
  42. self.setUpTargetTemperature(
  43. TEMPERATURE_DPS,
  44. self.subject,
  45. min=18,
  46. max=45,
  47. )
  48. self.setUpBasicSensor(
  49. POWERLEVEL_DPS,
  50. self.entities.get("sensor_power_level"),
  51. unit=PERCENTAGE,
  52. device_class=DEVICE_CLASS_POWER_FACTOR,
  53. state_class="measurement",
  54. )
  55. def test_supported_features(self):
  56. self.assertEqual(
  57. self.subject.supported_features,
  58. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  59. )
  60. def test_icon(self):
  61. self.dps[HVACMODE_DPS] = True
  62. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  63. self.dps[HVACMODE_DPS] = False
  64. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  65. def test_temperature_unit(self):
  66. self.dps[UNITS_DPS] = False
  67. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  68. self.dps[UNITS_DPS] = True
  69. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  70. def test_minimum_fahrenheit_temperature(self):
  71. self.dps[UNITS_DPS] = False
  72. self.assertEqual(self.subject.min_temp, 60)
  73. def test_maximum_fahrenheit_temperature(self):
  74. self.dps[UNITS_DPS] = False
  75. self.assertEqual(self.subject.max_temp, 115)
  76. def test_current_temperature(self):
  77. self.dps[CURRENTTEMP_DPS] = 25
  78. self.assertEqual(self.subject.current_temperature, 25)
  79. def test_hvac_mode(self):
  80. self.dps[HVACMODE_DPS] = True
  81. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  82. self.dps[HVACMODE_DPS] = False
  83. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  84. self.dps[HVACMODE_DPS] = None
  85. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  86. def test_hvac_modes(self):
  87. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  88. async def test_turn_on(self):
  89. async with assert_device_properties_set(
  90. self.subject._device, {HVACMODE_DPS: True}
  91. ):
  92. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  93. async def test_turn_off(self):
  94. async with assert_device_properties_set(
  95. self.subject._device, {HVACMODE_DPS: False}
  96. ):
  97. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  98. def test_preset_mode(self):
  99. self.dps[PRESET_DPS] = False
  100. self.assertEqual(self.subject.preset_mode, "Silent")
  101. self.dps[PRESET_DPS] = True
  102. self.assertEqual(self.subject.preset_mode, "Smart")
  103. self.dps[PRESET_DPS] = None
  104. self.assertIs(self.subject.preset_mode, None)
  105. def test_preset_modes(self):
  106. self.assertCountEqual(self.subject.preset_modes, ["Silent", "Smart"])
  107. async def test_set_preset_mode_to_silent(self):
  108. async with assert_device_properties_set(
  109. self.subject._device,
  110. {PRESET_DPS: False},
  111. ):
  112. await self.subject.async_set_preset_mode("Silent")
  113. async def test_set_preset_mode_to_smart(self):
  114. async with assert_device_properties_set(
  115. self.subject._device,
  116. {PRESET_DPS: True},
  117. ):
  118. await self.subject.async_set_preset_mode("Smart")
  119. def test_hvac_action(self):
  120. self.dps[HVACMODE_DPS] = True
  121. self.dps[OPMODE_DPS] = "heating"
  122. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_HEAT)
  123. self.dps[OPMODE_DPS] = "warm"
  124. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_IDLE)
  125. self.dps[HVACMODE_DPS] = False
  126. self.assertEqual(self.subject.hvac_action, CURRENT_HVAC_OFF)
  127. def test_device_state_attributes(self):
  128. self.dps[POWERLEVEL_DPS] = 50
  129. self.dps[UNKNOWN107_DPS] = 1
  130. self.dps[UNKNOWN108_DPS] = 2
  131. self.dps[UNKNOWN115_DPS] = 3
  132. self.dps[UNKNOWN116_DPS] = 4
  133. self.assertDictEqual(
  134. self.subject.device_state_attributes,
  135. {
  136. "power_level": 50,
  137. "unknown_107": 1,
  138. "unknown_108": 2,
  139. "unknown_115": 3,
  140. "unknown_116": 4,
  141. },
  142. )