test_hydrotherm_dynamicx8.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 ..const import HYDROTHERM_DYNAMICX8_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from ..mixins.binary_sensor import BasicBinarySensorTests
  14. from .base_device_tests import TuyaDeviceTestCase
  15. POWER_DP = "1"
  16. TEMPERATURE_DP = "2"
  17. CURRENTTEMP_DP = "3"
  18. MODE_DP = "4"
  19. ERROR_DP = "21"
  20. class TestHydrothermDynamicX8(
  21. BasicBinarySensorTests,
  22. TuyaDeviceTestCase,
  23. ):
  24. __test__ = True
  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_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. )
  42. def test_temperature_unit_returns_device_temperature_unit(self):
  43. self.assertEqual(
  44. self.subject.temperature_unit,
  45. self.subject._device.temperature_unit,
  46. )
  47. def test_current_temperature(self):
  48. self.dps[CURRENTTEMP_DP] = 55
  49. self.assertEqual(self.subject.current_temperature, 55)
  50. def test_target_temperature(self):
  51. self.dps[TEMPERATURE_DP] = 61
  52. self.assertEqual(self.subject.target_temperature, 61)
  53. def test_operation_list(self):
  54. self.assertCountEqual(
  55. self.subject.operation_list,
  56. [
  57. STATE_ECO,
  58. STATE_ELECTRIC,
  59. STATE_HEAT_PUMP,
  60. STATE_HIGH_DEMAND,
  61. STATE_PERFORMANCE,
  62. STATE_OFF,
  63. ],
  64. )
  65. def test_current_operation(self):
  66. self.dps[POWER_DP] = True
  67. self.dps[MODE_DP] = "ECO"
  68. self.assertEqual(self.subject.current_operation, STATE_ECO)
  69. self.dps[MODE_DP] = "STANDARD"
  70. self.assertEqual(self.subject.current_operation, STATE_HEAT_PUMP)
  71. self.dps[MODE_DP] = "HYBRID"
  72. self.assertEqual(self.subject.current_operation, STATE_HIGH_DEMAND)
  73. self.dps[MODE_DP] = "HYBRID1"
  74. self.assertEqual(self.subject.current_operation, STATE_PERFORMANCE)
  75. self.dps[MODE_DP] = "ELEMENT"
  76. self.assertEqual(self.subject.current_operation, STATE_ELECTRIC)
  77. self.dps[POWER_DP] = False
  78. self.assertEqual(self.subject.current_operation, STATE_OFF)
  79. async def test_set_temperature_fails(self):
  80. with self.assertRaises(TypeError):
  81. await self.subject.async_set_temperature(temperature=65)
  82. async def test_set_operation_mode_to_eco(self):
  83. async with assert_device_properties_set(
  84. self.subject._device,
  85. {POWER_DP: True, MODE_DP: "ECO"},
  86. ):
  87. await self.subject.async_set_operation_mode(STATE_ECO)
  88. async def test_set_operation_mode_to_heat_pump(self):
  89. async with assert_device_properties_set(
  90. self.subject._device,
  91. {POWER_DP: True, MODE_DP: "STANDARD"},
  92. ):
  93. await self.subject.async_set_operation_mode(STATE_HEAT_PUMP)
  94. async def test_set_operation_mode_to_electric(self):
  95. async with assert_device_properties_set(
  96. self.subject._device,
  97. {POWER_DP: True, MODE_DP: "ELEMENT"},
  98. ):
  99. await self.subject.async_set_operation_mode(STATE_ELECTRIC)
  100. async def test_set_operation_mode_to_highdemand(self):
  101. async with assert_device_properties_set(
  102. self.subject._device,
  103. {POWER_DP: True, MODE_DP: "HYBRID"},
  104. ):
  105. await self.subject.async_set_operation_mode(STATE_HIGH_DEMAND)
  106. async def test_set_operation_mode_to_performance(self):
  107. async with assert_device_properties_set(
  108. self.subject._device,
  109. {POWER_DP: True, MODE_DP: "HYBRID1"},
  110. ):
  111. await self.subject.async_set_operation_mode(STATE_PERFORMANCE)
  112. async def test_set_operation_mode_to_off(self):
  113. async with assert_device_properties_set(
  114. self.subject._device,
  115. {POWER_DP: False},
  116. ):
  117. await self.subject.async_set_operation_mode(STATE_OFF)