test_thermex_if50v.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  2. from homeassistant.components.water_heater import (
  3. STATE_ECO,
  4. STATE_ELECTRIC,
  5. STATE_OFF,
  6. STATE_PERFORMANCE,
  7. WaterHeaterEntityFeature,
  8. )
  9. from homeassistant.const import PRECISION_WHOLE, UnitOfTemperature
  10. from ..const import THERMEX_IF50V_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from ..mixins.binary_sensor import BasicBinarySensorTests
  13. from .base_device_tests import TuyaDeviceTestCase
  14. POWER_DP = "101"
  15. TEMPERATURE_DP = "104"
  16. CURRENTTEMP_DP = "102"
  17. MODE_DP = "105"
  18. ERROR_DP = "106"
  19. class TestThermexIF50V(
  20. BasicBinarySensorTests,
  21. TuyaDeviceTestCase,
  22. ):
  23. __test__ = True
  24. def setUp(self):
  25. self.setUpForConfig(
  26. "thermex_if50v_waterheater.yaml",
  27. THERMEX_IF50V_PAYLOAD,
  28. )
  29. self.subject = self.entities.get("water_heater")
  30. self.setUpBasicBinarySensor(
  31. ERROR_DP,
  32. self.entities.get("binary_sensor_fault"),
  33. device_class=BinarySensorDeviceClass.PROBLEM,
  34. testdata=(1, 0),
  35. )
  36. self.mark_secondary(["binary_sensor_fault"])
  37. def test_supported_features(self):
  38. self.assertEqual(
  39. self.subject.supported_features,
  40. WaterHeaterEntityFeature.OPERATION_MODE
  41. | WaterHeaterEntityFeature.TARGET_TEMPERATURE
  42. | WaterHeaterEntityFeature.AWAY_MODE,
  43. )
  44. def test_temperature_unit_returns_celsius(self):
  45. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  46. def test_precision(self):
  47. self.assertEqual(self.subject.precision, PRECISION_WHOLE)
  48. def test_current_temperature(self):
  49. self.dps[CURRENTTEMP_DP] = 55
  50. self.assertEqual(self.subject.current_temperature, 55)
  51. def test_min_temp(self):
  52. self.assertEqual(self.subject.min_temp, 15)
  53. def test_max_temp(self):
  54. self.assertEqual(self.subject.max_temp, 75)
  55. def test_target_temperature(self):
  56. self.dps[TEMPERATURE_DP] = 61
  57. self.assertEqual(self.subject.target_temperature, 61)
  58. def test_target_temperature_step(self):
  59. self.assertEqual(self.subject.target_temperature_step, 1)
  60. def test_operation_list(self):
  61. self.assertCountEqual(
  62. self.subject.operation_list,
  63. [
  64. STATE_ECO,
  65. STATE_ELECTRIC,
  66. STATE_PERFORMANCE,
  67. STATE_OFF,
  68. "away",
  69. ],
  70. )
  71. def test_current_operation(self):
  72. self.dps[POWER_DP] = True
  73. self.dps[MODE_DP] = "3"
  74. self.assertEqual(self.subject.current_operation, STATE_ECO)
  75. self.dps[MODE_DP] = "1"
  76. self.assertEqual(self.subject.current_operation, STATE_PERFORMANCE)
  77. self.dps[MODE_DP] = "2"
  78. self.assertEqual(self.subject.current_operation, STATE_ELECTRIC)
  79. self.dps[MODE_DP] = "4"
  80. self.assertEqual(self.subject.current_operation, "away")
  81. self.dps[POWER_DP] = False
  82. self.assertEqual(self.subject.current_operation, STATE_OFF)
  83. def test_is_away_mode_redirects_to_mode(self):
  84. self.dps[POWER_DP] = True
  85. self.dps[MODE_DP] = "4"
  86. self.assertTrue(self.subject.is_away_mode_on)
  87. self.dps[MODE_DP] = "2"
  88. self.assertFalse(self.subject.is_away_mode_on)
  89. async def test_set_temperature(self):
  90. async with assert_device_properties_set(
  91. self.subject._device,
  92. {TEMPERATURE_DP: 65},
  93. ):
  94. await self.subject.async_set_temperature(temperature=65)
  95. async def test_set_operation_mode_to_eco(self):
  96. async with assert_device_properties_set(
  97. self.subject._device,
  98. {POWER_DP: True, MODE_DP: "3"},
  99. ):
  100. await self.subject.async_set_operation_mode(STATE_ECO)
  101. async def test_set_operation_mode_with_temperature_service(self):
  102. async with assert_device_properties_set(
  103. self.subject._device,
  104. {POWER_DP: True, MODE_DP: "3"},
  105. ):
  106. await self.subject.async_set_temperature(operation_mode=STATE_ECO)
  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: "2"},
  111. ):
  112. await self.subject.async_set_operation_mode(STATE_ELECTRIC)
  113. async def test_set_operation_mode_to_performance(self):
  114. async with assert_device_properties_set(
  115. self.subject._device,
  116. {POWER_DP: True, MODE_DP: "1"},
  117. ):
  118. await self.subject.async_set_operation_mode(STATE_PERFORMANCE)
  119. async def test_set_operation_mode_to_off(self):
  120. async with assert_device_properties_set(
  121. self.subject._device,
  122. {POWER_DP: False},
  123. ):
  124. await self.subject.async_set_operation_mode(STATE_OFF)
  125. async def test_turn_on(self):
  126. async with assert_device_properties_set(
  127. self.subject._device,
  128. {POWER_DP: True},
  129. ):
  130. await self.subject.async_turn_on()
  131. async def test_turn_off(self):
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {POWER_DP: False},
  135. ):
  136. await self.subject.async_turn_off()
  137. async def test_turn_away_mode_on(self):
  138. async with assert_device_properties_set(
  139. self.subject._device,
  140. {POWER_DP: True, MODE_DP: "4"},
  141. ):
  142. await self.subject.async_turn_away_mode_on()
  143. async def test_turn_away_mode_off(self):
  144. self.dps[POWER_DP] = True
  145. self.dps[MODE_DP] = "4"
  146. async with assert_device_properties_set(
  147. self.subject._device,
  148. {POWER_DP: True, MODE_DP: "2"},
  149. ):
  150. await self.subject.async_turn_away_mode_off()