test_ips_pro_heatpump.py 5.6 KB

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