4
0

test_thermex_if50v.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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_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
  41. | WaterHeaterEntityFeature.TARGET_TEMPERATURE
  42. | WaterHeaterEntityFeature.AWAY_MODE
  43. | WaterHeaterEntityFeature.ON_OFF,
  44. )
  45. def test_temperature_unit_returns_celsius(self):
  46. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  47. def test_precision(self):
  48. self.assertEqual(self.subject.precision, PRECISION_WHOLE)
  49. def test_current_temperature(self):
  50. self.dps[CURRENTTEMP_DP] = 55
  51. self.assertEqual(self.subject.current_temperature, 55)
  52. def test_min_temp(self):
  53. self.assertEqual(self.subject.min_temp, 15)
  54. def test_max_temp(self):
  55. self.assertEqual(self.subject.max_temp, 75)
  56. def test_target_temperature(self):
  57. self.dps[TEMPERATURE_DP] = 61
  58. self.assertEqual(self.subject.target_temperature, 61)
  59. def test_target_temperature_step(self):
  60. self.assertEqual(self.subject.target_temperature_step, 1)
  61. def test_operation_list(self):
  62. self.assertCountEqual(
  63. self.subject.operation_list,
  64. [
  65. STATE_ECO,
  66. STATE_ELECTRIC,
  67. STATE_PERFORMANCE,
  68. STATE_OFF,
  69. "away",
  70. ],
  71. )
  72. def test_current_operation(self):
  73. self.dps[POWER_DP] = True
  74. self.dps[MODE_DP] = "3"
  75. self.assertEqual(self.subject.current_operation, STATE_ECO)
  76. self.dps[MODE_DP] = "1"
  77. self.assertEqual(self.subject.current_operation, STATE_PERFORMANCE)
  78. self.dps[MODE_DP] = "2"
  79. self.assertEqual(self.subject.current_operation, STATE_ELECTRIC)
  80. self.dps[MODE_DP] = "4"
  81. self.assertEqual(self.subject.current_operation, "away")
  82. self.dps[POWER_DP] = False
  83. self.assertEqual(self.subject.current_operation, STATE_OFF)
  84. def test_is_away_mode_redirects_to_mode(self):
  85. self.dps[POWER_DP] = True
  86. self.dps[MODE_DP] = "4"
  87. self.assertTrue(self.subject.is_away_mode_on)
  88. self.dps[MODE_DP] = "2"
  89. self.assertFalse(self.subject.is_away_mode_on)
  90. async def test_set_temperature(self):
  91. async with assert_device_properties_set(
  92. self.subject._device,
  93. {TEMPERATURE_DP: 65},
  94. ):
  95. await self.subject.async_set_temperature(temperature=65)
  96. async def test_set_operation_mode_to_eco(self):
  97. async with assert_device_properties_set(
  98. self.subject._device,
  99. {POWER_DP: True, MODE_DP: "3"},
  100. ):
  101. await self.subject.async_set_operation_mode(STATE_ECO)
  102. async def test_set_operation_mode_with_temperature_service(self):
  103. async with assert_device_properties_set(
  104. self.subject._device,
  105. {POWER_DP: True, MODE_DP: "3"},
  106. ):
  107. await self.subject.async_set_temperature(operation_mode=STATE_ECO)
  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: "2"},
  112. ):
  113. await self.subject.async_set_operation_mode(STATE_ELECTRIC)
  114. async def test_set_operation_mode_to_performance(self):
  115. async with assert_device_properties_set(
  116. self.subject._device,
  117. {POWER_DP: True, MODE_DP: "1"},
  118. ):
  119. await self.subject.async_set_operation_mode(STATE_PERFORMANCE)
  120. async def test_set_operation_mode_to_off(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {POWER_DP: False},
  124. ):
  125. await self.subject.async_set_operation_mode(STATE_OFF)
  126. async def test_turn_on(self):
  127. async with assert_device_properties_set(
  128. self.subject._device,
  129. {POWER_DP: True},
  130. ):
  131. await self.subject.async_turn_on()
  132. async def test_turn_off(self):
  133. async with assert_device_properties_set(
  134. self.subject._device,
  135. {POWER_DP: False},
  136. ):
  137. await self.subject.async_turn_off()
  138. async def test_turn_away_mode_on(self):
  139. async with assert_device_properties_set(
  140. self.subject._device,
  141. {POWER_DP: True, MODE_DP: "4"},
  142. ):
  143. await self.subject.async_turn_away_mode_on()
  144. async def test_turn_away_mode_off(self):
  145. self.dps[POWER_DP] = True
  146. self.dps[MODE_DP] = "4"
  147. async with assert_device_properties_set(
  148. self.subject._device,
  149. {POWER_DP: True, MODE_DP: "2"},
  150. ):
  151. await self.subject.async_turn_away_mode_off()
  152. def test_basic_bsensor_extra_state_attributes(self):
  153. self.dps[ERROR_DP] = 2
  154. self.assertDictEqual(
  155. self.basicBSensor.extra_state_attributes,
  156. {"fault_code": 2},
  157. )