test_poolex_qline_heatpump.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.climate.const import ClimateEntityFeature, HVACMode
  3. from homeassistant.const import UnitOfTemperature
  4. from ..const import POOLEX_QLINE_HEATPUMP_PAYLOAD
  5. from ..helpers import assert_device_properties_set
  6. from ..mixins.binary_sensor import MultiBinarySensorTests
  7. from ..mixins.climate import TargetTemperatureTests
  8. from .base_device_tests import TuyaDeviceTestCase
  9. HVACMODE_DPS = "1"
  10. MODE_DPS = "2"
  11. TEMPERATURE_DPS = "4"
  12. CURRENTTEMP_DPS = "16"
  13. ERROR_DPS = "15"
  14. class TestPoolexQlineHeatpump(
  15. MultiBinarySensorTests,
  16. TargetTemperatureTests,
  17. TuyaDeviceTestCase,
  18. ):
  19. __test__ = True
  20. def setUp(self):
  21. self.setUpForConfig("poolex_qline_heatpump.yaml", POOLEX_QLINE_HEATPUMP_PAYLOAD)
  22. self.subject = self.entities.get("climate")
  23. self.setUpTargetTemperature(
  24. TEMPERATURE_DPS,
  25. self.subject,
  26. min=8.0,
  27. max=40.0,
  28. )
  29. self.setUpMultiBinarySensors(
  30. [
  31. {
  32. "dps": ERROR_DPS,
  33. "name": "binary_sensor_water_flow",
  34. "device_class": BinarySensorDeviceClass.PROBLEM,
  35. "testdata": (1, 0),
  36. },
  37. {
  38. "dps": ERROR_DPS,
  39. "name": "binary_sensor_anti_freeze",
  40. "device_class": BinarySensorDeviceClass.COLD,
  41. "testdata": (2, 0),
  42. },
  43. ],
  44. )
  45. self.mark_secondary(
  46. [
  47. "binary_sensor_water_flow",
  48. "binary_sensor_anti_freeze",
  49. ]
  50. )
  51. def test_supported_features(self):
  52. self.assertEqual(
  53. self.subject.supported_features,
  54. ClimateEntityFeature.TARGET_TEMPERATURE
  55. | ClimateEntityFeature.TURN_OFF
  56. | ClimateEntityFeature.TURN_ON,
  57. )
  58. def test_icon(self):
  59. self.dps[HVACMODE_DPS] = True
  60. self.dps[MODE_DPS] = "heating"
  61. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  62. self.dps[MODE_DPS] = "cold"
  63. self.assertEqual(self.subject.icon, "mdi:snowflake")
  64. self.dps[MODE_DPS] = "mute"
  65. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  66. self.dps[ERROR_DPS] = 1
  67. self.assertEqual(self.subject.icon, "mdi:water-pump-off")
  68. self.dps[HVACMODE_DPS] = False
  69. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  70. def test_temperature_unit_returns_celsius(self):
  71. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  72. def test_current_temperature(self):
  73. self.dps[CURRENTTEMP_DPS] = 25
  74. self.assertEqual(self.subject.current_temperature, 25)
  75. def test_hvac_mode(self):
  76. self.dps[HVACMODE_DPS] = True
  77. self.dps[MODE_DPS] = "heating"
  78. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  79. self.dps[MODE_DPS] = "cold"
  80. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  81. self.dps[MODE_DPS] = "mute"
  82. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  83. self.dps[HVACMODE_DPS] = False
  84. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  85. def test_hvac_modes(self):
  86. self.assertCountEqual(
  87. self.subject.hvac_modes,
  88. [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT, HVACMode.HEAT_COOL],
  89. )
  90. async def test_hvac_mode_heat(self):
  91. async with assert_device_properties_set(
  92. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "heating"}
  93. ):
  94. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  95. async def test_hvac_mode_cool(self):
  96. async with assert_device_properties_set(
  97. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "cold"}
  98. ):
  99. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  100. async def test_hvac_mode_mute(self):
  101. async with assert_device_properties_set(
  102. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "mute"}
  103. ):
  104. await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
  105. async def test_turn_off(self):
  106. async with assert_device_properties_set(
  107. self.subject._device, {HVACMODE_DPS: False}
  108. ):
  109. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  110. def test_error_state(self):
  111. self.dps[ERROR_DPS] = 0
  112. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  113. self.dps[ERROR_DPS] = 1
  114. self.assertEqual(
  115. self.subject.extra_state_attributes,
  116. {"error": "Water flow protection"},
  117. )
  118. self.dps[ERROR_DPS] = 2
  119. self.assertEqual(
  120. self.subject.extra_state_attributes,
  121. {"error": "Anti-freeze protection"},
  122. )
  123. self.dps[ERROR_DPS] = 4
  124. self.assertEqual(
  125. self.subject.extra_state_attributes,
  126. {"error": 4},
  127. )