test_poolex_qline_heatpump.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_defrost",
  40. "testdata": (2, 0),
  41. },
  42. ],
  43. )
  44. self.mark_secondary(
  45. [
  46. "binary_sensor_water_flow",
  47. "binary_sensor_defrost",
  48. ]
  49. )
  50. def test_supported_features(self):
  51. self.assertEqual(
  52. self.subject.supported_features,
  53. ClimateEntityFeature.TARGET_TEMPERATURE
  54. | ClimateEntityFeature.TURN_OFF
  55. | ClimateEntityFeature.TURN_ON,
  56. )
  57. def test_icon(self):
  58. self.dps[HVACMODE_DPS] = True
  59. self.dps[MODE_DPS] = "heating"
  60. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  61. self.dps[MODE_DPS] = "cold"
  62. self.assertEqual(self.subject.icon, "mdi:snowflake")
  63. self.dps[MODE_DPS] = "mute"
  64. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  65. self.dps[ERROR_DPS] = 1
  66. self.assertEqual(self.subject.icon, "mdi:water-pump-off")
  67. self.dps[HVACMODE_DPS] = False
  68. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  69. def test_temperature_unit_returns_celsius(self):
  70. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  71. def test_current_temperature(self):
  72. self.dps[CURRENTTEMP_DPS] = 25
  73. self.assertEqual(self.subject.current_temperature, 25)
  74. def test_hvac_mode(self):
  75. self.dps[HVACMODE_DPS] = True
  76. self.dps[MODE_DPS] = "heating"
  77. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  78. self.dps[MODE_DPS] = "cold"
  79. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  80. self.dps[MODE_DPS] = "mute"
  81. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  82. self.dps[HVACMODE_DPS] = False
  83. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  84. def test_hvac_modes(self):
  85. self.assertCountEqual(
  86. self.subject.hvac_modes,
  87. [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT, HVACMode.HEAT_COOL],
  88. )
  89. async def test_hvac_mode_heat(self):
  90. async with assert_device_properties_set(
  91. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "heating"}
  92. ):
  93. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  94. async def test_hvac_mode_cool(self):
  95. async with assert_device_properties_set(
  96. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "cold"}
  97. ):
  98. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  99. async def test_hvac_mode_mute(self):
  100. async with assert_device_properties_set(
  101. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "mute"}
  102. ):
  103. await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
  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_error_state(self):
  110. self.dps[ERROR_DPS] = 0
  111. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  112. self.dps[ERROR_DPS] = 1
  113. self.assertEqual(
  114. self.subject.extra_state_attributes,
  115. {"error": "Water flow protection"},
  116. )
  117. self.dps[ERROR_DPS] = 2
  118. self.assertEqual(
  119. self.subject.extra_state_attributes,
  120. {"error": "Anti-freeze protection"},
  121. )
  122. self.dps[ERROR_DPS] = 4
  123. self.assertEqual(
  124. self.subject.extra_state_attributes,
  125. {"error": 4},
  126. )