test_aspen_adv200_fan.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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, 51),
  36. (2, 128),
  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,
  46. max=95,
  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. )
  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, ["normal", "smart"])
  108. def test_fan_preset_mode(self):
  109. self.dps[PRESET_DPS] = False
  110. self.assertEqual(self.subject.preset_mode, "normal")
  111. self.dps[PRESET_DPS] = True
  112. self.assertEqual(self.subject.preset_mode, "smart")
  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("normal")
  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("smart")
  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, UnitOfTemperature.FAHRENHEIT)
  130. def test_climate_hvac_mode(self):
  131. self.dps[SWITCH_DPS] = False
  132. self.assertEqual(self.climate.hvac_mode, HVACMode.OFF)
  133. self.dps[SWITCH_DPS] = True
  134. self.assertEqual(self.climate.hvac_mode, HVACMode.FAN_ONLY)
  135. def test_climate_hvac_modes(self):
  136. self.assertCountEqual(
  137. self.climate.hvac_modes,
  138. [HVACMode.FAN_ONLY, HVACMode.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(HVACMode.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(HVACMode.OFF)
  152. def test_extra_state_attributes(self):
  153. self.dps[UNKNOWN8_DPS] = 8
  154. self.assertDictEqual(self.subject.extra_state_attributes, {"unknown_8": 8})
  155. self.assertEqual(self.climate.extra_state_attributes, {})