test_beca_bac002_thermostat.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. from homeassistant.components.climate.const import (
  2. FAN_AUTO,
  3. FAN_HIGH,
  4. FAN_LOW,
  5. FAN_MEDIUM,
  6. HVAC_MODE_COOL,
  7. HVAC_MODE_HEAT,
  8. HVAC_MODE_FAN_ONLY,
  9. HVAC_MODE_OFF,
  10. PRESET_COMFORT,
  11. PRESET_ECO,
  12. SUPPORT_FAN_MODE,
  13. SUPPORT_PRESET_MODE,
  14. SUPPORT_TARGET_TEMPERATURE,
  15. )
  16. from homeassistant.const import STATE_UNAVAILABLE, TEMP_CELSIUS
  17. from ..const import BECA_BAC002_PAYLOAD
  18. from ..helpers import assert_device_properties_set
  19. from ..mixins.climate import TargetTemperatureTests
  20. from ..mixins.lock import BasicLockTests
  21. from ..mixins.select import BasicSelectTests
  22. from .base_device_tests import TuyaDeviceTestCase
  23. SWITCH_DPS = "1"
  24. TEMPERATURE_DPS = "2"
  25. CURRENTTEMP_DPS = "3"
  26. PROGRAM_DPS = "4"
  27. PRESET_DPS = "5"
  28. LOCK_DPS = "6"
  29. HVACMODE_DPS = "102"
  30. FAN_DPS = "103"
  31. class TestBecaBAC002Thermostat(
  32. BasicLockTests,
  33. BasicSelectTests,
  34. TargetTemperatureTests,
  35. TuyaDeviceTestCase,
  36. ):
  37. __test__ = True
  38. def setUp(self):
  39. self.setUpForConfig("beca_bac002_thermostat_c.yaml", BECA_BAC002_PAYLOAD)
  40. self.subject = self.entities.get("climate")
  41. self.setUpTargetTemperature(
  42. TEMPERATURE_DPS,
  43. self.subject,
  44. min=5.0,
  45. max=35.0,
  46. scale=2,
  47. )
  48. self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
  49. self.setUpBasicSelect(
  50. PROGRAM_DPS,
  51. self.entities.get("select_schedule"),
  52. {
  53. "0": "program",
  54. "1": "manual",
  55. },
  56. )
  57. self.mark_secondary(["lock_child_lock"])
  58. def test_supported_features(self):
  59. self.assertEqual(
  60. self.subject.supported_features,
  61. SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE | SUPPORT_TARGET_TEMPERATURE,
  62. )
  63. def test_temperature_unit_returns_configured_temperature_unit(self):
  64. self.assertEqual(self.subject.temperature_unit, TEMP_CELSIUS)
  65. async def test_legacy_set_temperature_with_preset_mode(self):
  66. async with assert_device_properties_set(
  67. self.subject._device, {PRESET_DPS: True}
  68. ):
  69. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  70. async def test_legacy_set_temperature_with_both_properties(self):
  71. async with assert_device_properties_set(
  72. self.subject._device,
  73. {
  74. TEMPERATURE_DPS: 58,
  75. PRESET_DPS: False,
  76. },
  77. ):
  78. await self.subject.async_set_temperature(
  79. temperature=29, preset_mode=PRESET_COMFORT
  80. )
  81. def test_current_temperature(self):
  82. self.dps[CURRENTTEMP_DPS] = 70
  83. self.assertEqual(self.subject.current_temperature, 35.0)
  84. def test_hvac_mode(self):
  85. self.dps[SWITCH_DPS] = True
  86. self.dps[HVACMODE_DPS] = "0"
  87. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_COOL)
  88. self.dps[HVACMODE_DPS] = "1"
  89. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_HEAT)
  90. self.dps[HVACMODE_DPS] = "2"
  91. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_FAN_ONLY)
  92. self.dps[SWITCH_DPS] = False
  93. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  94. self.dps[HVACMODE_DPS] = None
  95. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  96. def test_hvac_modes(self):
  97. self.assertCountEqual(
  98. self.subject.hvac_modes,
  99. [
  100. HVAC_MODE_COOL,
  101. HVAC_MODE_FAN_ONLY,
  102. HVAC_MODE_HEAT,
  103. HVAC_MODE_OFF,
  104. ],
  105. )
  106. async def test_set_hvac_mode_to_cool(self):
  107. async with assert_device_properties_set(
  108. self.subject._device,
  109. {SWITCH_DPS: True, HVACMODE_DPS: "0"},
  110. ):
  111. await self.subject.async_set_hvac_mode(HVAC_MODE_COOL)
  112. async def test_set_hvac_mode_to_heat(self):
  113. async with assert_device_properties_set(
  114. self.subject._device,
  115. {SWITCH_DPS: True, HVACMODE_DPS: "1"},
  116. ):
  117. await self.subject.async_set_hvac_mode(HVAC_MODE_HEAT)
  118. async def test_set_hvac_mode_to_fan(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {SWITCH_DPS: True, HVACMODE_DPS: "2"},
  122. ):
  123. await self.subject.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  124. async def test_set_hvac_mode_to_off(self):
  125. async with assert_device_properties_set(
  126. self.subject._device, {SWITCH_DPS: False}
  127. ):
  128. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  129. def test_preset_modes(self):
  130. self.assertCountEqual(self.subject.preset_modes, [PRESET_COMFORT, PRESET_ECO])
  131. def test_preset_mode(self):
  132. self.dps[PRESET_DPS] = False
  133. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  134. self.dps[PRESET_DPS] = True
  135. self.assertEqual(self.subject.preset_mode, PRESET_ECO)
  136. async def test_set_preset_to_comfort(self):
  137. async with assert_device_properties_set(
  138. self.subject._device,
  139. {PRESET_DPS: False},
  140. ):
  141. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  142. async def test_set_preset_to_eco(self):
  143. async with assert_device_properties_set(
  144. self.subject._device,
  145. {PRESET_DPS: True},
  146. ):
  147. await self.subject.async_set_preset_mode(PRESET_ECO)
  148. def test_fan_mode(self):
  149. self.dps[FAN_DPS] = "0"
  150. self.assertEqual(self.subject.fan_mode, FAN_AUTO)
  151. self.dps[FAN_DPS] = "1"
  152. self.assertEqual(self.subject.fan_mode, FAN_HIGH)
  153. self.dps[FAN_DPS] = "2"
  154. self.assertEqual(self.subject.fan_mode, FAN_MEDIUM)
  155. self.dps[FAN_DPS] = "3"
  156. self.assertEqual(self.subject.fan_mode, FAN_LOW)
  157. def test_fan_modes(self):
  158. self.assertCountEqual(
  159. self.subject.fan_modes,
  160. [
  161. FAN_AUTO,
  162. FAN_LOW,
  163. FAN_MEDIUM,
  164. FAN_HIGH,
  165. ],
  166. )
  167. async def test_set_fan_mode_to_auto(self):
  168. async with assert_device_properties_set(
  169. self.subject._device,
  170. {FAN_DPS: "0"},
  171. ):
  172. await self.subject.async_set_fan_mode(FAN_AUTO)
  173. async def test_set_fan_mode_to_high(self):
  174. async with assert_device_properties_set(
  175. self.subject._device,
  176. {FAN_DPS: "1"},
  177. ):
  178. await self.subject.async_set_fan_mode(FAN_HIGH)
  179. async def test_set_fan_mode_to_medium(self):
  180. async with assert_device_properties_set(
  181. self.subject._device,
  182. {FAN_DPS: "2"},
  183. ):
  184. await self.subject.async_set_fan_mode(FAN_MEDIUM)
  185. async def test_set_fan_mode_to_low(self):
  186. async with assert_device_properties_set(
  187. self.subject._device,
  188. {FAN_DPS: "3"},
  189. ):
  190. await self.subject.async_set_fan_mode(FAN_LOW)
  191. def test_extra_state_attribures(self):
  192. self.assertEqual(self.subject.extra_state_attributes, {})