test_beca_bac002_thermostat.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. from homeassistant.components.climate.const import (
  2. FAN_AUTO,
  3. FAN_HIGH,
  4. FAN_LOW,
  5. FAN_MEDIUM,
  6. PRESET_COMFORT,
  7. PRESET_ECO,
  8. ClimateEntityFeature,
  9. HVACMode,
  10. )
  11. from homeassistant.const import PRECISION_TENTHS, 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. def test_precision(self):
  65. self.assertEqual(self.subject.precision, PRECISION_TENTHS)
  66. async def test_legacy_set_temperature_with_preset_mode(self):
  67. async with assert_device_properties_set(
  68. self.subject._device, {PRESET_DPS: True}
  69. ):
  70. await self.subject.async_set_temperature(preset_mode=PRESET_ECO)
  71. async def test_legacy_set_temperature_with_both_properties(self):
  72. async with assert_device_properties_set(
  73. self.subject._device,
  74. {
  75. TEMPERATURE_DPS: 58,
  76. PRESET_DPS: False,
  77. },
  78. ):
  79. await self.subject.async_set_temperature(
  80. temperature=29, preset_mode=PRESET_COMFORT
  81. )
  82. def test_current_temperature(self):
  83. self.dps[CURRENTTEMP_DPS] = 70
  84. self.assertEqual(self.subject.current_temperature, 35.0)
  85. def test_hvac_mode(self):
  86. self.dps[SWITCH_DPS] = True
  87. self.dps[HVACMODE_DPS] = "0"
  88. self.assertEqual(self.subject.hvac_mode, HVACMode.COOL)
  89. self.dps[HVACMODE_DPS] = "1"
  90. self.assertEqual(self.subject.hvac_mode, HVACMode.HEAT)
  91. self.dps[HVACMODE_DPS] = "2"
  92. self.assertEqual(self.subject.hvac_mode, HVACMode.FAN_ONLY)
  93. self.dps[SWITCH_DPS] = False
  94. self.assertEqual(self.subject.hvac_mode, HVACMode.OFF)
  95. def test_hvac_modes(self):
  96. self.assertCountEqual(
  97. self.subject.hvac_modes,
  98. [
  99. HVACMode.COOL,
  100. HVACMode.FAN_ONLY,
  101. HVACMode.HEAT,
  102. HVACMode.OFF,
  103. ],
  104. )
  105. async def test_set_hvac_mode_to_cool(self):
  106. async with assert_device_properties_set(
  107. self.subject._device,
  108. {SWITCH_DPS: True, HVACMODE_DPS: "0"},
  109. ):
  110. await self.subject.async_set_hvac_mode(HVACMode.COOL)
  111. async def test_set_hvac_mode_to_heat(self):
  112. async with assert_device_properties_set(
  113. self.subject._device,
  114. {SWITCH_DPS: True, HVACMODE_DPS: "1"},
  115. ):
  116. await self.subject.async_set_hvac_mode(HVACMode.HEAT)
  117. async def test_set_hvac_mode_to_fan(self):
  118. async with assert_device_properties_set(
  119. self.subject._device,
  120. {SWITCH_DPS: True, HVACMODE_DPS: "2"},
  121. ):
  122. await self.subject.async_set_hvac_mode(HVACMode.FAN_ONLY)
  123. async def test_set_hvac_mode_to_off(self):
  124. async with assert_device_properties_set(
  125. self.subject._device, {SWITCH_DPS: False}
  126. ):
  127. await self.subject.async_set_hvac_mode(HVACMode.OFF)
  128. def test_preset_modes(self):
  129. self.assertCountEqual(self.subject.preset_modes, [PRESET_COMFORT, PRESET_ECO])
  130. def test_preset_mode(self):
  131. self.dps[PRESET_DPS] = False
  132. self.assertEqual(self.subject.preset_mode, PRESET_COMFORT)
  133. self.dps[PRESET_DPS] = True
  134. self.assertEqual(self.subject.preset_mode, PRESET_ECO)
  135. async def test_set_preset_to_comfort(self):
  136. async with assert_device_properties_set(
  137. self.subject._device,
  138. {PRESET_DPS: False},
  139. ):
  140. await self.subject.async_set_preset_mode(PRESET_COMFORT)
  141. async def test_set_preset_to_eco(self):
  142. async with assert_device_properties_set(
  143. self.subject._device,
  144. {PRESET_DPS: True},
  145. ):
  146. await self.subject.async_set_preset_mode(PRESET_ECO)
  147. def test_fan_mode(self):
  148. self.dps[FAN_DPS] = "0"
  149. self.assertEqual(self.subject.fan_mode, FAN_AUTO)
  150. self.dps[FAN_DPS] = "1"
  151. self.assertEqual(self.subject.fan_mode, FAN_HIGH)
  152. self.dps[FAN_DPS] = "2"
  153. self.assertEqual(self.subject.fan_mode, FAN_MEDIUM)
  154. self.dps[FAN_DPS] = "3"
  155. self.assertEqual(self.subject.fan_mode, FAN_LOW)
  156. def test_fan_modes(self):
  157. self.assertCountEqual(
  158. self.subject.fan_modes,
  159. [
  160. FAN_AUTO,
  161. FAN_LOW,
  162. FAN_MEDIUM,
  163. FAN_HIGH,
  164. ],
  165. )
  166. async def test_set_fan_mode_to_auto(self):
  167. async with assert_device_properties_set(
  168. self.subject._device,
  169. {FAN_DPS: "0"},
  170. ):
  171. await self.subject.async_set_fan_mode(FAN_AUTO)
  172. async def test_set_fan_mode_to_high(self):
  173. async with assert_device_properties_set(
  174. self.subject._device,
  175. {FAN_DPS: "1"},
  176. ):
  177. await self.subject.async_set_fan_mode(FAN_HIGH)
  178. async def test_set_fan_mode_to_medium(self):
  179. async with assert_device_properties_set(
  180. self.subject._device,
  181. {FAN_DPS: "2"},
  182. ):
  183. await self.subject.async_set_fan_mode(FAN_MEDIUM)
  184. async def test_set_fan_mode_to_low(self):
  185. async with assert_device_properties_set(
  186. self.subject._device,
  187. {FAN_DPS: "3"},
  188. ):
  189. await self.subject.async_set_fan_mode(FAN_LOW)
  190. def test_extra_state_attribures(self):
  191. self.assertEqual(self.subject.extra_state_attributes, {})