test_hydrotherm_dynamicx8.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.water_heater import (
  3. STATE_ECO,
  4. STATE_ELECTRIC,
  5. STATE_HIGH_DEMAND,
  6. STATE_HEAT_PUMP,
  7. STATE_OFF,
  8. STATE_PERFORMANCE,
  9. WaterHeaterEntityFeature,
  10. )
  11. from homeassistant.const import PRECISION_WHOLE, UnitOfTemperature
  12. from ..const import HYDROTHERM_DYNAMICX8_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from ..mixins.binary_sensor import BasicBinarySensorTests
  15. from .base_device_tests import TuyaDeviceTestCase
  16. POWER_DP = "1"
  17. TEMPERATURE_DP = "2"
  18. CURRENTTEMP_DP = "3"
  19. MODE_DP = "4"
  20. ERROR_DP = "21"
  21. class TestHydrothermDynamicX8(
  22. BasicBinarySensorTests,
  23. TuyaDeviceTestCase,
  24. ):
  25. __test__ = True
  26. def setUp(self):
  27. self.setUpForConfig(
  28. "hydrotherm_dynamic_x8_water_heater.yaml", HYDROTHERM_DYNAMICX8_PAYLOAD
  29. )
  30. self.subject = self.entities.get("water_heater")
  31. self.setUpBasicBinarySensor(
  32. ERROR_DP,
  33. self.entities.get("binary_sensor_fault"),
  34. device_class=BinarySensorDeviceClass.PROBLEM,
  35. testdata=(1, 0),
  36. )
  37. self.mark_secondary(["binary_sensor_fault"])
  38. def test_supported_features(self):
  39. self.assertEqual(
  40. self.subject.supported_features,
  41. WaterHeaterEntityFeature.OPERATION_MODE,
  42. )
  43. def test_temperature_unit_returns_celsius(self):
  44. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  45. def test_precision(self):
  46. self.assertEqual(self.subject.precision, PRECISION_WHOLE)
  47. def test_current_temperature(self):
  48. self.dps[CURRENTTEMP_DP] = 55
  49. self.assertEqual(self.subject.current_temperature, 55)
  50. def test_min_temp(self):
  51. self.assertEqual(self.subject.min_temp, 15)
  52. def test_max_temp(self):
  53. self.assertEqual(self.subject.max_temp, 75)
  54. def test_target_temperature(self):
  55. self.dps[TEMPERATURE_DP] = 61
  56. self.assertEqual(self.subject.target_temperature, 61)
  57. def test_target_temperature_step(self):
  58. self.assertEqual(self.subject.target_temperature_step, 1)
  59. def test_operation_list(self):
  60. self.assertCountEqual(
  61. self.subject.operation_list,
  62. [
  63. STATE_ECO,
  64. STATE_ELECTRIC,
  65. STATE_HEAT_PUMP,
  66. STATE_HIGH_DEMAND,
  67. STATE_PERFORMANCE,
  68. STATE_OFF,
  69. ],
  70. )
  71. def test_current_operation(self):
  72. self.dps[POWER_DP] = True
  73. self.dps[MODE_DP] = "ECO"
  74. self.assertEqual(self.subject.current_operation, STATE_ECO)
  75. self.dps[MODE_DP] = "STANDARD"
  76. self.assertEqual(self.subject.current_operation, STATE_HEAT_PUMP)
  77. self.dps[MODE_DP] = "HYBRID"
  78. self.assertEqual(self.subject.current_operation, STATE_HIGH_DEMAND)
  79. self.dps[MODE_DP] = "HYBRID1"
  80. self.assertEqual(self.subject.current_operation, STATE_PERFORMANCE)
  81. self.dps[MODE_DP] = "ELEMENT"
  82. self.assertEqual(self.subject.current_operation, STATE_ELECTRIC)
  83. self.dps[POWER_DP] = False
  84. self.assertEqual(self.subject.current_operation, STATE_OFF)
  85. async def test_set_temperature_fails(self):
  86. with self.assertRaises(TypeError):
  87. await self.subject.async_set_temperature(temperature=65)
  88. async def test_set_operation_mode_to_eco(self):
  89. async with assert_device_properties_set(
  90. self.subject._device,
  91. {POWER_DP: True, MODE_DP: "ECO"},
  92. ):
  93. await self.subject.async_set_operation_mode(STATE_ECO)
  94. async def test_set_operation_mode_with_temperature_service(self):
  95. async with assert_device_properties_set(
  96. self.subject._device,
  97. {POWER_DP: True, MODE_DP: "ECO"},
  98. ):
  99. await self.subject.async_set_temperature(operation_mode=STATE_ECO)
  100. async def test_set_operation_mode_to_heat_pump(self):
  101. async with assert_device_properties_set(
  102. self.subject._device,
  103. {POWER_DP: True, MODE_DP: "STANDARD"},
  104. ):
  105. await self.subject.async_set_operation_mode(STATE_HEAT_PUMP)
  106. async def test_set_operation_mode_to_electric(self):
  107. async with assert_device_properties_set(
  108. self.subject._device,
  109. {POWER_DP: True, MODE_DP: "ELEMENT"},
  110. ):
  111. await self.subject.async_set_operation_mode(STATE_ELECTRIC)
  112. async def test_set_operation_mode_to_highdemand(self):
  113. async with assert_device_properties_set(
  114. self.subject._device,
  115. {POWER_DP: True, MODE_DP: "HYBRID"},
  116. ):
  117. await self.subject.async_set_operation_mode(STATE_HIGH_DEMAND)
  118. async def test_set_operation_mode_to_performance(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {POWER_DP: True, MODE_DP: "HYBRID1"},
  122. ):
  123. await self.subject.async_set_operation_mode(STATE_PERFORMANCE)
  124. async def test_set_operation_mode_to_off(self):
  125. async with assert_device_properties_set(
  126. self.subject._device,
  127. {POWER_DP: False},
  128. ):
  129. await self.subject.async_set_operation_mode(STATE_OFF)