test_beca_bht6000_thermostat.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. self.mark_secondary(["light_display", "lock_child_lock"])
  59. def test_supported_features(self):
  60. self.assertEqual(
  61. self.subject.supported_features,
  62. SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  63. )
  64. def test_temperature_unit(self):
  65. self.assertEqual(
  66. self.subject.temperature_unit,
  67. self.subject._device.temperature_unit,
  68. )
  69. async def test_legacy_set_temperature_with_preset_mode(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {PRESET_DPS: True}
  72. ):
  73. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  74. async def test_legacy_set_temperature_with_both_properties(self):
  75. async with assert_device_properties_set(
  76. self.subject._device,
  77. {
  78. TEMPERATURE_DPS: 44,
  79. PRESET_DPS: False,
  80. },
  81. ):
  82. await self.subject.async_set_temperature(
  83. temperature=22, preset_mode=PRESET_COMFORT
  84. )
  85. def test_current_temperature(self):
  86. self.dps[CURRENTTEMP_DPS] = 44
  87. self.assertEqual(self.subject.current_temperature, 22)
  88. def test_hvac_mode(self):
  89. self.dps[POWER_DPS] = False
  90. self.dps[HVACMODE_DPS] = "0"
  91. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  92. self.dps[POWER_DPS] = True
  93. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  94. self.dps[HVACMODE_DPS] = "1"
  95. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  96. self.dps[HVACMODE_DPS] = None
  97. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  98. def test_hvac_modes(self):
  99. self.assertCountEqual(
  100. self.subject.hvac_modes,
  101. [
  102. HVAC_MODE_HEAT,
  103. HVAC_MODE_AUTO,
  104. HVAC_MODE_OFF,
  105. ],
  106. )
  107. def test_extra_state_attributes(self):
  108. self.dps[FLOOR_DPS] = 45
  109. self.dps[UNKNOWN103_DPS] = "103"
  110. self.dps[UNKNOWN104_DPS] = False
  111. self.assertDictEqual(
  112. self.subject.extra_state_attributes,
  113. {"floor_temperature": 22.5, "unknown_103": "103", "unknown_104": False},
  114. )
  115. def test_icons(self):
  116. self.dps[POWER_DPS] = True
  117. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  118. self.dps[POWER_DPS] = False
  119. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  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")