test_poolex_qline_heatpump.py 4.3 KB

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