test_beca_bht6000_thermostat.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_BHT6000_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. UNKNOWN103_DPS = "103"
  30. UNKNOWN104_DPS = "104"
  31. class TestBecaBHT6000Thermostat(
  32. BasicLightTests,
  33. BasicLockTests,
  34. BasicSensorTests,
  35. TargetTemperatureTests,
  36. TuyaDeviceTestCase,
  37. ):
  38. __test__ = True
  39. def setUp(self):
  40. self.setUpForConfig(
  41. "beca_bht6000_thermostat_c.yaml",
  42. BECA_BHT6000_PAYLOAD,
  43. )
  44. self.subject = self.entities.get("climate")
  45. self.setUpTargetTemperature(
  46. TEMPERATURE_DPS, self.subject, min=5.0, max=35.0, scale=2
  47. )
  48. self.setUpBasicLight(POWER_DPS, self.entities.get("light_display"))
  49. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  50. self.setUpBasicSensor(
  51. FLOOR_DPS,
  52. self.entities.get("sensor_external_temperature"),
  53. unit=TEMP_CELSIUS,
  54. device_class=DEVICE_CLASS_TEMPERATURE,
  55. state_class="measurement",
  56. testdata=(36, 18),
  57. )
  58. def test_supported_features(self):
  59. self.assertEqual(
  60. self.subject.supported_features,
  61. SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  62. )
  63. def test_temperature_unit(self):
  64. self.assertEqual(
  65. self.subject.temperature_unit,
  66. self.subject._device.temperature_unit,
  67. )
  68. async def test_legacy_set_temperature_with_preset_mode(self):
  69. async with assert_device_properties_set(
  70. self.subject._device, {PRESET_DPS: True}
  71. ):
  72. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  73. async def test_legacy_set_temperature_with_both_properties(self):
  74. async with assert_device_properties_set(
  75. self.subject._device,
  76. {
  77. TEMPERATURE_DPS: 44,
  78. PRESET_DPS: False,
  79. },
  80. ):
  81. await self.subject.async_set_temperature(
  82. temperature=22, preset_mode=PRESET_COMFORT
  83. )
  84. def test_current_temperature(self):
  85. self.dps[CURRENTTEMP_DPS] = 44
  86. self.assertEqual(self.subject.current_temperature, 22)
  87. def test_hvac_mode(self):
  88. self.dps[POWER_DPS] = False
  89. self.dps[HVACMODE_DPS] = "0"
  90. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  91. self.dps[POWER_DPS] = True
  92. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  93. self.dps[HVACMODE_DPS] = "1"
  94. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  95. self.dps[HVACMODE_DPS] = None
  96. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  97. def test_hvac_modes(self):
  98. self.assertCountEqual(
  99. self.subject.hvac_modes,
  100. [
  101. HVAC_MODE_HEAT,
  102. HVAC_MODE_AUTO,
  103. HVAC_MODE_OFF,
  104. ],
  105. )
  106. def test_device_state_attribures(self):
  107. self.dps[FLOOR_DPS] = 45
  108. self.dps[UNKNOWN103_DPS] = "103"
  109. self.dps[UNKNOWN104_DPS] = False
  110. self.assertDictEqual(
  111. self.subject.device_state_attributes,
  112. {"floor_temperature": 22.5, "unknown_103": "103", "unknown_104": False},
  113. )
  114. def test_icons(self):
  115. self.dps[POWER_DPS] = True
  116. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  117. self.dps[POWER_DPS] = False
  118. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  119. self.dps[LOCK_DPS] = True
  120. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  121. self.dps[LOCK_DPS] = False
  122. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")