test_betterlife_bl1500_heater.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. )
  5. from homeassistant.components.sensor import SensorDeviceClass
  6. from homeassistant.const import UnitOfTime, UnitOfTemperature
  7. from ..const import BETTERLIFE_BL1500_PAYLOAD
  8. from ..helpers import assert_device_properties_set
  9. from ..mixins.climate import TargetTemperatureTests
  10. from ..mixins.lock import BasicLockTests
  11. from ..mixins.select import BasicSelectTests
  12. from ..mixins.sensor import BasicSensorTests
  13. from .base_device_tests import TuyaDeviceTestCase
  14. HVACMODE_DPS = "1"
  15. TEMPERATURE_DPS = "2"
  16. PRESET_DPS = "4"
  17. LOCK_DPS = "7"
  18. TIMER_DPS = "11"
  19. COUNTDOWN_DPS = "12"
  20. class TestBetterlifeBL1500Heater(
  21. BasicLockTests,
  22. BasicSelectTests,
  23. BasicSensorTests,
  24. TargetTemperatureTests,
  25. TuyaDeviceTestCase,
  26. ):
  27. __test__ = True
  28. def setUp(self):
  29. self.setUpForConfig("betterlife_bl1500_heater.yaml", BETTERLIFE_BL1500_PAYLOAD)
  30. self.subject = self.entities.get("climate")
  31. self.setUpTargetTemperature(
  32. TEMPERATURE_DPS,
  33. self.subject,
  34. min=15,
  35. max=30,
  36. )
  37. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  38. self.setUpBasicSelect(
  39. TIMER_DPS,
  40. self.entities.get("select_timer"),
  41. {
  42. "0": "Off",
  43. "1": "1 hour",
  44. "2": "2 hours",
  45. "3": "3 hours",
  46. "4": "4 hours",
  47. "5": "5 hours",
  48. "6": "6 hours",
  49. "7": "7 hours",
  50. "8": "8 hours",
  51. "9": "9 hours",
  52. "10": "10 hours",
  53. "11": "11 hours",
  54. "12": "12 hours",
  55. },
  56. )
  57. self.setUpBasicSensor(
  58. COUNTDOWN_DPS,
  59. self.entities.get("sensor_timer_countdown"),
  60. unit=UnitOfTime.MINUTES,
  61. device_class=SensorDeviceClass.DURATION,
  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. (
  70. ClimateEntityFeature.TARGET_TEMPERATURE
  71. | ClimateEntityFeature.PRESET_MODE
  72. ),
  73. )
  74. def test_icon(self):
  75. self.dps[HVACMODE_DPS] = True
  76. self.assertEqual(self.subject.icon, "mdi:radiator")
  77. self.dps[HVACMODE_DPS] = False
  78. self.assertEqual(self.subject.icon, "mdi:radiator-disabled")
  79. def test_temperature_unit_returns_celsius(self):
  80. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  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")