test_poolex_qline_heatpump.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_defrost",
  40. "testdata": (2, 0),
  41. },
  42. ],
  43. )
  44. self.mark_secondary(
  45. [
  46. "binary_sensor_water_flow",
  47. "binary_sensor_defrost",
  48. "binary_sensor_problem",
  49. ]
  50. )
  51. def test_supported_features(self):
  52. self.assertEqual(
  53. self.subject.supported_features,
  54. ClimateEntityFeature.TARGET_TEMPERATURE
  55. | ClimateEntityFeature.TURN_OFF
  56. | ClimateEntityFeature.TURN_ON,
  57. )
  58. def test_temperature_unit_returns_celsius(self):
  59. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  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, HVACMode.HEAT)
  67. self.dps[MODE_DPS] = "cold"
  68. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  69. self.dps[MODE_DPS] = "mute"
  70. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT_COOL)
  71. self.dps[HVACMODE_DPS] = False
  72. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  73. def test_hvac_modes(self):
  74. self.assertCountEqual(
  75. self.subject.hvac_modes,
  76. [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT, HVACMode.HEAT_COOL],
  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(HVACMode.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(HVACMode.COOL)
  88. async def test_hvac_mode_mute(self):
  89. async with assert_device_properties_set(
  90. self.subject._device, {HVACMODE_DPS: True, MODE_DPS: "mute"}
  91. ):
  92. await self.subject.async_set_hvac_mode(HVACMode.HEAT_COOL)
  93. async def test_turn_off(self):
  94. async with assert_device_properties_set(
  95. self.subject._device, {HVACMODE_DPS: False}
  96. ):
  97. await self.subject.async_set_hvac_mode(HVACMode.OFF)