test_beca_bhp6000_thermostat.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_AUTO,
  3. HVAC_MODE_COOL,
  4. HVAC_MODE_HEAT,
  5. HVAC_MODE_HEAT_COOL,
  6. HVAC_MODE_OFF,
  7. SUPPORT_FAN_MODE,
  8. SUPPORT_PRESET_MODE,
  9. SUPPORT_TARGET_TEMPERATURE,
  10. )
  11. from homeassistant.const import STATE_UNAVAILABLE, TEMP_CELSIUS, TEMP_FAHRENHEIT
  12. from ..const import BECA_BHP6000_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from ..mixins.climate import TargetTemperatureTests
  15. from ..mixins.light import BasicLightTests
  16. from ..mixins.lock import BasicLockTests
  17. from .base_device_tests import TuyaDeviceTestCase
  18. LIGHT_DPS = "1"
  19. TEMPERATURE_DPS = "2"
  20. CURRENTTEMP_DPS = "3"
  21. PRESET_DPS = "4"
  22. HVACMODE_DPS = "5"
  23. FAN_DPS = "6"
  24. LOCK_DPS = "7"
  25. class TestBecaBHP6000Thermostat(
  26. BasicLightTests,
  27. BasicLockTests,
  28. TargetTemperatureTests,
  29. TuyaDeviceTestCase,
  30. ):
  31. __test__ = True
  32. def setUp(self):
  33. self.setUpForConfig("beca_bhp6000_thermostat_f.yaml", BECA_BHP6000_PAYLOAD)
  34. self.subject = self.entities.get("climate")
  35. self.setUpTargetTemperature(
  36. TEMPERATURE_DPS,
  37. self.subject,
  38. min=40,
  39. max=95,
  40. )
  41. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  42. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  43. def test_supported_features(self):
  44. self.assertEqual(
  45. self.subject.supported_features,
  46. SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  47. )
  48. def test_temperature_unit_returns_configured_temperature_unit(self):
  49. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  50. async def test_legacy_set_temperature_with_preset_mode(self):
  51. async with assert_device_properties_set(self.subject._device, {PRESET_DPS: 1}):
  52. await self.subject.async_set_temperature(preset_mode="Schedule")
  53. async def test_legacy_set_temperature_with_both_properties(self):
  54. async with assert_device_properties_set(
  55. self.subject._device,
  56. {
  57. TEMPERATURE_DPS: 78,
  58. PRESET_DPS: 4,
  59. },
  60. ):
  61. await self.subject.async_set_temperature(
  62. temperature=78, preset_mode="Holiday Hold"
  63. )
  64. def test_current_temperature(self):
  65. self.dps[CURRENTTEMP_DPS] = 70
  66. self.assertEqual(self.subject.current_temperature, 70)
  67. def test_hvac_mode(self):
  68. self.dps[HVACMODE_DPS] = "1"
  69. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  70. self.dps[HVACMODE_DPS] = "2"
  71. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  72. self.dps[HVACMODE_DPS] = "3"
  73. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  74. self.dps[HVACMODE_DPS] = "4"
  75. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT_COOL)
  76. self.dps[HVACMODE_DPS] = "5"
  77. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  78. self.dps[HVACMODE_DPS] = None
  79. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  80. def test_hvac_modes(self):
  81. self.assertCountEqual(
  82. self.subject.hvac_modes,
  83. [
  84. HVAC_MODE_OFF,
  85. HVAC_MODE_HEAT,
  86. HVAC_MODE_HEAT_COOL,
  87. HVAC_MODE_COOL,
  88. HVAC_MODE_AUTO,
  89. ],
  90. )
  91. def test_fan_mode(self):
  92. self.dps[FAN_DPS] = False
  93. self.assertEqual(self.subject.fan_mode, "auto")
  94. self.dps[FAN_DPS] = True
  95. self.assertEqual(self.subject.fan_mode, "on")
  96. def test_fan_modes(self):
  97. self.assertCountEqual(
  98. self.subject.fan_modes,
  99. [
  100. "auto",
  101. "on",
  102. ],
  103. )
  104. async def test_set_fan_mode_to_auto(self):
  105. async with assert_device_properties_set(
  106. self.subject._device,
  107. {FAN_DPS: False},
  108. ):
  109. await self.subject.async_set_fan_mode("auto")
  110. async def test_set_fan_mode_to_on(self):
  111. async with assert_device_properties_set(
  112. self.subject._device,
  113. {FAN_DPS: True},
  114. ):
  115. await self.subject.async_set_fan_mode("on")
  116. def test_device_state_attribures(self):
  117. self.assertEqual(self.subject.device_state_attributes, {})
  118. def test_icons(self):
  119. self.dps[HVACMODE_DPS] = 1
  120. self.assertEqual(self.subject.icon, "mdi:snowflake")
  121. self.dps[HVACMODE_DPS] = 2
  122. self.assertEqual(self.subject.icon, "mdi:fire")
  123. self.dps[HVACMODE_DPS] = 3
  124. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  125. self.dps[HVACMODE_DPS] = 4
  126. self.assertEqual(self.subject.icon, "mdi:fire-alert")
  127. self.dps[HVACMODE_DPS] = 5
  128. self.assertEqual(self.subject.icon, "mdi:hvac")
  129. self.dps[LIGHT_DPS] = True
  130. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  131. self.dps[LIGHT_DPS] = False
  132. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  133. class TestBecaBHP6000ThermostatC(TuyaDeviceTestCase):
  134. __test__ = True
  135. def setUp(self):
  136. self.setUpForConfig("beca_bhp6000_thermostat_c.yaml", BECA_BHP6000_PAYLOAD)
  137. self.subject = self.entities.get("climate")
  138. def test_temperature_unit_returns_configured_temperature_unit(self):
  139. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  140. def test_minimum_target_temperature(self):
  141. self.assertEqual(self.subject.min_temp, 5)
  142. def test_maximum_target_temperature(self):
  143. self.assertEqual(self.subject.max_temp, 35)