test_betterlife_bl1500_heater.py 5.0 KB

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