test_poolex_qline_heatpump.py 4.3 KB

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