test_ips_pro_heatpump.py 5.2 KB

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