test_poolex_qline_heatpump.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.climate.const import (
  3. HVAC_MODE_COOL,
  4. HVAC_MODE_HEAT,
  5. HVAC_MODE_OFF,
  6. SUPPORT_TARGET_TEMPERATURE,
  7. )
  8. from homeassistant.const import STATE_UNAVAILABLE
  9. from ..const import POOLEX_QLINE_HEATPUMP_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from ..mixins.binary_sensor import BasicBinarySensorTests
  12. from ..mixins.climate import TargetTemperatureTests
  13. from .base_device_tests import TuyaDeviceTestCase
  14. HVACMODE_DPS = "1"
  15. MODE_DPS = "2"
  16. TEMPERATURE_DPS = "4"
  17. CURRENTTEMP_DPS = "16"
  18. ERROR_DPS = "15"
  19. class TestPoolexSilverlineHeatpump(
  20. BasicBinarySensorTests,
  21. TargetTemperatureTests,
  22. TuyaDeviceTestCase,
  23. ):
  24. __test__ = True
  25. def setUp(self):
  26. self.setUpForConfig("poolex_qline_heatpump.yaml", POOLEX_QLINE_HEATPUMP_PAYLOAD)
  27. self.subject = self.entities.get("climate")
  28. self.setUpTargetTemperature(
  29. TEMPERATURE_DPS,
  30. self.subject,
  31. min=8,
  32. max=40,
  33. )
  34. self.setUpBasicBinarySensor(
  35. ERROR_DPS,
  36. self.entities.get("binary_sensor_water_flow"),
  37. device_class=BinarySensorDeviceClass.PROBLEM,
  38. testdata=(1, 0),
  39. )
  40. self.mark_secondary(["binary_sensor_water_flow"])
  41. def test_supported_features(self):
  42. self.assertEqual(
  43. self.subject.supported_features,
  44. SUPPORT_TARGET_TEMPERATURE,
  45. )
  46. def test_icon(self):
  47. self.dps[HVACMODE_DPS] = True
  48. self.dps[MODE_DPS] = "heating"
  49. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  50. self.dps[MODE_DPS] = "cold"
  51. self.assertEqual(self.subject.icon, "mdi:snowflake")
  52. self.dps[ERROR_DPS] = 1
  53. self.assertEqual(self.subject.icon, "mdi:water-pump-off")
  54. self.dps[HVACMODE_DPS] = False
  55. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  56. def test_temperature_unit_returns_device_temperature_unit(self):
  57. self.assertEqual(
  58. self.subject.temperature_unit, self.subject._device.temperature_unit
  59. )
  60. def test_current_temperature(self):
  61. self.dps[CURRENTTEMP_DPS] = 25
  62. self.assertEqual(self.subject.current_temperature, 25)
  63. def test_hvac_mode(self):
  64. self.dps[HVACMODE_DPS] = True
  65. self.dps[MODE_DPS] = "heating"
  66. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  67. self.dps[MODE_DPS] = "cold"
  68. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  69. self.dps[HVACMODE_DPS] = False
  70. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  71. self.dps[HVACMODE_DPS] = None
  72. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  73. def test_hvac_modes(self):
  74. self.assertCountEqual(
  75. self.subject.hvac_modes,
  76. [HVAC_MODE_OFF, HVAC_MODE_COOL, HVAC_MODE_HEAT],
  77. )
  78. async def test_hvac_mode_heat(self):
  79. async with assert_device_properties_set(
  80. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "heating"}
  81. ):
  82. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  83. async def test_hvac_mode_cool(self):
  84. async with assert_device_properties_set(
  85. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "cold"}
  86. ):
  87. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  88. async def test_turn_off(self):
  89. async with assert_device_properties_set(
  90. self.subject._device, {HVACMODE_DPS: False}
  91. ):
  92. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  93. def test_error_state(self):
  94. self.dps[ERROR_DPS] = 0
  95. self.assertEqual(self.subject.extra_state_attributes, {"error": "OK"})
  96. self.dps[ERROR_DPS] = 1
  97. self.assertEqual(
  98. self.subject.extra_state_attributes,
  99. {"error": "Water Flow Protection"},
  100. )
  101. self.dps[ERROR_DPS] = 2
  102. self.assertEqual(
  103. self.subject.extra_state_attributes,
  104. {"error": 2},
  105. )