test_moes_bht002_thermostat.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_AUTO,
  3. HVAC_MODE_HEAT,
  4. HVAC_MODE_OFF,
  5. PRESET_ECO,
  6. PRESET_COMFORT,
  7. SUPPORT_PRESET_MODE,
  8. SUPPORT_TARGET_TEMPERATURE,
  9. )
  10. from homeassistant.const import STATE_UNAVAILABLE
  11. from ..const import MOES_BHT002_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from ..mixins.lock import BasicLockTests
  14. from .base_device_tests import TuyaDeviceTestCase
  15. POWER_DPS = "1"
  16. TEMPERATURE_DPS = "2"
  17. CURRENTTEMP_DPS = "3"
  18. HVACMODE_DPS = "4"
  19. PRESET_DPS = "5"
  20. LOCK_DPS = "6"
  21. UNKNOWN104_DPS = "104"
  22. class TestMoesBHT002Thermostat(BasicLockTests, TuyaDeviceTestCase):
  23. __test__ = True
  24. def setUp(self):
  25. self.setUpForConfig(
  26. "moes_bht002_thermostat_c.yaml",
  27. MOES_BHT002_PAYLOAD,
  28. )
  29. self.subject = self.entities.get("climate")
  30. self.setUpBasicLock(LOCK_DPS, 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[POWER_DPS] = False
  96. self.dps[HVACMODE_DPS] = "0"
  97. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  98. self.dps[POWER_DPS] = True
  99. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  100. self.dps[HVACMODE_DPS] = "1"
  101. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  102. self.dps[HVACMODE_DPS] = None
  103. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  104. def test_hvac_modes(self):
  105. self.assertCountEqual(
  106. self.subject.hvac_modes,
  107. [
  108. HVAC_MODE_HEAT,
  109. HVAC_MODE_AUTO,
  110. HVAC_MODE_OFF,
  111. ],
  112. )
  113. def test_device_state_attribures(self):
  114. self.dps[UNKNOWN104_DPS] = False
  115. self.assertDictEqual(
  116. self.subject.device_state_attributes,
  117. {"unknown_104": False},
  118. )
  119. def test_icons(self):
  120. self.dps[LOCK_DPS] = True
  121. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  122. self.dps[LOCK_DPS] = False
  123. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")