test_beca_bhp6000_thermostat.py 5.8 KB

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