test_betterlife_bl1500_heater.py 5.1 KB

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