test_beca_bht002_thermostat.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. from homeassistant.components.climate.const import (
  2. PRESET_COMFORT,
  3. PRESET_ECO,
  4. ClimateEntityFeature,
  5. HVACMode,
  6. )
  7. from homeassistant.components.sensor import SensorDeviceClass
  8. from homeassistant.const import UnitOfTemperature
  9. from ..const import BECA_BHT002_PAYLOAD
  10. from ..helpers import assert_device_properties_set
  11. from ..mixins.climate import TargetTemperatureTests
  12. from ..mixins.lock import BasicLockTests
  13. from ..mixins.sensor import BasicSensorTests
  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. FLOOR_DPS = "102"
  22. UNKNOWN104_DPS = "104"
  23. class TestBecaBHT002Thermostat(
  24. BasicLockTests,
  25. BasicSensorTests,
  26. TargetTemperatureTests,
  27. TuyaDeviceTestCase,
  28. ):
  29. __test__ = True
  30. def setUp(self):
  31. self.setUpForConfig(
  32. "beca_bht002_thermostat_c.yaml",
  33. BECA_BHT002_PAYLOAD,
  34. )
  35. self.subject = self.entities.get("climate")
  36. self.setUpTargetTemperature(
  37. TEMPERATURE_DPS,
  38. self.subject,
  39. min=5.0,
  40. max=35.0,
  41. scale=2,
  42. )
  43. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  44. self.setUpBasicSensor(
  45. FLOOR_DPS,
  46. self.entities.get("sensor_external_temperature"),
  47. unit=UnitOfTemperature.CELSIUS,
  48. device_class=SensorDeviceClass.TEMPERATURE,
  49. state_class="measurement",
  50. testdata=(30, 15),
  51. )
  52. self.mark_secondary(["lock_child_lock"])
  53. def test_supported_features(self):
  54. self.assertEqual(
  55. self.subject.supported_features,
  56. (
  57. ClimateEntityFeature.PRESET_MODE
  58. | ClimateEntityFeature.TARGET_TEMPERATURE
  59. ),
  60. )
  61. def test_temperature_unit(self):
  62. self.assertEqual(
  63. self.subject.temperature_unit,
  64. UnitOfTemperature.CELSIUS,
  65. )
  66. async def test_legacy_set_temperature_with_preset_mode(self):
  67. async with assert_device_properties_set(
  68. self.subject._device, {PRESET_DPS: True}
  69. ):
  70. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  71. async def test_legacy_set_temperature_with_both_properties(self):
  72. async with assert_device_properties_set(
  73. self.subject._device,
  74. {
  75. TEMPERATURE_DPS: 44,
  76. PRESET_DPS: False,
  77. },
  78. ):
  79. await self.subject.async_set_temperature(
  80. temperature=22, preset_mode=PRESET_COMFORT
  81. )
  82. def test_current_temperature(self):
  83. self.dps[CURRENTTEMP_DPS] = 44
  84. self.assertEqual(self.subject.current_temperature, 22)
  85. def test_hvac_mode(self):
  86. self.dps[POWER_DPS] = False
  87. self.dps[HVACMODE_DPS] = "0"
  88. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  89. self.dps[POWER_DPS] = True
  90. self.assertEqual(self.subject.hvac_mode, HVACMode.AUTO)
  91. self.dps[HVACMODE_DPS] = "1"
  92. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  93. def test_hvac_modes(self):
  94. self.assertCountEqual(
  95. self.subject.hvac_modes,
  96. [
  97. HVACMode.HEAT,
  98. HVACMode.AUTO,
  99. HVACMode.OFF,
  100. ],
  101. )
  102. def test_extra_state_attributes(self):
  103. self.dps[FLOOR_DPS] = 45
  104. self.dps[UNKNOWN104_DPS] = False
  105. self.assertDictEqual(
  106. self.subject.extra_state_attributes,
  107. {"floor_temperature": 22.5, "unknown_104": False},
  108. )
  109. def test_icons(self):
  110. self.dps[LOCK_DPS] = True
  111. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right-off")
  112. self.dps[LOCK_DPS] = False
  113. self.assertEqual(self.basicLock.icon, "mdi:hand-back-right")