test_aspen_adv200_fan.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. from homeassistant.components.climate.const import (
  2. ClimateEntityFeature,
  3. HVACMode,
  4. )
  5. from homeassistant.components.fan import (
  6. DIRECTION_FORWARD,
  7. DIRECTION_REVERSE,
  8. FanEntityFeature,
  9. )
  10. from homeassistant.const import UnitOfTemperature
  11. from ..const import ASPEN_ASP200_FAN_PAYLOAD
  12. from ..helpers import assert_device_properties_set
  13. from ..mixins.climate import TargetTemperatureTests
  14. from ..mixins.light import DimmableLightTests
  15. from ..mixins.switch import SwitchableTests
  16. from .base_device_tests import TuyaDeviceTestCase
  17. SWITCH_DPS = "1"
  18. DIRECTION_DPS = "2"
  19. SPEED_DPS = "3"
  20. UNKNOWN8_DPS = "8"
  21. TEMPERATURE_DPS = "18"
  22. CURTEMP_DPS = "19"
  23. PRESET_DPS = "101"
  24. LIGHT_DPS = "102"
  25. class TestAspenASP200Fan(
  26. DimmableLightTests, SwitchableTests, TargetTemperatureTests, TuyaDeviceTestCase
  27. ):
  28. __test__ = True
  29. def setUp(self):
  30. self.setUpForConfig("aspen_asp200_fan.yaml", ASPEN_ASP200_FAN_PAYLOAD)
  31. self.subject = self.entities.get("fan")
  32. self.climate = self.entities.get("climate")
  33. self.setUpDimmableLight(
  34. LIGHT_DPS,
  35. self.entities.get("light_display"),
  36. offval=1,
  37. tests=[
  38. (1, 51),
  39. (2, 128),
  40. (3, 255),
  41. ],
  42. no_off=True,
  43. )
  44. self.setUpSwitchable(SWITCH_DPS, self.subject)
  45. self.setUpTargetTemperature(
  46. TEMPERATURE_DPS,
  47. self.climate,
  48. min=40,
  49. max=95,
  50. )
  51. self.mark_secondary(["light_display"])
  52. def test_supported_features(self):
  53. self.assertEqual(
  54. self.subject.supported_features,
  55. (
  56. FanEntityFeature.DIRECTION
  57. | FanEntityFeature.PRESET_MODE
  58. | FanEntityFeature.SET_SPEED
  59. ),
  60. )
  61. self.assertEqual(
  62. self.climate.supported_features,
  63. ClimateEntityFeature.TARGET_TEMPERATURE,
  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.3, 1)
  90. self.dps[SPEED_DPS] = "2"
  91. self.assertAlmostEqual(self.subject.percentage, 66.7, 1)
  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, ["constant", "auto"])
  111. def test_fan_preset_mode(self):
  112. self.dps[PRESET_DPS] = False
  113. self.assertEqual(self.subject.preset_mode, "constant")
  114. self.dps[PRESET_DPS] = True
  115. self.assertEqual(self.subject.preset_mode, "auto")
  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("constant")
  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("auto")
  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, {})