test_gardenpac_heatpump.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 TestGardenPACPoolHeatpump(
  31. BasicBinarySensorTests,
  32. BasicSensorTests,
  33. TargetTemperatureTests,
  34. TuyaDeviceTestCase,
  35. ):
  36. __test__ = True
  37. def setUp(self):
  38. self.setUpForConfig("gardenpac_heatpump.yaml", GARDENPAC_HEATPUMP_PAYLOAD)
  39. self.subject = self.entities.get("climate")
  40. self.setUpTargetTemperature(
  41. TEMPERATURE_DPS,
  42. self.subject,
  43. min=18,
  44. max=45,
  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[ERROR_DPS] = 0
  70. self.dps[HVACMODE_DPS] = True
  71. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  72. self.dps[ERROR_DPS] = 4
  73. self.assertEqual(self.subject.icon, "mdi:water-pump-off")
  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(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  79. self.dps[UNITS_DPS] = True
  80. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  81. def test_minimum_fahrenheit_temperature(self):
  82. self.dps[UNITS_DPS] = False
  83. self.dps[MINTEMP_DPS] = 60
  84. self.assertEqual(self.subject.min_temp, 60)
  85. def test_maximum_fahrenheit_temperature(self):
  86. self.dps[UNITS_DPS] = False
  87. self.dps[MAXTEMP_DPS] = 115
  88. self.assertEqual(self.subject.max_temp, 115)
  89. def test_current_temperature(self):
  90. self.dps[CURRENTTEMP_DPS] = 25
  91. self.assertEqual(self.subject.current_temperature, 25)
  92. def test_hvac_mode(self):
  93. self.dps[HVACMODE_DPS] = True
  94. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  95. self.dps[HVACMODE_DPS] = False
  96. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  97. def test_hvac_modes(self):
  98. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  99. async def test_turn_on(self):
  100. async with assert_device_properties_set(
  101. self.subject._device, {HVACMODE_DPS: True}
  102. ):
  103. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  104. async def test_turn_off(self):
  105. async with assert_device_properties_set(
  106. self.subject._device, {HVACMODE_DPS: False}
  107. ):
  108. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  109. def test_preset_mode(self):
  110. self.dps[PRESET_DPS] = False
  111. self.assertEqual(self.subject.preset_mode, "Silent")
  112. self.dps[PRESET_DPS] = True
  113. self.assertEqual(self.subject.preset_mode, "Smart")
  114. self.dps[PRESET_DPS] = None
  115. self.assertIs(self.subject.preset_mode, None)
  116. def test_preset_modes(self):
  117. self.assertCountEqual(self.subject.preset_modes, ["Silent", "Smart"])
  118. async def test_set_preset_mode_to_silent(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {PRESET_DPS: False},
  122. ):
  123. await self.subject.async_set_preset_mode("Silent")
  124. async def test_set_preset_mode_to_smart(self):
  125. async with assert_device_properties_set(
  126. self.subject._device,
  127. {PRESET_DPS: True},
  128. ):
  129. await self.subject.async_set_preset_mode("Smart")
  130. def test_hvac_action(self):
  131. self.dps[HVACMODE_DPS] = True
  132. self.dps[OPMODE_DPS] = "heating"
  133. self.assertEqual(self.subject.hvac_action, HVACAction.HEATING)
  134. self.dps[OPMODE_DPS] = "warm"
  135. self.assertEqual(self.subject.hvac_action, HVACAction.IDLE)
  136. self.dps[HVACMODE_DPS] = False
  137. self.assertEqual(self.subject.hvac_action, HVACAction.OFF)
  138. def test_extra_state_attributes(self):
  139. self.dps[ERROR_DPS] = 3
  140. self.dps[ERROR2_DPS] = 4
  141. self.assertDictEqual(
  142. self.subject.extra_state_attributes,
  143. {
  144. "error": 3,
  145. "error_2": 4,
  146. },
  147. )