4
0

test_poolex_qline_heatpump.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 BasicBinarySensorTests
  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 TestPoolexSilverlineHeatpump(
  15. BasicBinarySensorTests,
  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,
  27. max=40,
  28. )
  29. self.setUpBasicBinarySensor(
  30. ERROR_DPS,
  31. self.entities.get("binary_sensor_water_flow"),
  32. device_class=BinarySensorDeviceClass.PROBLEM,
  33. testdata=(1, 0),
  34. )
  35. self.mark_secondary(["binary_sensor_water_flow"])
  36. def test_supported_features(self):
  37. self.assertEqual(
  38. self.subject.supported_features,
  39. ClimateEntityFeature.TARGET_TEMPERATURE,
  40. )
  41. def test_icon(self):
  42. self.dps[HVACMODE_DPS] = True
  43. self.dps[MODE_DPS] = "heating"
  44. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  45. self.dps[MODE_DPS] = "cold"
  46. self.assertEqual(self.subject.icon, "mdi:snowflake")
  47. self.dps[MODE_DPS] = "mute"
  48. self.assertEqual(self.subject.icon, "mdi:hot-tub")
  49. self.dps[ERROR_DPS] = 1
  50. self.assertEqual(self.subject.icon, "mdi:water-pump-off")
  51. self.dps[HVACMODE_DPS] = False
  52. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  53. def test_temperature_unit_returns_celsius(self):
  54. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  55. def test_current_temperature(self):
  56. self.dps[CURRENTTEMP_DPS] = 25
  57. self.assertEqual(self.subject.current_temperature, 25)
  58. def test_hvac_mode(self):
  59. self.dps[HVACMODE_DPS] = True
  60. self.dps[MODE_DPS] = "heating"
  61. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  62. self.dps[MODE_DPS] = "cold"
  63. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  64. self.dps[MODE_DPS] = "mute"
  65. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  66. self.dps[HVACMODE_DPS] = False
  67. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  68. def test_hvac_modes(self):
  69. self.assertCountEqual(
  70. self.subject.hvac_modes,
  71. [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT, HVACMode.HEAT_COOL],
  72. )
  73. async def test_hvac_mode_heat(self):
  74. async with assert_device_properties_set(
  75. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "heating"}
  76. ):
  77. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  78. async def test_hvac_mode_cool(self):
  79. async with assert_device_properties_set(
  80. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "cold"}
  81. ):
  82. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  83. async def test_hvac_mode_mute(self):
  84. async with assert_device_properties_set(
  85. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "mute"}
  86. ):
  87. await self.subject.async_set_hvac_mode(HVACMode.HEAT_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(HVACMode.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. )