test_beca_bht002_thermostat.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. self.mark_secondary(["light_display", "lock_child_lock"])
  62. def test_supported_features(self):
  63. self.assertEqual(
  64. self.subject.supported_features,
  65. SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  66. )
  67. def test_temperature_unit(self):
  68. self.assertEqual(
  69. self.subject.temperature_unit,
  70. self.subject._device.temperature_unit,
  71. )
  72. async def test_legacy_set_temperature_with_preset_mode(self):
  73. async with assert_device_properties_set(
  74. self.subject._device, {PRESET_DPS: True}
  75. ):
  76. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  77. async def test_legacy_set_temperature_with_both_properties(self):
  78. async with assert_device_properties_set(
  79. self.subject._device,
  80. {
  81. TEMPERATURE_DPS: 44,
  82. PRESET_DPS: False,
  83. },
  84. ):
  85. await self.subject.async_set_temperature(
  86. temperature=22, preset_mode=PRESET_COMFORT
  87. )
  88. def test_current_temperature(self):
  89. self.dps[CURRENTTEMP_DPS] = 44
  90. self.assertEqual(self.subject.current_temperature, 22)
  91. def test_hvac_mode(self):
  92. self.dps[POWER_DPS] = False
  93. self.dps[HVACMODE_DPS] = "0"
  94. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  95. self.dps[POWER_DPS] = True
  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. HVAC_MODE_OFF,
  108. ],
  109. )
  110. def test_extra_state_attributes(self):
  111. self.dps[FLOOR_DPS] = 45
  112. self.dps[UNKNOWN104_DPS] = False
  113. self.assertDictEqual(
  114. self.subject.extra_state_attributes,
  115. {"floor_temperature": 22.5, "unknown_104": False},
  116. )
  117. def test_icons(self):
  118. self.dps[POWER_DPS] = True
  119. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  120. self.dps[POWER_DPS] = False
  121. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  122. self.dps[LOCK_DPS] = True
  123. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  124. self.dps[LOCK_DPS] = False
  125. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")