test_betterlife_bl1500_heater.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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,
  32. max=30,
  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": "Off",
  40. "1": "1 hour",
  41. "2": "2 hours",
  42. "3": "3 hours",
  43. "4": "4 hours",
  44. "5": "5 hours",
  45. "6": "6 hours",
  46. "7": "7 hours",
  47. "8": "8 hours",
  48. "9": "9 hours",
  49. "10": "10 hours",
  50. "11": "11 hours",
  51. "12": "12 hours",
  52. },
  53. )
  54. self.setUpBasicSensor(
  55. COUNTDOWN_DPS,
  56. self.entities.get("sensor_timer_countdown"),
  57. unit=UnitOfTime.MINUTES,
  58. device_class=SensorDeviceClass.DURATION,
  59. )
  60. self.mark_secondary(
  61. ["lock_child_lock", "select_timer", "sensor_timer_countdown"]
  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. ),
  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_celsius(self):
  77. self.assertEqual(self.subject.temperature_unit, UnitOfTemperature.CELSIUS)
  78. async def test_legacy_set_temperature_with_preset_mode(self):
  79. async with assert_device_properties_set(
  80. self.subject._device, {PRESET_DPS: "2"}
  81. ):
  82. await self.subject.async_set_temperature(preset_mode="eco")
  83. async def test_legacy_set_temperature_with_both_properties(self):
  84. async with assert_device_properties_set(
  85. self.subject._device, {TEMPERATURE_DPS: 26, PRESET_DPS: "1"}
  86. ):
  87. await self.subject.async_set_temperature(
  88. temperature=26, preset_mode="boost"
  89. )
  90. def test_hvac_mode(self):
  91. self.dps[HVACMODE_DPS] = True
  92. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  93. self.dps[HVACMODE_DPS] = False
  94. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  95. def test_hvac_modes(self):
  96. self.assertCountEqual(self.subject.hvac_modes, [HVACMode.OFF, HVACMode.HEAT])
  97. async def test_turn_on(self):
  98. async with assert_device_properties_set(
  99. self.subject._device, {HVACMODE_DPS: True}
  100. ):
  101. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  102. async def test_turn_off(self):
  103. async with assert_device_properties_set(
  104. self.subject._device, {HVACMODE_DPS: False}
  105. ):
  106. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  107. def test_preset_mode(self):
  108. self.dps[PRESET_DPS] = "0"
  109. self.assertEqual(self.subject.preset_mode, "comfort")
  110. self.dps[PRESET_DPS] = "1"
  111. self.assertEqual(self.subject.preset_mode, "boost")
  112. self.dps[PRESET_DPS] = "2"
  113. self.assertEqual(self.subject.preset_mode, "eco")
  114. self.dps[PRESET_DPS] = None
  115. self.assertIs(self.subject.preset_mode, None)
  116. def test_preset_modes(self):
  117. self.assertCountEqual(self.subject.preset_modes, ["comfort", "boost", "eco"])
  118. async def test_set_preset_mode_to_comfort(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {PRESET_DPS: "0"},
  122. ):
  123. await self.subject.async_set_preset_mode("comfort")
  124. async def test_set_preset_mode_to_boost(self):
  125. async with assert_device_properties_set(
  126. self.subject._device,
  127. {PRESET_DPS: "1"},
  128. ):
  129. await self.subject.async_set_preset_mode("boost")
  130. async def test_set_preset_mode_to_eco(self):
  131. async with assert_device_properties_set(
  132. self.subject._device,
  133. {PRESET_DPS: "2"},
  134. ):
  135. await self.subject.async_set_preset_mode("eco")