test_goldair_fan.py 11 KB

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