test_hydrotherm_dynamicx8.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. __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_problem"),
  34. device_class=BinarySensorDeviceClass.PROBLEM,
  35. testdata=(1, 0),
  36. )
  37. self.mark_secondary(["binary_sensor_problem"])
  38. def test_supported_features(self):
  39. self.assertEqual(
  40. self.subject.supported_features,
  41. WaterHeaterEntityFeature.OPERATION_MODE | WaterHeaterEntityFeature.ON_OFF,
  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.0)
  52. def test_max_temp(self):
  53. self.assertEqual(self.subject.max_temp, 75.0)
  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. def test_is_away_mode_is_none_when_unsupported(self):
  86. self.assertIsNone(self.subject.is_away_mode_on)
  87. async def test_set_temperature_fails(self):
  88. with self.assertRaises(TypeError):
  89. await self.subject.async_set_temperature(temperature=65)
  90. async def test_set_operation_mode_to_eco(self):
  91. async with assert_device_properties_set(
  92. self.subject._device,
  93. {POWER_DP: True, MODE_DP: "ECO"},
  94. ):
  95. await self.subject.async_set_operation_mode(STATE_ECO)
  96. async def test_set_operation_mode_with_temperature_service(self):
  97. async with assert_device_properties_set(
  98. self.subject._device,
  99. {POWER_DP: True, MODE_DP: "ECO"},
  100. ):
  101. await self.subject.async_set_temperature(operation_mode=STATE_ECO)
  102. async def test_set_operation_mode_to_heat_pump(self):
  103. async with assert_device_properties_set(
  104. self.subject._device,
  105. {POWER_DP: True, MODE_DP: "STANDARD"},
  106. ):
  107. await self.subject.async_set_operation_mode(STATE_HEAT_PUMP)
  108. async def test_set_operation_mode_to_electric(self):
  109. async with assert_device_properties_set(
  110. self.subject._device,
  111. {POWER_DP: True, MODE_DP: "ELEMENT"},
  112. ):
  113. await self.subject.async_set_operation_mode(STATE_ELECTRIC)
  114. async def test_set_operation_mode_to_highdemand(self):
  115. async with assert_device_properties_set(
  116. self.subject._device,
  117. {POWER_DP: True, MODE_DP: "HYBRID"},
  118. ):
  119. await self.subject.async_set_operation_mode(STATE_HIGH_DEMAND)
  120. async def test_set_operation_mode_to_performance(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {POWER_DP: True, MODE_DP: "HYBRID1"},
  124. ):
  125. await self.subject.async_set_operation_mode(STATE_PERFORMANCE)
  126. async def test_set_operation_mode_to_off(self):
  127. async with assert_device_properties_set(
  128. self.subject._device,
  129. {POWER_DP: False},
  130. ):
  131. await self.subject.async_set_operation_mode(STATE_OFF)
  132. async def test_turn_on(self):
  133. async with assert_device_properties_set(
  134. self.subject._device,
  135. {POWER_DP: True},
  136. ):
  137. await self.subject.async_turn_on()
  138. async def test_turn_off(self):
  139. async with assert_device_properties_set(
  140. self.subject._device,
  141. {POWER_DP: False},
  142. ):
  143. await self.subject.async_turn_off()
  144. async def test_turn_away_mode_on_fails(self):
  145. with self.assertRaises(NotImplementedError):
  146. await self.subject.async_turn_away_mode_on()
  147. async def test_turn_away_mode_off_fails(self):
  148. with self.assertRaises(NotImplementedError):
  149. await self.subject.async_turn_away_mode_off()
  150. def test_basic_bsensor_extra_state_attributes(self):
  151. self.dps[ERROR_DP] = 2
  152. self.assertDictEqual(
  153. self.basicBSensor.extra_state_attributes,
  154. {"fault_code": 2},
  155. )