test_fairland_iphcr15_heatpump.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 GARDENPAC_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 = "117"
  30. class TestFairlandIPHCR15PoolHeatpump(
  31. BasicBinarySensorTests,
  32. BasicSensorTests,
  33. TargetTemperatureTests,
  34. TuyaDeviceTestCase,
  35. ):
  36. __test__ = True
  37. def setUp(self):
  38. self.setUpForConfig(
  39. "fairland_iphcr15_heatpump.yaml", GARDENPAC_HEATPUMP_PAYLOAD
  40. )
  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=SensorDeviceClass.POWER_FACTOR,
  53. state_class="measurement",
  54. )
  55. self.setUpBasicBinarySensor(
  56. ERROR_DPS,
  57. self.entities.get("binary_sensor_water_flow"),
  58. device_class=BinarySensorDeviceClass.PROBLEM,
  59. testdata=(4, 0),
  60. )
  61. self.mark_secondary(["sensor_power_level", "binary_sensor_water_flow"])
  62. def test_supported_features(self):
  63. self.assertEqual(
  64. self.subject.supported_features,
  65. (
  66. ClimateEntityFeature.TARGET_TEMPERATURE
  67. | ClimateEntityFeature.PRESET_MODE
  68. ),
  69. )
  70. def test_icon(self):
  71. self.dps[ERROR_DPS] = 0
  72. self.dps[HVACMODE_DPS] = True
  73. self.dps[OPMODE_DPS] = "warm"
  74. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  75. self.dps[OPMODE_DPS] = "cool"
  76. self.assertEqual(self.subject.icon, "mdi:snowflake")
  77. self.dps[OPMODE_DPS] = "smart"
  78. self.assertEqual(self.subject.icon, "mdi:refresh-auto")
  79. self.dps[ERROR_DPS] = 4
  80. self.assertEqual(self.subject.icon, "mdi:water-pump-off")
  81. self.dps[HVACMODE_DPS] = False
  82. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  83. def test_temperature_unit(self):
  84. self.dps[UNITS_DPS] = False
  85. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  86. self.dps[UNITS_DPS] = True
  87. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  88. def test_minimum_fahrenheit_temperature(self):
  89. self.dps[UNITS_DPS] = False
  90. self.dps[MINTEMP_DPS] = 60
  91. self.assertEqual(self.subject.min_temp, 60)
  92. def test_maximum_fahrenheit_temperature(self):
  93. self.dps[UNITS_DPS] = False
  94. self.dps[MAXTEMP_DPS] = 115
  95. self.assertEqual(self.subject.max_temp, 115)
  96. def test_current_temperature(self):
  97. self.dps[CURRENTTEMP_DPS] = 25
  98. self.assertEqual(self.subject.current_temperature, 25)
  99. def test_hvac_mode(self):
  100. self.dps[HVACMODE_DPS] = True
  101. self.dps[OPMODE_DPS] = "warm"
  102. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  103. self.dps[OPMODE_DPS] = "cool"
  104. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  105. self.dps[OPMODE_DPS] = "smart"
  106. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  107. self.dps[HVACMODE_DPS] = False
  108. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  109. def test_hvac_modes(self):
  110. self.assertCountEqual(
  111. self.subject.hvac_modes,
  112. [HVACMode.OFF, HVACMode.HEAT, HVACMode.COOL, HVACMode.HEAT_COOL],
  113. )
  114. async def test_turn_on_heat(self):
  115. async with assert_device_properties_set(
  116. self.subject._device, {HVACMODE_DPS: True, OPMODE_DPS: "warm"}
  117. ):
  118. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  119. async def test_turn_on_cool(self):
  120. async with assert_device_properties_set(
  121. self.subject._device, {HVACMODE_DPS: True, OPMODE_DPS: "cool"}
  122. ):
  123. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  124. async def test_turn_on_smart(self):
  125. async with assert_device_properties_set(
  126. self.subject._device, {HVACMODE_DPS: True, OPMODE_DPS: "smart"}
  127. ):
  128. await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
  129. async def test_turn_off(self):
  130. async with assert_device_properties_set(
  131. self.subject._device, {HVACMODE_DPS: False}
  132. ):
  133. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  134. def test_preset_mode(self):
  135. self.dps[PRESET_DPS] = False
  136. self.assertEqual(self.subject.preset_mode, "Silent")
  137. self.dps[PRESET_DPS] = True
  138. self.assertEqual(self.subject.preset_mode, "Boost")
  139. self.dps[PRESET_DPS] = None
  140. self.assertIs(self.subject.preset_mode, None)
  141. def test_preset_modes(self):
  142. self.assertCountEqual(self.subject.preset_modes, ["Silent", "Boost"])
  143. async def test_set_preset_mode_to_silent(self):
  144. async with assert_device_properties_set(
  145. self.subject._device,
  146. {PRESET_DPS: False},
  147. ):
  148. await self.subject.async_set_preset_mode("Silent")
  149. async def test_set_preset_mode_to_boost(self):
  150. async with assert_device_properties_set(
  151. self.subject._device,
  152. {PRESET_DPS: True},
  153. ):
  154. await self.subject.async_set_preset_mode("Boost")
  155. def test_extra_state_attributes(self):
  156. self.dps[OPMODE_DPS] = "smart"
  157. self.dps[ERROR_DPS] = 3
  158. self.dps[ERROR2_DPS] = 4
  159. self.assertDictEqual(
  160. self.subject.extra_state_attributes,
  161. {
  162. "mode": "smart",
  163. "error": 3,
  164. "error_2": 4,
  165. },
  166. )