test_beca_bht002_thermostat.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 (
  11. DEVICE_CLASS_TEMPERATURE,
  12. STATE_UNAVAILABLE,
  13. TEMP_CELSIUS,
  14. )
  15. from ..const import BECA_BHT002_PAYLOAD
  16. from ..helpers import assert_device_properties_set
  17. from ..mixins.climate import TargetTemperatureTests
  18. from ..mixins.light import BasicLightTests
  19. from ..mixins.lock import BasicLockTests
  20. from ..mixins.sensor import BasicSensorTests
  21. from .base_device_tests import TuyaDeviceTestCase
  22. POWER_DPS = "1"
  23. TEMPERATURE_DPS = "2"
  24. CURRENTTEMP_DPS = "3"
  25. HVACMODE_DPS = "4"
  26. PRESET_DPS = "5"
  27. LOCK_DPS = "6"
  28. FLOOR_DPS = "102"
  29. UNKNOWN104_DPS = "104"
  30. class TestBecaBHT002Thermostat(
  31. BasicLightTests,
  32. BasicLockTests,
  33. BasicSensorTests,
  34. TargetTemperatureTests,
  35. TuyaDeviceTestCase,
  36. ):
  37. __test__ = True
  38. def setUp(self):
  39. self.setUpForConfig(
  40. "beca_bht002_thermostat_c.yaml",
  41. BECA_BHT002_PAYLOAD,
  42. )
  43. self.subject = self.entities.get("climate")
  44. self.setUpTargetTemperature(
  45. TEMPERATURE_DPS,
  46. self.subject,
  47. min=5.0,
  48. max=35.0,
  49. scale=2,
  50. )
  51. self.setUpBasicLight(POWER_DPS, self.entities.get("light_display"))
  52. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  53. self.setUpBasicSensor(
  54. FLOOR_DPS,
  55. self.entities.get("sensor_external_temperature"),
  56. unit=TEMP_CELSIUS,
  57. device_class=DEVICE_CLASS_TEMPERATURE,
  58. state_class="measurement",
  59. testdata=(30, 15),
  60. )
  61. def test_supported_features(self):
  62. self.assertEqual(
  63. self.subject.supported_features,
  64. SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  65. )
  66. def test_temperature_unit(self):
  67. self.assertEqual(
  68. self.subject.temperature_unit,
  69. self.subject._device.temperature_unit,
  70. )
  71. async def test_legacy_set_temperature_with_preset_mode(self):
  72. async with assert_device_properties_set(
  73. self.subject._device, {PRESET_DPS: True}
  74. ):
  75. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  76. async def test_legacy_set_temperature_with_both_properties(self):
  77. async with assert_device_properties_set(
  78. self.subject._device,
  79. {
  80. TEMPERATURE_DPS: 44,
  81. PRESET_DPS: False,
  82. },
  83. ):
  84. await self.subject.async_set_temperature(
  85. temperature=22, preset_mode=PRESET_COMFORT
  86. )
  87. def test_current_temperature(self):
  88. self.dps[CURRENTTEMP_DPS] = 44
  89. self.assertEqual(self.subject.current_temperature, 22)
  90. def test_hvac_mode(self):
  91. self.dps[POWER_DPS] = False
  92. self.dps[HVACMODE_DPS] = "0"
  93. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  94. self.dps[POWER_DPS] = True
  95. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  96. self.dps[HVACMODE_DPS] = "1"
  97. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  98. self.dps[HVACMODE_DPS] = None
  99. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  100. def test_hvac_modes(self):
  101. self.assertCountEqual(
  102. self.subject.hvac_modes,
  103. [
  104. HVAC_MODE_HEAT,
  105. HVAC_MODE_AUTO,
  106. HVAC_MODE_OFF,
  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. def test_icons(self):
  117. self.dps[POWER_DPS] = True
  118. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  119. self.dps[POWER_DPS] = False
  120. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  121. self.dps[LOCK_DPS] = True
  122. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  123. self.dps[LOCK_DPS] = False
  124. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")