test_betterlife_bl1500_heater.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_HEAT,
  3. HVAC_MODE_OFF,
  4. SUPPORT_PRESET_MODE,
  5. SUPPORT_TARGET_TEMPERATURE,
  6. )
  7. from homeassistant.const import STATE_UNAVAILABLE, TIME_MINUTES
  8. from ..const import BETTERLIFE_BL1500_PAYLOAD
  9. from ..helpers import assert_device_properties_set
  10. from ..mixins.climate import TargetTemperatureTests
  11. from ..mixins.lock import BasicLockTests
  12. from ..mixins.select import BasicSelectTests
  13. from ..mixins.sensor import BasicSensorTests
  14. from .base_device_tests import TuyaDeviceTestCase
  15. HVACMODE_DPS = "1"
  16. TEMPERATURE_DPS = "2"
  17. PRESET_DPS = "4"
  18. LOCK_DPS = "7"
  19. TIMER_DPS = "11"
  20. COUNTDOWN_DPS = "12"
  21. class TestBetterlifeBL1500Heater(
  22. BasicLockTests,
  23. BasicSelectTests,
  24. BasicSensorTests,
  25. TargetTemperatureTests,
  26. TuyaDeviceTestCase,
  27. ):
  28. __test__ = True
  29. def setUp(self):
  30. self.setUpForConfig("betterlife_bl1500_heater.yaml", BETTERLIFE_BL1500_PAYLOAD)
  31. self.subject = self.entities.get("climate")
  32. self.setUpTargetTemperature(
  33. TEMPERATURE_DPS,
  34. self.subject,
  35. min=15,
  36. max=30,
  37. )
  38. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  39. self.setUpBasicSelect(
  40. TIMER_DPS,
  41. self.entities.get("select_timer"),
  42. {
  43. "0": "Off",
  44. "1": "1 hour",
  45. "2": "2 hours",
  46. "3": "3 hours",
  47. "4": "4 hours",
  48. "5": "5 hours",
  49. "6": "6 hours",
  50. "7": "7 hours",
  51. "8": "8 hours",
  52. "9": "9 hours",
  53. "10": "10 hours",
  54. "11": "11 hours",
  55. "12": "12 hours",
  56. },
  57. )
  58. self.setUpBasicSensor(
  59. COUNTDOWN_DPS,
  60. self.entities.get("sensor_timer_countdown"),
  61. unit=TIME_MINUTES,
  62. )
  63. self.mark_secondary(
  64. ["lock_child_lock", "select_timer", "sensor_timer_countdown"]
  65. )
  66. def test_supported_features(self):
  67. self.assertEqual(
  68. self.subject.supported_features,
  69. SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE,
  70. )
  71. def test_icon(self):
  72. self.dps[HVACMODE_DPS] = True
  73. self.assertEqual(self.subject.icon, "mdi:radiator")
  74. self.dps[HVACMODE_DPS] = False
  75. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  76. def test_temperature_unit_returns_device_temperature_unit(self):
  77. self.assertEqual(
  78. self.subject.temperature_unit, self.subject._device.temperature_unit
  79. )
  80. async def test_legacy_set_temperature_with_preset_mode(self):
  81. async with assert_device_properties_set(
  82. self.subject._device, {PRESET_DPS: "2"}
  83. ):
  84. await self.subject.async_set_temperature(preset_mode="eco")
  85. async def test_legacy_set_temperature_with_both_properties(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "1"}
  88. ):
  89. await self.subject.async_set_temperature(
  90. temperature=26, preset_mode="boost"
  91. )
  92. def test_hvac_mode(self):
  93. self.dps[HVACMODE_DPS] = True
  94. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  95. self.dps[HVACMODE_DPS] = False
  96. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  97. self.dps[HVACMODE_DPS] = None
  98. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  99. def test_hvac_modes(self):
  100. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_HEAT])
  101. async def test_turn_on(self):
  102. async with assert_device_properties_set(
  103. self.subject._device, {HVACMODE_DPS: True}
  104. ):
  105. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  106. async def test_turn_off(self):
  107. async with assert_device_properties_set(
  108. self.subject._device, {HVACMODE_DPS: False}
  109. ):
  110. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  111. def test_preset_mode(self):
  112. self.dps[PRESET_DPS] = "0"
  113. self.assertEqual(self.subject.preset_mode, "comfort")
  114. self.dps[PRESET_DPS] = "1"
  115. self.assertEqual(self.subject.preset_mode, "boost")
  116. self.dps[PRESET_DPS] = "2"
  117. self.assertEqual(self.subject.preset_mode, "eco")
  118. self.dps[PRESET_DPS] = None
  119. self.assertIs(self.subject.preset_mode, None)
  120. def test_preset_modes(self):
  121. self.assertCountEqual(self.subject.preset_modes, ["comfort", "boost", "eco"])
  122. async def test_set_preset_mode_to_comfort(self):
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {PRESET_DPS: "0"},
  126. ):
  127. await self.subject.async_set_preset_mode("comfort")
  128. async def test_set_preset_mode_to_boost(self):
  129. async with assert_device_properties_set(
  130. self.subject._device,
  131. {PRESET_DPS: "1"},
  132. ):
  133. await self.subject.async_set_preset_mode("boost")
  134. async def test_set_preset_mode_to_eco(self):
  135. async with assert_device_properties_set(
  136. self.subject._device,
  137. {PRESET_DPS: "2"},
  138. ):
  139. await self.subject.async_set_preset_mode("eco")