test_hydrotherm_dynamicx8.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 homeassistant.const import 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_fault"),
  34. device_class=BinarySensorDeviceClass.PROBLEM,
  35. testdata=(1, 0),
  36. )
  37. self.mark_secondary(["binary_sensor_fault"])
  38. def test_supported_features(self):
  39. self.assertEqual(
  40. self.subject.supported_features,
  41. WaterHeaterEntityFeature.OPERATION_MODE,
  42. )
  43. def test_temperature_unit_returns_celsius(self):
  44. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  45. def test_current_temperature(self):
  46. self.dps[CURRENTTEMP_DP] = 55
  47. self.assertEqual(self.subject.current_temperature, 55)
  48. def test_target_temperature(self):
  49. self.dps[TEMPERATURE_DP] = 61
  50. self.assertEqual(self.subject.target_temperature, 61)
  51. def test_operation_list(self):
  52. self.assertCountEqual(
  53. self.subject.operation_list,
  54. [
  55. STATE_ECO,
  56. STATE_ELECTRIC,
  57. STATE_HEAT_PUMP,
  58. STATE_HIGH_DEMAND,
  59. STATE_PERFORMANCE,
  60. STATE_OFF,
  61. ],
  62. )
  63. def test_current_operation(self):
  64. self.dps[POWER_DP] = True
  65. self.dps[MODE_DP] = "ECO"
  66. self.assertEqual(self.subject.current_operation, STATE_ECO)
  67. self.dps[MODE_DP] = "STANDARD"
  68. self.assertEqual(self.subject.current_operation, STATE_HEAT_PUMP)
  69. self.dps[MODE_DP] = "HYBRID"
  70. self.assertEqual(self.subject.current_operation, STATE_HIGH_DEMAND)
  71. self.dps[MODE_DP] = "HYBRID1"
  72. self.assertEqual(self.subject.current_operation, STATE_PERFORMANCE)
  73. self.dps[MODE_DP] = "ELEMENT"
  74. self.assertEqual(self.subject.current_operation, STATE_ELECTRIC)
  75. self.dps[POWER_DP] = False
  76. self.assertEqual(self.subject.current_operation, STATE_OFF)
  77. async def test_set_temperature_fails(self):
  78. with self.assertRaises(TypeError):
  79. await self.subject.async_set_temperature(temperature=65)
  80. async def test_set_operation_mode_to_eco(self):
  81. async with assert_device_properties_set(
  82. self.subject._device,
  83. {POWER_DP: True, MODE_DP: "ECO"},
  84. ):
  85. await self.subject.async_set_operation_mode(STATE_ECO)
  86. async def test_set_operation_mode_to_heat_pump(self):
  87. async with assert_device_properties_set(
  88. self.subject._device,
  89. {POWER_DP: True, MODE_DP: "STANDARD"},
  90. ):
  91. await self.subject.async_set_operation_mode(STATE_HEAT_PUMP)
  92. async def test_set_operation_mode_to_electric(self):
  93. async with assert_device_properties_set(
  94. self.subject._device,
  95. {POWER_DP: True, MODE_DP: "ELEMENT"},
  96. ):
  97. await self.subject.async_set_operation_mode(STATE_ELECTRIC)
  98. async def test_set_operation_mode_to_highdemand(self):
  99. async with assert_device_properties_set(
  100. self.subject._device,
  101. {POWER_DP: True, MODE_DP: "HYBRID"},
  102. ):
  103. await self.subject.async_set_operation_mode(STATE_HIGH_DEMAND)
  104. async def test_set_operation_mode_to_performance(self):
  105. async with assert_device_properties_set(
  106. self.subject._device,
  107. {POWER_DP: True, MODE_DP: "HYBRID1"},
  108. ):
  109. await self.subject.async_set_operation_mode(STATE_PERFORMANCE)
  110. async def test_set_operation_mode_to_off(self):
  111. async with assert_device_properties_set(
  112. self.subject._device,
  113. {POWER_DP: False},
  114. ):
  115. await self.subject.async_set_operation_mode(STATE_OFF)