test_aspen_adv200_fan.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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=0,
  37. tests=[
  38. (1, 85),
  39. (2, 170),
  40. (3, 255),
  41. ],
  42. )
  43. self.setUpSwitchable(SWITCH_DPS, self.subject)
  44. self.setUpTargetTemperature(
  45. TEMPERATURE_DPS,
  46. self.climate,
  47. min=40,
  48. max=95,
  49. )
  50. self.mark_secondary(["light_display"])
  51. def test_supported_features(self):
  52. self.assertEqual(
  53. self.subject.supported_features,
  54. (
  55. FanEntityFeature.DIRECTION
  56. | FanEntityFeature.PRESET_MODE
  57. | FanEntityFeature.SET_SPEED
  58. ),
  59. )
  60. self.assertEqual(
  61. self.climate.supported_features,
  62. ClimateEntityFeature.TARGET_TEMPERATURE,
  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.3, 1)
  89. self.dps[SPEED_DPS] = "2"
  90. self.assertAlmostEqual(self.subject.percentage, 66.7, 1)
  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, ["constant", "auto"])
  110. def test_fan_preset_mode(self):
  111. self.dps[PRESET_DPS] = False
  112. self.assertEqual(self.subject.preset_mode, "constant")
  113. self.dps[PRESET_DPS] = True
  114. self.assertEqual(self.subject.preset_mode, "auto")
  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("constant")
  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("auto")
  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, {})