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