test_aspen_adv200_fan.py 6.4 KB

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