test_eurom_601_heater.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. from homeassistant.components.binary_sensor import DEVICE_CLASS_PROBLEM
  2. from homeassistant.components.climate.const import (
  3. HVAC_MODE_HEAT,
  4. HVAC_MODE_OFF,
  5. PRESET_COMFORT,
  6. PRESET_ECO,
  7. SUPPORT_TARGET_TEMPERATURE,
  8. SUPPORT_PRESET_MODE,
  9. )
  10. from homeassistant.const import STATE_UNAVAILABLE
  11. from ..const import EUROM_601_HEATER_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from ..mixins.binary_sensor import BasicBinarySensorTests
  14. from .base_device_tests import TuyaDeviceTestCase
  15. HVACMODE_DPS = "1"
  16. TEMPERATURE_DPS = "2"
  17. CURRENTTEMP_DPS = "3"
  18. PRESET_DPS = "6"
  19. ERROR_DPS = "13"
  20. class TestEurom601Heater(BasicBinarySensorTests, TuyaDeviceTestCase):
  21. __test__ = True
  22. def setUp(self):
  23. self.setUpForConfig("eurom_601_heater.yaml", EUROM_601_HEATER_PAYLOAD)
  24. self.subject = self.entities.get("climate")
  25. self.setUpBasicBinarySensor(
  26. ERROR_DPS,
  27. self.entities.get("binary_sensor_error"),
  28. device_class=DEVICE_CLASS_PROBLEM,
  29. testdata=(1, 0),
  30. )
  31. def test_supported_features(self):
  32. self.assertEqual(
  33. self.subject.supported_features,
  34. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  35. )
  36. def test_icon(self):
  37. self.dps[HVACMODE_DPS] = True
  38. self.assertEqual(self.subject.icon, "mdi:radiator")
  39. self.dps[HVACMODE_DPS] = False
  40. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  41. def test_temperature_unit_returns_device_temperature_unit(self):
  42. self.assertEqual(
  43. self.subject.temperature_unit, self.subject._device.temperature_unit
  44. )
  45. def test_target_temperature(self):
  46. self.dps[TEMPERATURE_DPS] = 25
  47. self.assertEqual(self.subject.target_temperature, 25)
  48. def test_target_temperature_step(self):
  49. self.assertEqual(self.subject.target_temperature_step, 1)
  50. def test_minimum_target_temperature(self):
  51. self.assertEqual(self.subject.min_temp, 15)
  52. def test_maximum_target_temperature(self):
  53. self.assertEqual(self.subject.max_temp, 35)
  54. async def test_legacy_set_temperature_with_temperature(self):
  55. async with assert_device_properties_set(
  56. self.subject._device, {TEMPERATURE_DPS: 24}
  57. ):
  58. await self.subject.async_set_temperature(temperature=24)
  59. async def test_legacy_set_temperature_with_no_valid_properties(self):
  60. await self.subject.async_set_temperature(something="else")
  61. self.subject._device.async_set_property.assert_not_called()
  62. async def test_set_target_temperature_succeeds_within_valid_range(self):
  63. async with assert_device_properties_set(
  64. self.subject._device,
  65. {TEMPERATURE_DPS: 25},
  66. ):
  67. await self.subject.async_set_target_temperature(25)
  68. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  69. async with assert_device_properties_set(
  70. self.subject._device, {TEMPERATURE_DPS: 23}
  71. ):
  72. await self.subject.async_set_target_temperature(22.6)
  73. async def test_set_target_temperature_fails_outside_valid_range(self):
  74. with self.assertRaisesRegex(
  75. ValueError, "temperature \\(14\\) must be between 15 and 35"
  76. ):
  77. await self.subject.async_set_target_temperature(14)
  78. with self.assertRaisesRegex(
  79. ValueError, "temperature \\(36\\) must be between 15 and 35"
  80. ):
  81. await self.subject.async_set_target_temperature(36)
  82. def test_current_temperature(self):
  83. self.dps[CURRENTTEMP_DPS] = 25
  84. self.assertEqual(self.subject.current_temperature, 25)
  85. def test_hvac_mode(self):
  86. self.dps[HVACMODE_DPS] = True
  87. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  88. self.dps[HVACMODE_DPS] = False
  89. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  90. self.dps[HVACMODE_DPS] = None
  91. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  92. def test_hvac_modes(self):
  93. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  94. async def test_turn_on(self):
  95. async with assert_device_properties_set(
  96. self.subject._device, {HVACMODE_DPS: True}
  97. ):
  98. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  99. async def test_turn_off(self):
  100. async with assert_device_properties_set(
  101. self.subject._device, {HVACMODE_DPS: False}
  102. ):
  103. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  104. def test_preset_modes(self):
  105. self.assertCountEqual(
  106. self.subject.preset_modes,
  107. [PRESET_COMFORT, PRESET_ECO],
  108. )
  109. def test_preset_mode(self):
  110. self.dps[PRESET_DPS] = True
  111. self.assertEqual(self.subject.preset_mode, PRESET_ECO)
  112. self.dps[PRESET_DPS] = False
  113. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  114. async def test_set_preset_more_to_eco(self):
  115. async with assert_device_properties_set(
  116. self.subject._device, {PRESET_DPS: True}
  117. ):
  118. await self.subject.async_set_preset_mode(PRESET_ECO)
  119. async def test_set_preset_more_to_comfort(self):
  120. async with assert_device_properties_set(
  121. self.subject._device, {PRESET_DPS: False}
  122. ):
  123. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  124. def test_device_state_attributes(self):
  125. self.dps[ERROR_DPS] = 13
  126. self.assertCountEqual(
  127. self.subject.device_state_attributes,
  128. {"error": 13},
  129. )