test_beca_bht002_thermostat.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_AUTO,
  3. HVAC_MODE_HEAT,
  4. PRESET_ECO,
  5. PRESET_COMFORT,
  6. SUPPORT_PRESET_MODE,
  7. SUPPORT_TARGET_TEMPERATURE,
  8. )
  9. from homeassistant.const import STATE_UNAVAILABLE
  10. from ..const import BECA_BHT002_PAYLOAD
  11. from ..helpers import assert_device_properties_set
  12. from .base_device_tests import TuyaDeviceTestCase
  13. LIGHT_DPS = "1"
  14. TEMPERATURE_DPS = "2"
  15. CURRENTTEMP_DPS = "3"
  16. HVACMODE_DPS = "4"
  17. PRESET_DPS = "5"
  18. LOCK_DPS = "6"
  19. FLOOR_DPS = "102"
  20. UNKNOWN104_DPS = "104"
  21. class TestBecaBHT002Thermostat(TuyaDeviceTestCase):
  22. __test__ = True
  23. def setUp(self):
  24. self.setUpForConfig(
  25. "beca_bht002_thermostat_c.yaml",
  26. BECA_BHT002_PAYLOAD,
  27. )
  28. self.subject = self.entities.get("climate")
  29. self.light = self.entities.get("light_display")
  30. self.lock = self.entities.get("lock_child_lock")
  31. def test_supported_features(self):
  32. self.assertEqual(
  33. self.subject.supported_features,
  34. SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  35. )
  36. def test_temperature_unit(self):
  37. self.assertEqual(
  38. self.subject.temperature_unit,
  39. self.subject._device.temperature_unit,
  40. )
  41. def test_target_temperature(self):
  42. self.dps[TEMPERATURE_DPS] = 50
  43. self.assertEqual(self.subject.target_temperature, 25)
  44. def test_target_temperature_step(self):
  45. self.assertEqual(self.subject.target_temperature_step, 0.5)
  46. def test_minimum_target_temperature(self):
  47. self.assertEqual(self.subject.min_temp, 5)
  48. def test_maximum_target_temperature(self):
  49. self.assertEqual(self.subject.max_temp, 35)
  50. async def test_legacy_set_temperature_with_temperature(self):
  51. async with assert_device_properties_set(
  52. self.subject._device, {TEMPERATURE_DPS: 41}
  53. ):
  54. await self.subject.async_set_temperature(temperature=20.5)
  55. async def test_legacy_set_temperature_with_preset_mode(self):
  56. async with assert_device_properties_set(
  57. self.subject._device, {PRESET_DPS: True}
  58. ):
  59. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  60. async def test_legacy_set_temperature_with_both_properties(self):
  61. async with assert_device_properties_set(
  62. self.subject._device,
  63. {
  64. TEMPERATURE_DPS: 44,
  65. PRESET_DPS: False,
  66. },
  67. ):
  68. await self.subject.async_set_temperature(
  69. temperature=22, preset_mode=PRESET_COMFORT
  70. )
  71. async def test_set_target_temperature_succeeds_within_valid_range(self):
  72. async with assert_device_properties_set(
  73. self.subject._device,
  74. {TEMPERATURE_DPS: 45},
  75. ):
  76. await self.subject.async_set_target_temperature(22.5)
  77. async def test_set_target_temperature_rounds_value_to_closest_half(self):
  78. async with assert_device_properties_set(
  79. self.subject._device, {TEMPERATURE_DPS: 35}
  80. ):
  81. await self.subject.async_set_target_temperature(17.6)
  82. async def test_set_target_temperature_fails_outside_valid_range(self):
  83. with self.assertRaisesRegex(
  84. ValueError, "temperature \\(4.5\\) must be between 5.0 and 35.0"
  85. ):
  86. await self.subject.async_set_target_temperature(4.5)
  87. with self.assertRaisesRegex(
  88. ValueError, "temperature \\(35.5\\) must be between 5.0 and 35.0"
  89. ):
  90. await self.subject.async_set_target_temperature(35.5)
  91. def test_current_temperature(self):
  92. self.dps[CURRENTTEMP_DPS] = 44
  93. self.assertEqual(self.subject.current_temperature, 22)
  94. def test_hvac_mode(self):
  95. self.dps[HVACMODE_DPS] = "0"
  96. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  97. self.dps[HVACMODE_DPS] = "1"
  98. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  99. self.dps[HVACMODE_DPS] = None
  100. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  101. def test_hvac_modes(self):
  102. self.assertCountEqual(
  103. self.subject.hvac_modes,
  104. [
  105. HVAC_MODE_HEAT,
  106. HVAC_MODE_AUTO,
  107. ],
  108. )
  109. def test_device_state_attribures(self):
  110. self.dps[FLOOR_DPS] = 45
  111. self.dps[UNKNOWN104_DPS] = False
  112. self.assertDictEqual(
  113. self.subject.device_state_attributes,
  114. {"floor_temperature": 22.5, "unknown_104": False},
  115. )
  116. self.assertDictEqual(self.light.device_state_attributes, {})
  117. self.assertDictEqual(self.lock.device_state_attributes, {})
  118. def test_icons(self):
  119. self.dps[LIGHT_DPS] = True
  120. self.assertEqual(self.light.icon, "mdi:led-on")
  121. self.dps[LIGHT_DPS] = False
  122. self.assertEqual(self.light.icon, "mdi:led-off")
  123. self.dps[LOCK_DPS] = True
  124. self.assertEqual(self.lock.icon, "mdi:hand-back-right-off")
  125. self.dps[LOCK_DPS] = False
  126. self.assertEqual(self.lock.icon, "mdi:hand-back-right")