test_poolex_qline_heatpump.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. )
  56. def test_icon(self):
  57. self.dps[HVACMODE_DPS] = True
  58. self.dps[MODE_DPS] = "heating"
  59. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  60. self.dps[MODE_DPS] = "cold"
  61. self.assertEqual(self.subject.icon, "mdi:snowflake")
  62. self.dps[MODE_DPS] = "mute"
  63. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  64. self.dps[ERROR_DPS] = 1
  65. self.assertEqual(self.subject.icon, "mdi:water-pump-off")
  66. self.dps[HVACMODE_DPS] = False
  67. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  68. def test_temperature_unit_returns_celsius(self):
  69. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  70. def test_current_temperature(self):
  71. self.dps[CURRENTTEMP_DPS] = 25
  72. self.assertEqual(self.subject.current_temperature, 25)
  73. def test_hvac_mode(self):
  74. self.dps[HVACMODE_DPS] = True
  75. self.dps[MODE_DPS] = "heating"
  76. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  77. self.dps[MODE_DPS] = "cold"
  78. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  79. self.dps[MODE_DPS] = "mute"
  80. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  81. self.dps[HVACMODE_DPS] = False
  82. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  83. def test_hvac_modes(self):
  84. self.assertCountEqual(
  85. self.subject.hvac_modes,
  86. [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT, HVACMode.HEAT_COOL],
  87. )
  88. async def test_hvac_mode_heat(self):
  89. async with assert_device_properties_set(
  90. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "heating"}
  91. ):
  92. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  93. async def test_hvac_mode_cool(self):
  94. async with assert_device_properties_set(
  95. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "cold"}
  96. ):
  97. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  98. async def test_hvac_mode_mute(self):
  99. async with assert_device_properties_set(
  100. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "mute"}
  101. ):
  102. await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
  103. async def test_turn_off(self):
  104. async with assert_device_properties_set(
  105. self.subject._device, {HVACMODE_DPS: False}
  106. ):
  107. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  108. def test_error_state(self):
  109. self.dps[ERROR_DPS] = 0
  110. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  111. self.dps[ERROR_DPS] = 1
  112. self.assertEqual(
  113. self.subject.extra_state_attributes,
  114. {"error": "Water flow protection"},
  115. )
  116. self.dps[ERROR_DPS] = 2
  117. self.assertEqual(
  118. self.subject.extra_state_attributes,
  119. {"error": "Anti-freeze protection"},
  120. )
  121. self.dps[ERROR_DPS] = 4
  122. self.assertEqual(
  123. self.subject.extra_state_attributes,
  124. {"error": 4},
  125. )