test_beca_bac002_thermostat.py 7.0 KB

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