test_aspen_adv200_fan.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. self.mark_secondary(["light_display"])
  54. def test_supported_features(self):
  55. self.assertEqual(
  56. self.subject.supported_features,
  57. SUPPORT_DIRECTION | SUPPORT_PRESET_MODE | SUPPORT_SET_SPEED,
  58. )
  59. self.assertEqual(
  60. self.climate.supported_features,
  61. SUPPORT_TARGET_TEMPERATURE,
  62. )
  63. def test_fan_direction(self):
  64. self.dps[DIRECTION_DPS] = "in"
  65. self.assertEqual(self.subject.current_direction, DIRECTION_FORWARD)
  66. self.dps[DIRECTION_DPS] = "out"
  67. self.assertEqual(self.subject.current_direction, DIRECTION_REVERSE)
  68. self.dps[DIRECTION_DPS] = "exch"
  69. self.assertEqual(self.subject.current_direction, "exchange")
  70. async def test_fan_set_direction_forward(self):
  71. async with assert_device_properties_set(
  72. self.subject._device, {DIRECTION_DPS: "in"}
  73. ):
  74. await self.subject.async_set_direction(DIRECTION_FORWARD)
  75. async def test_fan_set_direction_reverse(self):
  76. async with assert_device_properties_set(
  77. self.subject._device, {DIRECTION_DPS: "out"}
  78. ):
  79. await self.subject.async_set_direction(DIRECTION_REVERSE)
  80. async def test_fan_set_direction_exchange(self):
  81. async with assert_device_properties_set(
  82. self.subject._device, {DIRECTION_DPS: "exch"}
  83. ):
  84. await self.subject.async_set_direction("exchange")
  85. def test_fan_speed(self):
  86. self.dps[SPEED_DPS] = "1"
  87. self.assertAlmostEqual(self.subject.percentage, 33.3, 1)
  88. self.dps[SPEED_DPS] = "2"
  89. self.assertAlmostEqual(self.subject.percentage, 66.7, 1)
  90. self.dps[SPEED_DPS] = "3"
  91. self.assertEqual(self.subject.percentage, 100)
  92. def test_fan_speed_step(self):
  93. self.assertAlmostEqual(self.subject.percentage_step, 33.33, 2)
  94. self.assertEqual(self.subject.speed_count, 3)
  95. async def test_fan_set_speed(self):
  96. async with assert_device_properties_set(
  97. self.subject._device,
  98. {SPEED_DPS: 1},
  99. ):
  100. await self.subject.async_set_percentage(33)
  101. async def test_fan_set_speed_snaps(self):
  102. async with assert_device_properties_set(
  103. self.subject._device,
  104. {SPEED_DPS: 2},
  105. ):
  106. await self.subject.async_set_percentage(80)
  107. def test_fan_preset_modes(self):
  108. self.assertCountEqual(self.subject.preset_modes, ["constant", "auto"])
  109. def test_fan_preset_mode(self):
  110. self.dps[PRESET_DPS] = False
  111. self.assertEqual(self.subject.preset_mode, "constant")
  112. self.dps[PRESET_DPS] = True
  113. self.assertEqual(self.subject.preset_mode, "auto")
  114. async def test_fan_set_preset_to_constant(self):
  115. async with assert_device_properties_set(
  116. self.subject._device,
  117. {PRESET_DPS: False},
  118. ):
  119. await self.subject.async_set_preset_mode("constant")
  120. async def test_fan_set_preset_to_auto(self):
  121. async with assert_device_properties_set(
  122. self.subject._device,
  123. {PRESET_DPS: True},
  124. ):
  125. await self.subject.async_set_preset_mode("auto")
  126. def test_climate_current_temperature(self):
  127. self.dps[CURTEMP_DPS] = 24
  128. self.assertEqual(self.climate.current_temperature, 24)
  129. def test_climate_temperature_unit(self):
  130. self.assertEqual(self.climate.temperature_unit, TEMP_FAHRENHEIT)
  131. def test_climate_hvac_mode(self):
  132. self.dps[SWITCH_DPS] = False
  133. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_OFF)
  134. self.dps[SWITCH_DPS] = True
  135. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_FAN_ONLY)
  136. def test_climate_hvac_modes(self):
  137. self.assertCountEqual(
  138. self.climate.hvac_modes,
  139. [HVAC_MODE_FAN_ONLY, HVAC_MODE_OFF],
  140. )
  141. async def test_climate_turn_on(self):
  142. async with assert_device_properties_set(
  143. self.climate._device,
  144. {SWITCH_DPS: True},
  145. ):
  146. await self.climate.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  147. async def test_climate_turn_off(self):
  148. async with assert_device_properties_set(
  149. self.climate._device,
  150. {SWITCH_DPS: False},
  151. ):
  152. await self.climate.async_set_hvac_mode(HVAC_MODE_OFF)
  153. def test_extra_state_attributes(self):
  154. self.dps[UNKNOWN8_DPS] = 8
  155. self.assertDictEqual(self.subject.extra_state_attributes, {"unknown_8": 8})
  156. self.assertEqual(self.climate.extra_state_attributes, {})