test_goldair_fan.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. from homeassistant.components.climate.const import (
  2. HVAC_MODE_FAN_ONLY,
  3. HVAC_MODE_OFF,
  4. PRESET_ECO,
  5. PRESET_SLEEP,
  6. SUPPORT_FAN_MODE,
  7. SUPPORT_PRESET_MODE as SUPPORT_CLIMATE_PRESET,
  8. SUPPORT_SWING_MODE,
  9. SWING_HORIZONTAL,
  10. SWING_OFF,
  11. )
  12. from homeassistant.components.fan import (
  13. SUPPORT_OSCILLATE,
  14. SUPPORT_PRESET_MODE,
  15. SUPPORT_SET_SPEED,
  16. )
  17. from homeassistant.const import STATE_UNAVAILABLE
  18. from ..const import FAN_PAYLOAD
  19. from ..helpers import assert_device_properties_set
  20. from ..mixins.light import BasicLightTests
  21. from ..mixins.switch import SwitchableTests
  22. from .base_device_tests import TuyaDeviceTestCase
  23. HVACMODE_DPS = "1"
  24. FANMODE_DPS = "2"
  25. PRESET_DPS = "3"
  26. SWING_DPS = "8"
  27. TIMER_DPS = "11"
  28. LIGHT_DPS = "101"
  29. class TestGoldairFan(BasicLightTests, SwitchableTests, TuyaDeviceTestCase):
  30. __test__ = True
  31. def setUp(self):
  32. self.setUpForConfig("goldair_fan.yaml", FAN_PAYLOAD)
  33. self.subject = self.entities.get("fan")
  34. self.climate = self.entities.get("climate")
  35. self.setUpSwitchable(HVACMODE_DPS, self.subject)
  36. self.setUpBasicLight(LIGHT_DPS, self.entities.get("light_display"))
  37. self.mark_secondary(["light_display"])
  38. def test_supported_features(self):
  39. self.assertEqual(
  40. self.subject.supported_features,
  41. SUPPORT_OSCILLATE | SUPPORT_PRESET_MODE | SUPPORT_SET_SPEED,
  42. )
  43. self.assertEqual(
  44. self.climate.supported_features,
  45. SUPPORT_FAN_MODE | SUPPORT_CLIMATE_PRESET | SUPPORT_SWING_MODE,
  46. )
  47. def test_climate_icon_is_fan(self):
  48. self.dps[HVACMODE_DPS] = True
  49. self.assertEqual(self.climate.icon, "mdi:fan")
  50. self.dps[HVACMODE_DPS] = False
  51. self.assertEqual(self.climate.icon, "mdi:fan-off")
  52. def test_temperature_unit_returns_device_temperature_unit(self):
  53. self.assertEqual(
  54. self.climate.temperature_unit, self.climate._device.temperature_unit
  55. )
  56. def test_is_on(self):
  57. self.dps[HVACMODE_DPS] = True
  58. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_FAN_ONLY)
  59. self.assertTrue(self.subject.is_on)
  60. self.dps[HVACMODE_DPS] = False
  61. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_OFF)
  62. self.assertFalse(self.subject.is_on)
  63. self.dps[HVACMODE_DPS] = None
  64. self.assertEqual(self.climate.hvac_mode, STATE_UNAVAILABLE)
  65. self.assertIsNone(self.subject.is_on)
  66. def test_climate_hvac_modes(self):
  67. self.assertCountEqual(
  68. self.climate.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_FAN_ONLY]
  69. )
  70. async def test_climate_turn_on(self):
  71. async with assert_device_properties_set(
  72. self.climate._device, {HVACMODE_DPS: True}
  73. ):
  74. await self.climate.async_set_hvac_mode(HVAC_MODE_FAN_ONLY)
  75. async def test_climate_turn_off(self):
  76. async with assert_device_properties_set(
  77. self.climate._device, {HVACMODE_DPS: False}
  78. ):
  79. await self.climate.async_set_hvac_mode(HVAC_MODE_OFF)
  80. async def test_turn_on(self):
  81. async with assert_device_properties_set(
  82. self.subject._device, {HVACMODE_DPS: True}
  83. ):
  84. await self.subject.async_turn_on()
  85. async def test_turn_off(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {HVACMODE_DPS: False}
  88. ):
  89. await self.subject.async_turn_off()
  90. def test_preset_mode(self):
  91. self.dps[PRESET_DPS] = "normal"
  92. self.assertEqual(self.climate.preset_mode, "normal")
  93. self.assertEqual(self.subject.preset_mode, "normal")
  94. self.dps[PRESET_DPS] = "nature"
  95. self.assertEqual(self.climate.preset_mode, PRESET_ECO)
  96. self.assertEqual(self.subject.preset_mode, "nature")
  97. self.dps[PRESET_DPS] = PRESET_SLEEP
  98. self.assertEqual(self.climate.preset_mode, PRESET_SLEEP)
  99. self.assertEqual(self.subject.preset_mode, PRESET_SLEEP)
  100. self.dps[PRESET_DPS] = None
  101. self.assertIs(self.climate.preset_mode, None)
  102. def test_preset_modes(self):
  103. self.assertCountEqual(
  104. self.climate.preset_modes, ["normal", PRESET_ECO, PRESET_SLEEP]
  105. )
  106. self.assertCountEqual(self.subject.preset_modes, ["normal", "nature", "sleep"])
  107. async def test_set_climate_preset_mode_to_normal(self):
  108. async with assert_device_properties_set(
  109. self.climate._device,
  110. {PRESET_DPS: "normal"},
  111. ):
  112. await self.climate.async_set_preset_mode("normal")
  113. async def test_set_climate_preset_mode_to_eco(self):
  114. async with assert_device_properties_set(
  115. self.climate._device,
  116. {PRESET_DPS: "nature"},
  117. ):
  118. await self.climate.async_set_preset_mode(PRESET_ECO)
  119. async def test_set_climate_preset_mode_to_sleep(self):
  120. async with assert_device_properties_set(
  121. self.climate._device,
  122. {PRESET_DPS: PRESET_SLEEP},
  123. ):
  124. await self.climate.async_set_preset_mode(PRESET_SLEEP)
  125. async def test_set_preset_mode_to_normal(self):
  126. async with assert_device_properties_set(
  127. self.subject._device,
  128. {PRESET_DPS: "normal"},
  129. ):
  130. await self.subject.async_set_preset_mode("normal")
  131. async def test_set_preset_mode_to_nature(self):
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {PRESET_DPS: "nature"},
  135. ):
  136. await self.subject.async_set_preset_mode("nature")
  137. async def test_set_preset_mode_to_sleep(self):
  138. async with assert_device_properties_set(
  139. self.subject._device,
  140. {PRESET_DPS: "sleep"},
  141. ):
  142. await self.subject.async_set_preset_mode("sleep")
  143. def test_swing_mode(self):
  144. self.dps[SWING_DPS] = False
  145. self.assertEqual(self.climate.swing_mode, SWING_OFF)
  146. self.assertFalse(self.subject.oscillating)
  147. self.dps[SWING_DPS] = True
  148. self.assertEqual(self.climate.swing_mode, SWING_HORIZONTAL)
  149. self.assertTrue(self.subject.oscillating)
  150. self.dps[SWING_DPS] = None
  151. self.assertIs(self.climate.swing_mode, None)
  152. self.assertFalse(self.subject.oscillating)
  153. def test_swing_modes(self):
  154. self.assertCountEqual(self.climate.swing_modes, [SWING_OFF, SWING_HORIZONTAL])
  155. async def test_climate_set_swing_mode_to_off(self):
  156. async with assert_device_properties_set(
  157. self.climate._device,
  158. {SWING_DPS: False},
  159. ):
  160. await self.climate.async_set_swing_mode(SWING_OFF)
  161. async def test_climate_set_swing_mode_to_horizontal(self):
  162. async with assert_device_properties_set(
  163. self.climate._device,
  164. {SWING_DPS: True},
  165. ):
  166. await self.climate.async_set_swing_mode(SWING_HORIZONTAL)
  167. async def test_oscillate_off(self):
  168. async with assert_device_properties_set(
  169. self.subject._device, {SWING_DPS: False}
  170. ):
  171. await self.subject.async_oscillate(False)
  172. async def test_oscillate_on(self):
  173. async with assert_device_properties_set(
  174. self.subject._device, {SWING_DPS: True}
  175. ):
  176. await self.subject.async_oscillate(True)
  177. def test_speed(self):
  178. self.dps[PRESET_DPS] = "normal"
  179. self.dps[FANMODE_DPS] = 6
  180. self.assertEqual(self.subject.percentage, 50)
  181. async def test_set_speed_in_normal_mode(self):
  182. self.dps[PRESET_DPS] = "normal"
  183. async with assert_device_properties_set(self.subject._device, {FANMODE_DPS: 3}):
  184. await self.subject.async_set_percentage(25)
  185. async def test_set_speed_in_normal_mode_snaps(self):
  186. self.dps[PRESET_DPS] = "normal"
  187. async with assert_device_properties_set(
  188. self.subject._device, {FANMODE_DPS: 10}
  189. ):
  190. await self.subject.async_set_percentage(80)
  191. async def test_set_speed_in_sleep_mode_snaps(self):
  192. self.dps[PRESET_DPS] = "sleep"
  193. async with assert_device_properties_set(self.subject._device, {FANMODE_DPS: 8}):
  194. await self.subject.async_set_percentage(75)
  195. def test_climate_fan_modes(self):
  196. self.dps[PRESET_DPS] = "normal"
  197. self.assertCountEqual(self.climate.fan_modes, list(range(1, 13)))
  198. self.dps[PRESET_DPS] = "nature"
  199. self.assertCountEqual(self.climate.fan_modes, ["low", "medium", "high"])
  200. self.dps[PRESET_DPS] = PRESET_SLEEP
  201. self.assertCountEqual(self.climate.fan_modes, ["low", "medium", "high"])
  202. self.dps[PRESET_DPS] = None
  203. self.assertEqual(self.climate.fan_modes, None)
  204. def test_climate_fan_mode_for_normal_preset(self):
  205. self.dps[PRESET_DPS] = "normal"
  206. self.dps[FANMODE_DPS] = 1
  207. self.assertEqual(self.climate.fan_mode, 1)
  208. self.dps[FANMODE_DPS] = 6
  209. self.assertEqual(self.climate.fan_mode, 6)
  210. self.dps[FANMODE_DPS] = 12
  211. self.assertEqual(self.climate.fan_mode, 12)
  212. self.dps[FANMODE_DPS] = None
  213. self.assertEqual(self.climate.fan_mode, None)
  214. async def test_climate_set_fan_mode_for_normal_preset(self):
  215. self.dps[PRESET_DPS] = "normal"
  216. async with assert_device_properties_set(
  217. self.climate._device,
  218. {FANMODE_DPS: 6},
  219. ):
  220. await self.climate.async_set_fan_mode(6)
  221. def test_climate_fan_mode_for_eco_preset(self):
  222. self.dps[PRESET_DPS] = "nature"
  223. self.dps[FANMODE_DPS] = 4
  224. self.assertEqual(self.climate.fan_mode, "low")
  225. self.dps[FANMODE_DPS] = 8
  226. self.assertEqual(self.climate.fan_mode, "medium")
  227. self.dps[FANMODE_DPS] = 12
  228. self.assertEqual(self.climate.fan_mode, "high")
  229. self.dps[FANMODE_DPS] = None
  230. self.assertEqual(self.climate.fan_mode, None)
  231. async def test_climate_set_fan_mode_for_eco_preset(self):
  232. self.dps[PRESET_DPS] = "nature"
  233. async with assert_device_properties_set(
  234. self.climate._device,
  235. {FANMODE_DPS: 4},
  236. ):
  237. await self.climate.async_set_fan_mode("low")
  238. def test_climate_fan_mode_for_sleep_preset(self):
  239. self.dps[PRESET_DPS] = PRESET_SLEEP
  240. self.dps[FANMODE_DPS] = 4
  241. self.assertEqual(self.climate.fan_mode, "low")
  242. self.dps[FANMODE_DPS] = 8
  243. self.assertEqual(self.climate.fan_mode, "medium")
  244. self.dps[FANMODE_DPS] = 12
  245. self.assertEqual(self.climate.fan_mode, "high")
  246. self.dps[FANMODE_DPS] = None
  247. self.assertEqual(self.climate.fan_mode, None)
  248. async def test_climate_set_fan_mode_for_sleep_preset(self):
  249. self.dps[PRESET_DPS] = PRESET_SLEEP
  250. async with assert_device_properties_set(
  251. self.climate._device,
  252. {FANMODE_DPS: 8},
  253. ):
  254. await self.climate.async_set_fan_mode("medium")
  255. def test_extra_state_attributes(self):
  256. self.dps[TIMER_DPS] = "5"
  257. self.assertEqual(self.climate.extra_state_attributes, {"timer": "5"})
  258. self.assertEqual(self.subject.extra_state_attributes, {"timer": "5"})
  259. def test_light_icon(self):
  260. self.dps[LIGHT_DPS] = True
  261. self.assertEqual(self.basicLight.icon, "mdi:led-on")
  262. self.dps[LIGHT_DPS] = False
  263. self.assertEqual(self.basicLight.icon, "mdi:led-off")