test_beca_bhp6000_thermostat.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. self.mark_secondary(["light_display", "lock_child_lock"])
  44. def test_supported_features(self):
  45. self.assertEqual(
  46. self.subject.supported_features,
  47. SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  48. )
  49. def test_temperature_unit_returns_configured_temperature_unit(self):
  50. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  51. async def test_legacy_set_temperature_with_preset_mode(self):
  52. async with assert_device_properties_set(self.subject._device, {PRESET_DPS: 1}):
  53. await self.subject.async_set_temperature(preset_mode="Schedule")
  54. async def test_legacy_set_temperature_with_both_properties(self):
  55. async with assert_device_properties_set(
  56. self.subject._device,
  57. {
  58. TEMPERATURE_DPS: 78,
  59. PRESET_DPS: 4,
  60. },
  61. ):
  62. await self.subject.async_set_temperature(
  63. temperature=78, preset_mode="Holiday Hold"
  64. )
  65. def test_current_temperature(self):
  66. self.dps[CURRENTTEMP_DPS] = 70
  67. self.assertEqual(self.subject.current_temperature, 70)
  68. def test_hvac_mode(self):
  69. self.dps[HVACMODE_DPS] = "1"
  70. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  71. self.dps[HVACMODE_DPS] = "2"
  72. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  73. self.dps[HVACMODE_DPS] = "3"
  74. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  75. self.dps[HVACMODE_DPS] = "4"
  76. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT_COOL)
  77. self.dps[HVACMODE_DPS] = "5"
  78. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  79. self.dps[HVACMODE_DPS] = None
  80. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  81. def test_hvac_modes(self):
  82. self.assertCountEqual(
  83. self.subject.hvac_modes,
  84. [
  85. HVAC_MODE_OFF,
  86. HVAC_MODE_HEAT,
  87. HVAC_MODE_HEAT_COOL,
  88. HVAC_MODE_COOL,
  89. HVAC_MODE_AUTO,
  90. ],
  91. )
  92. def test_fan_mode(self):
  93. self.dps[FAN_DPS] = False
  94. self.assertEqual(self.subject.fan_mode, "auto")
  95. self.dps[FAN_DPS] = True
  96. self.assertEqual(self.subject.fan_mode, "on")
  97. def test_fan_modes(self):
  98. self.assertCountEqual(
  99. self.subject.fan_modes,
  100. [
  101. "auto",
  102. "on",
  103. ],
  104. )
  105. async def test_set_fan_mode_to_auto(self):
  106. async with assert_device_properties_set(
  107. self.subject._device,
  108. {FAN_DPS: False},
  109. ):
  110. await self.subject.async_set_fan_mode("auto")
  111. async def test_set_fan_mode_to_on(self):
  112. async with assert_device_properties_set(
  113. self.subject._device,
  114. {FAN_DPS: True},
  115. ):
  116. await self.subject.async_set_fan_mode("on")
  117. def test_extra_state_attributes(self):
  118. self.assertEqual(self.subject.extra_state_attributes, {})
  119. def test_icons(self):
  120. self.dps[HVACMODE_DPS] = 1
  121. self.assertEqual(self.subject.icon, "mdi:snowflake")
  122. self.dps[HVACMODE_DPS] = 2
  123. self.assertEqual(self.subject.icon, "mdi:fire")
  124. self.dps[HVACMODE_DPS] = 3
  125. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  126. self.dps[HVACMODE_DPS] = 4
  127. self.assertEqual(self.subject.icon, "mdi:fire-alert")
  128. self.dps[HVACMODE_DPS] = 5
  129. self.assertEqual(self.subject.icon, "mdi:hvac")
  130. self.dps[LIGHT_DPS] = True
  131. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  132. self.dps[LIGHT_DPS] = False
  133. self.assertEqual(self.basicLight.icon, "mdi:led-off")
  134. class TestBecaBHP6000ThermostatC(TuyaDeviceTestCase):
  135. __test__ = True
  136. def setUp(self):
  137. self.setUpForConfig("beca_bhp6000_thermostat_c.yaml", BECA_BHP6000_PAYLOAD)
  138. self.subject = self.entities.get("climate")
  139. self.mark_secondary(["light_display", "lock_child_lock"])
  140. def test_temperature_unit_returns_configured_temperature_unit(self):
  141. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  142. def test_minimum_target_temperature(self):
  143. self.assertEqual(self.subject.min_temp, 5)
  144. def test_maximum_target_temperature(self):
  145. self.assertEqual(self.subject.max_temp, 35)