test_beca_bhp6000_thermostat.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 .base_device_tests import TuyaDeviceTestCase
  15. LIGHT_DPS = "1"
  16. TEMPERATURE_DPS = "2"
  17. CURRENTTEMP_DPS = "3"
  18. PRESET_DPS = "4"
  19. HVACMODE_DPS = "5"
  20. FAN_DPS = "6"
  21. LOCK_DPS = "7"
  22. class TestBecaBHP6000Thermostat(TuyaDeviceTestCase):
  23. __test__ = True
  24. def setUp(self):
  25. self.setUpForConfig("beca_bhp6000_thermostat_f.yaml", BECA_BHP6000_PAYLOAD)
  26. self.subject = self.entities.get("climate")
  27. self.light = self.entities.get("light")
  28. self.lock = self.entities.get("lock")
  29. def test_supported_features(self):
  30. self.assertEqual(
  31. self.subject.supported_features,
  32. SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  33. )
  34. def test_temperature_unit_returns_configured_temperature_unit(self):
  35. self.assertEqual(self.subject.temperature_unit, TEMP_FAHRENHEIT)
  36. def test_target_temperature(self):
  37. self.dps[TEMPERATURE_DPS] = 25
  38. self.assertEqual(self.subject.target_temperature, 25)
  39. def test_target_temperature_step(self):
  40. self.assertEqual(self.subject.target_temperature_step, 1)
  41. def test_minimum_target_temperature(self):
  42. self.assertEqual(self.subject.min_temp, 40)
  43. def test_maximum_target_temperature(self):
  44. self.assertEqual(self.subject.max_temp, 95)
  45. async def test_legacy_set_temperature_with_temperature(self):
  46. async with assert_device_properties_set(
  47. self.subject._device, {TEMPERATURE_DPS: 80}
  48. ):
  49. await self.subject.async_set_temperature(temperature=80)
  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. async def test_legacy_set_temperature_with_no_valid_properties(self):
  65. await self.subject.async_set_temperature(something="else")
  66. self.subject._device.async_set_property.assert_not_called()
  67. async def test_set_target_temperature_succeeds_within_valid_range(self):
  68. async with assert_device_properties_set(
  69. self.subject._device,
  70. {TEMPERATURE_DPS: 75},
  71. ):
  72. await self.subject.async_set_target_temperature(75)
  73. async def test_set_target_temperature_rounds_value_to_closest_integer(self):
  74. async with assert_device_properties_set(
  75. self.subject._device, {TEMPERATURE_DPS: 78}
  76. ):
  77. await self.subject.async_set_target_temperature(77.6)
  78. async def test_set_target_temperature_fails_outside_valid_range(self):
  79. with self.assertRaisesRegex(
  80. ValueError, "temperature \\(39\\) must be between 40 and 95"
  81. ):
  82. await self.subject.async_set_target_temperature(39)
  83. with self.assertRaisesRegex(
  84. ValueError, "temperature \\(96\\) must be between 40 and 95"
  85. ):
  86. await self.subject.async_set_target_temperature(96)
  87. def test_current_temperature(self):
  88. self.dps[CURRENTTEMP_DPS] = 70
  89. self.assertEqual(self.subject.current_temperature, 70)
  90. def test_hvac_mode(self):
  91. self.dps[HVACMODE_DPS] = "1"
  92. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  93. self.dps[HVACMODE_DPS] = "2"
  94. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  95. self.dps[HVACMODE_DPS] = "3"
  96. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  97. self.dps[HVACMODE_DPS] = "4"
  98. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT_COOL)
  99. self.dps[HVACMODE_DPS] = "5"
  100. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_AUTO)
  101. self.dps[HVACMODE_DPS] = None
  102. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  103. def test_hvac_modes(self):
  104. self.assertCountEqual(
  105. self.subject.hvac_modes,
  106. [
  107. HVAC_MODE_OFF,
  108. HVAC_MODE_HEAT,
  109. HVAC_MODE_HEAT_COOL,
  110. HVAC_MODE_COOL,
  111. HVAC_MODE_AUTO,
  112. ],
  113. )
  114. def test_fan_mode(self):
  115. self.dps[FAN_DPS] = False
  116. self.assertEqual(self.subject.fan_mode, "auto")
  117. self.dps[FAN_DPS] = True
  118. self.assertEqual(self.subject.fan_mode, "on")
  119. def test_fan_modes(self):
  120. self.assertCountEqual(
  121. self.subject.fan_modes,
  122. [
  123. "auto",
  124. "on",
  125. ],
  126. )
  127. async def test_set_fan_mode_to_auto(self):
  128. async with assert_device_properties_set(
  129. self.subject._device,
  130. {FAN_DPS: False},
  131. ):
  132. await self.subject.async_set_fan_mode("auto")
  133. async def test_set_fan_mode_to_on(self):
  134. async with assert_device_properties_set(
  135. self.subject._device,
  136. {FAN_DPS: True},
  137. ):
  138. await self.subject.async_set_fan_mode("on")
  139. def test_device_state_attribures(self):
  140. self.assertEqual(self.subject.device_state_attributes, {})
  141. self.assertEqual(self.light.device_state_attributes, {})
  142. self.assertEqual(self.lock.device_state_attributes, {})
  143. def test_icons(self):
  144. self.dps[HVACMODE_DPS] = 1
  145. self.assertEqual(self.subject.icon, "mdi:snowflake")
  146. self.dps[HVACMODE_DPS] = 2
  147. self.assertEqual(self.subject.icon, "mdi:fire")
  148. self.dps[HVACMODE_DPS] = 3
  149. self.assertEqual(self.subject.icon, "mdi:hvac-off")
  150. self.dps[HVACMODE_DPS] = 4
  151. self.assertEqual(self.subject.icon, "mdi:fire-alert")
  152. self.dps[HVACMODE_DPS] = 5
  153. self.assertEqual(self.subject.icon, "mdi:hvac")
  154. self.dps[LIGHT_DPS] = True
  155. self.assertEqual(self.light.icon, "mdi:led-on")
  156. self.dps[LIGHT_DPS] = False
  157. self.assertEqual(self.light.icon, "mdi:led-off")
  158. class TestBecaBHP6000ThermostatC(TuyaDeviceTestCase):
  159. __test__ = True
  160. def setUp(self):
  161. self.setUpForConfig("beca_bhp6000_thermostat_c.yaml", BECA_BHP6000_PAYLOAD)
  162. self.subject = self.entities.get("climate")
  163. def test_temperature_unit_returns_configured_temperature_unit(self):
  164. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  165. def test_minimum_target_temperature(self):
  166. self.assertEqual(self.subject.min_temp, 5)
  167. def test_maximum_target_temperature(self):
  168. self.assertEqual(self.subject.max_temp, 35)