test_hydrotherm_dynamicx8.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.water_heater import (
  3. STATE_ECO,
  4. STATE_ELECTRIC,
  5. STATE_HEAT_PUMP,
  6. STATE_HIGH_DEMAND,
  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. def setUp(self):
  26. self.setUpForConfig(
  27. "hydrotherm_dynamic_x8_water_heater.yaml", HYDROTHERM_DYNAMICX8_PAYLOAD
  28. )
  29. self.subject = self.entities.get("water_heater")
  30. self.setUpBasicBinarySensor(
  31. ERROR_DP,
  32. self.entities.get("binary_sensor_problem"),
  33. device_class=BinarySensorDeviceClass.PROBLEM,
  34. testdata=(1, 0),
  35. )
  36. self.mark_secondary(["binary_sensor_problem"])
  37. def test_supported_features(self):
  38. self.assertEqual(
  39. self.subject.supported_features,
  40. WaterHeaterEntityFeature.OPERATION_MODE | WaterHeaterEntityFeature.ON_OFF,
  41. )
  42. def test_temperature_unit_returns_celsius(self):
  43. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  44. def test_precision(self):
  45. self.assertEqual(self.subject.precision, PRECISION_WHOLE)
  46. def test_current_temperature(self):
  47. self.dps[CURRENTTEMP_DP] = 55
  48. self.assertEqual(self.subject.current_temperature, 55)
  49. def test_min_temp(self):
  50. self.assertEqual(self.subject.min_temp, 15.0)
  51. def test_max_temp(self):
  52. self.assertEqual(self.subject.max_temp, 75.0)
  53. def test_target_temperature(self):
  54. self.dps[TEMPERATURE_DP] = 61
  55. self.assertEqual(self.subject.target_temperature, 61)
  56. def test_target_temperature_step(self):
  57. self.assertEqual(self.subject.target_temperature_step, 1)
  58. def test_operation_list(self):
  59. self.assertCountEqual(
  60. self.subject.operation_list,
  61. [
  62. STATE_ECO,
  63. STATE_ELECTRIC,
  64. STATE_HEAT_PUMP,
  65. STATE_HIGH_DEMAND,
  66. STATE_PERFORMANCE,
  67. STATE_OFF,
  68. ],
  69. )
  70. def test_current_operation(self):
  71. self.dps[POWER_DP] = True
  72. self.dps[MODE_DP] = "ECO"
  73. self.assertEqual(self.subject.current_operation, STATE_ECO)
  74. self.dps[MODE_DP] = "STANDARD"
  75. self.assertEqual(self.subject.current_operation, STATE_HEAT_PUMP)
  76. self.dps[MODE_DP] = "HYBRID"
  77. self.assertEqual(self.subject.current_operation, STATE_HIGH_DEMAND)
  78. self.dps[MODE_DP] = "HYBRID1"
  79. self.assertEqual(self.subject.current_operation, STATE_PERFORMANCE)
  80. self.dps[MODE_DP] = "ELEMENT"
  81. self.assertEqual(self.subject.current_operation, STATE_ELECTRIC)
  82. self.dps[POWER_DP] = False
  83. self.assertEqual(self.subject.current_operation, STATE_OFF)
  84. def test_is_away_mode_is_none_when_unsupported(self):
  85. self.assertIsNone(self.subject.is_away_mode_on)
  86. async def test_set_temperature_fails(self):
  87. with self.assertRaises(TypeError):
  88. await self.subject.async_set_temperature(temperature=65)
  89. async def test_set_operation_mode_to_eco(self):
  90. async with assert_device_properties_set(
  91. self.subject._device,
  92. {POWER_DP: True, MODE_DP: "ECO"},
  93. ):
  94. await self.subject.async_set_operation_mode(STATE_ECO)
  95. async def test_set_operation_mode_with_temperature_service(self):
  96. async with assert_device_properties_set(
  97. self.subject._device,
  98. {POWER_DP: True, MODE_DP: "ECO"},
  99. ):
  100. await self.subject.async_set_temperature(operation_mode=STATE_ECO)
  101. async def test_set_operation_mode_to_heat_pump(self):
  102. async with assert_device_properties_set(
  103. self.subject._device,
  104. {POWER_DP: True, MODE_DP: "STANDARD"},
  105. ):
  106. await self.subject.async_set_operation_mode(STATE_HEAT_PUMP)
  107. async def test_set_operation_mode_to_electric(self):
  108. async with assert_device_properties_set(
  109. self.subject._device,
  110. {POWER_DP: True, MODE_DP: "ELEMENT"},
  111. ):
  112. await self.subject.async_set_operation_mode(STATE_ELECTRIC)
  113. async def test_set_operation_mode_to_highdemand(self):
  114. async with assert_device_properties_set(
  115. self.subject._device,
  116. {POWER_DP: True, MODE_DP: "HYBRID"},
  117. ):
  118. await self.subject.async_set_operation_mode(STATE_HIGH_DEMAND)
  119. async def test_set_operation_mode_to_performance(self):
  120. async with assert_device_properties_set(
  121. self.subject._device,
  122. {POWER_DP: True, MODE_DP: "HYBRID1"},
  123. ):
  124. await self.subject.async_set_operation_mode(STATE_PERFORMANCE)
  125. async def test_set_operation_mode_to_off(self):
  126. async with assert_device_properties_set(
  127. self.subject._device,
  128. {POWER_DP: False},
  129. ):
  130. await self.subject.async_set_operation_mode(STATE_OFF)
  131. async def test_turn_on(self):
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {POWER_DP: True},
  135. ):
  136. await self.subject.async_turn_on()
  137. async def test_turn_off(self):
  138. async with assert_device_properties_set(
  139. self.subject._device,
  140. {POWER_DP: False},
  141. ):
  142. await self.subject.async_turn_off()
  143. async def test_turn_away_mode_on_fails(self):
  144. with self.assertRaises(NotImplementedError):
  145. await self.subject.async_turn_away_mode_on()
  146. async def test_turn_away_mode_off_fails(self):
  147. with self.assertRaises(NotImplementedError):
  148. await self.subject.async_turn_away_mode_off()
  149. def test_basic_bsensor_extra_state_attributes(self):
  150. self.dps[ERROR_DP] = 2
  151. self.assertDictEqual(
  152. self.basicBSensor.extra_state_attributes,
  153. {"fault_code": 2},
  154. )