test_aspen_adv200_fan.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_FAN_ONLY,
  3. HVAC_MODE_OFF,
  4. SUPPORT_TARGET_TEMPERATURE,
  5. )
  6. from homeassistant.components.fan import (
  7. DIRECTION_FORWARD,
  8. DIRECTION_REVERSE,
  9. SUPPORT_DIRECTION,
  10. SUPPORT_PRESET_MODE,
  11. SUPPORT_SET_SPEED,
  12. )
  13. from homeassistant.const import TEMP_FAHRENHEIT
  14. from ..const import ASPEN_ASP200_FAN_PAYLOAD
  15. from ..helpers import assert_device_properties_set
  16. from ..mixins.climate import TargetTemperatureTests
  17. from ..mixins.light import DimmableLightTests
  18. from ..mixins.switch import SwitchableTests
  19. from .base_device_tests import TuyaDeviceTestCase
  20. SWITCH_DPS = "1"
  21. DIRECTION_DPS = "2"
  22. SPEED_DPS = "3"
  23. UNKNOWN8_DPS = "8"
  24. TEMPERATURE_DPS = "18"
  25. CURTEMP_DPS = "19"
  26. PRESET_DPS = "101"
  27. LIGHT_DPS = "102"
  28. class TestAspenASP200Fan(
  29. DimmableLightTests, SwitchableTests, TargetTemperatureTests, TuyaDeviceTestCase
  30. ):
  31. __test__ = True
  32. def setUp(self):
  33. self.setUpForConfig("aspen_asp200_fan.yaml", ASPEN_ASP200_FAN_PAYLOAD)
  34. self.subject = self.entities.get("fan")
  35. self.climate = self.entities.get("climate")
  36. self.setUpDimmableLight(
  37. LIGHT_DPS,
  38. self.entities.get("light_display"),
  39. offval=0,
  40. tests=[
  41. (1, 85),
  42. (2, 170),
  43. (3, 255),
  44. ],
  45. )
  46. self.setUpSwitchable(SWITCH_DPS, self.subject)
  47. self.setUpTargetTemperature(
  48. TEMPERATURE_DPS,
  49. self.climate,
  50. min=40,
  51. max=95,
  52. )
  53. def test_supported_features(self):
  54. self.assertEqual(
  55. self.subject.supported_features,
  56. SUPPORT_DIRECTION | SUPPORT_PRESET_MODE | SUPPORT_SET_SPEED,
  57. )
  58. self.assertEqual(
  59. self.climate.supported_features,
  60. SUPPORT_TARGET_TEMPERATURE,
  61. )
  62. def test_fan_direction(self):
  63. self.dps[DIRECTION_DPS] = "in"
  64. self.assertEqual(self.subject.current_direction, DIRECTION_FORWARD)
  65. self.dps[DIRECTION_DPS] = "out"
  66. self.assertEqual(self.subject.current_direction, DIRECTION_REVERSE)
  67. self.dps[DIRECTION_DPS] = "exch"
  68. self.assertEqual(self.subject.current_direction, "exchange")
  69. async def test_fan_set_direction_forward(self):
  70. async with assert_device_properties_set(
  71. self.subject._device, {DIRECTION_DPS: "in"}
  72. ):
  73. await self.subject.async_set_direction(DIRECTION_FORWARD)
  74. async def test_fan_set_direction_reverse(self):
  75. async with assert_device_properties_set(
  76. self.subject._device, {DIRECTION_DPS: "out"}
  77. ):
  78. await self.subject.async_set_direction(DIRECTION_REVERSE)
  79. async def test_fan_set_direction_exchange(self):
  80. async with assert_device_properties_set(
  81. self.subject._device, {DIRECTION_DPS: "exch"}
  82. ):
  83. await self.subject.async_set_direction("exchange")
  84. def test_fan_speed(self):
  85. self.dps[SPEED_DPS] = "1"
  86. self.assertAlmostEqual(self.subject.percentage, 33.3, 1)
  87. self.dps[SPEED_DPS] = "2"
  88. self.assertAlmostEqual(self.subject.percentage, 66.7, 1)
  89. self.dps[SPEED_DPS] = "3"
  90. self.assertEqual(self.subject.percentage, 100)
  91. def test_fan_speed_step(self):
  92. self.assertAlmostEqual(self.subject.percentage_step, 33.33, 2)
  93. self.assertEqual(self.subject.speed_count, 3)
  94. async def test_fan_set_speed(self):
  95. async with assert_device_properties_set(
  96. self.subject._device,
  97. {SPEED_DPS: 1},
  98. ):
  99. await self.subject.async_set_percentage(33)
  100. async def test_fan_set_speed_snaps(self):
  101. async with assert_device_properties_set(
  102. self.subject._device,
  103. {SPEED_DPS: 2},
  104. ):
  105. await self.subject.async_set_percentage(80)
  106. def test_fan_preset_modes(self):
  107. self.assertCountEqual(self.subject.preset_modes, ["constant", "auto"])
  108. def test_fan_preset_mode(self):
  109. self.dps[PRESET_DPS] = False
  110. self.assertEqual(self.subject.preset_mode, "constant")
  111. self.dps[PRESET_DPS] = True
  112. self.assertEqual(self.subject.preset_mode, "auto")
  113. async def test_fan_set_preset_to_constant(self):
  114. async with assert_device_properties_set(
  115. self.subject._device,
  116. {PRESET_DPS: False},
  117. ):
  118. await self.subject.async_set_preset_mode("constant")
  119. async def test_fan_set_preset_to_auto(self):
  120. async with assert_device_properties_set(
  121. self.subject._device,
  122. {PRESET_DPS: True},
  123. ):
  124. await self.subject.async_set_preset_mode("auto")
  125. def test_climate_current_temperature(self):
  126. self.dps[CURTEMP_DPS] = 24
  127. self.assertEqual(self.climate.current_temperature, 24)
  128. def test_climate_temperature_unit(self):
  129. self.assertEqual(self.climate.temperature_unit, TEMP_FAHRENHEIT)
  130. def test_climate_hvac_mode(self):
  131. self.dps[SWITCH_DPS] = False
  132. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_OFF)
  133. self.dps[SWITCH_DPS] = True
  134. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_FAN_ONLY)
  135. def test_climate_hvac_modes(self):
  136. self.assertCountEqual(
  137. self.climate.hvac_modes,
  138. [HVAC_MODE_FAN_ONLY, HVAC_MODE_OFF],
  139. )
  140. async def test_climate_turn_on(self):
  141. async with assert_device_properties_set(
  142. self.climate._device,
  143. {SWITCH_DPS: True},
  144. ):
  145. await self.climate.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  146. async def test_climate_turn_off(self):
  147. async with assert_device_properties_set(
  148. self.climate._device,
  149. {SWITCH_DPS: False},
  150. ):
  151. await self.climate.async_set_hvac_mode(HVAC_MODE_OFF)
  152. def test_device_state_attributes(self):
  153. self.dps[UNKNOWN8_DPS] = 8
  154. self.assertDictEqual(self.subject.device_state_attributes, {"unknown_8": 8})
  155. self.assertEqual(self.climate.device_state_attributes, {})