test_ips_pro_heatpump.py 5.8 KB

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