test_aspen_adv200_fan.py 6.4 KB

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