test_goldair_dehumidifier.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. from unittest import IsolatedAsyncioTestCase, skip
  2. from unittest.mock import AsyncMock, patch
  3. from homeassistant.components.climate.const import (
  4. FAN_HIGH,
  5. FAN_LOW,
  6. HVAC_MODE_DRY,
  7. HVAC_MODE_OFF,
  8. SUPPORT_FAN_MODE,
  9. SUPPORT_PRESET_MODE,
  10. SUPPORT_TARGET_HUMIDITY,
  11. )
  12. from homeassistant.components.humidifier.const import SUPPORT_MODES
  13. from homeassistant.components.lock import STATE_LOCKED, STATE_UNLOCKED
  14. from homeassistant.const import ATTR_TEMPERATURE, STATE_UNAVAILABLE
  15. from custom_components.tuya_local.generic.climate import TuyaLocalClimate
  16. from custom_components.tuya_local.generic.fan import TuyaLocalFan
  17. from custom_components.tuya_local.generic.humidifier import TuyaLocalHumidifier
  18. from custom_components.tuya_local.generic.light import TuyaLocalLight
  19. from custom_components.tuya_local.generic.lock import TuyaLocalLock
  20. from custom_components.tuya_local.helpers.device_config import TuyaDeviceConfig
  21. from ..const import DEHUMIDIFIER_PAYLOAD
  22. from ..helpers import assert_device_properties_set
  23. HVACMODE_DPS = "1"
  24. PRESET_DPS = "2"
  25. HUMIDITY_DPS = "4"
  26. AIRCLEAN_DPS = "5"
  27. FANMODE_DPS = "6"
  28. LOCK_DPS = "7"
  29. ERROR_DPS = "11"
  30. UNKNOWN12_DPS = "12"
  31. UNKNOWN101_DPS = "101"
  32. LIGHTOFF_DPS = "102"
  33. CURRENTTEMP_DPS = "103"
  34. CURRENTHUMID_DPS = "104"
  35. DEFROST_DPS = "105"
  36. PRESET_NORMAL = "0"
  37. PRESET_LOW = "1"
  38. PRESET_HIGH = "2"
  39. PRESET_DRY_CLOTHES = "3"
  40. ERROR_TANK = "Tank full or missing"
  41. class TestGoldairDehumidifier(IsolatedAsyncioTestCase):
  42. def setUp(self):
  43. device_patcher = patch("custom_components.tuya_local.device.TuyaLocalDevice")
  44. self.addCleanup(device_patcher.stop)
  45. self.mock_device = device_patcher.start()
  46. cfg = TuyaDeviceConfig("goldair_dehumidifier.yaml")
  47. entities = {}
  48. entities[cfg.primary_entity.entity] = cfg.primary_entity
  49. for e in cfg.secondary_entities():
  50. entities[e.entity] = e
  51. self.climate_name = (
  52. "missing" if "climate" not in entities else entities["climate"].name
  53. )
  54. self.light_name = (
  55. "missing" if "light" not in entities else entities["light"].name
  56. )
  57. self.lock_name = "missing" if "lock" not in entities else entities["lock"].name
  58. self.humidifier_name = (
  59. "missing" if "humidifier" not in entities else entities["humidifier"].name
  60. )
  61. self.fan_name = "missing" if "fan" not in entities else entities["fan"].name
  62. self.subject = TuyaLocalClimate(self.mock_device(), entities.get("climate"))
  63. self.light = TuyaLocalLight(self.mock_device(), entities.get("light"))
  64. self.lock = TuyaLocalLock(self.mock_device(), entities.get("lock"))
  65. self.humidifier = TuyaLocalHumidifier(
  66. self.mock_device(), entities.get("humidifier")
  67. )
  68. self.fan = TuyaLocalFan(self.mock_device(), entities.get("fan"))
  69. self.dps = DEHUMIDIFIER_PAYLOAD.copy()
  70. self.subject._device.get_property.side_effect = lambda id: self.dps[id]
  71. def test_supported_features(self):
  72. self.assertEqual(
  73. self.subject.supported_features,
  74. SUPPORT_TARGET_HUMIDITY | SUPPORT_PRESET_MODE | SUPPORT_FAN_MODE,
  75. )
  76. def test_should_poll(self):
  77. self.assertTrue(self.subject.should_poll)
  78. self.assertTrue(self.fan.should_poll)
  79. self.assertTrue(self.light.should_poll)
  80. self.assertTrue(self.lock.should_poll)
  81. self.assertTrue(self.humidifier.should_poll)
  82. def test_name_returns_device_name(self):
  83. self.assertEqual(self.subject.name, self.subject._device.name)
  84. self.assertEqual(self.fan.name, self.subject._device.name)
  85. self.assertEqual(self.light.name, self.subject._device.name)
  86. self.assertEqual(self.lock.name, self.subject._device.name)
  87. self.assertEqual(self.humidifier.name, self.subject._device.name)
  88. def test_friendly_name_returns_config_name(self):
  89. self.assertEqual(self.subject.friendly_name, self.climate_name)
  90. self.assertEqual(self.fan.friendly_name, self.fan_name)
  91. self.assertEqual(self.light.friendly_name, self.light_name)
  92. self.assertEqual(self.lock.friendly_name, self.lock_name)
  93. self.assertEqual(self.humidifier.friendly_name, self.humidifier_name)
  94. def test_unique_id_returns_device_unique_id(self):
  95. self.assertEqual(self.subject.unique_id, self.subject._device.unique_id)
  96. self.assertEqual(self.fan.unique_id, self.subject._device.unique_id)
  97. self.assertEqual(self.light.unique_id, self.subject._device.unique_id)
  98. self.assertEqual(self.lock.unique_id, self.subject._device.unique_id)
  99. self.assertEqual(self.humidifier.unique_id, self.subject._device.unique_id)
  100. def test_device_info_returns_device_info_from_device(self):
  101. self.assertEqual(self.subject.device_info, self.subject._device.device_info)
  102. self.assertEqual(self.fan.device_info, self.subject._device.device_info)
  103. self.assertEqual(self.light.device_info, self.subject._device.device_info)
  104. self.assertEqual(self.lock.device_info, self.subject._device.device_info)
  105. self.assertEqual(self.humidifier.device_info, self.subject._device.device_info)
  106. @skip("Icon customisation not supported yet")
  107. def test_icon_is_always_standard_when_off_without_error(self):
  108. self.dps[ERROR_DPS] = None
  109. self.dps[HVACMODE_DPS] = False
  110. self.dps[AIRCLEAN_DPS] = False
  111. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  112. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  113. self.dps[AIRCLEAN_DPS] = True
  114. self.dps[PRESET_DPS] = PRESET_NORMAL
  115. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  116. @skip("Icon customisation not supported yet")
  117. def test_icon_is_purifier_when_air_clean_is_active(self):
  118. self.dps[ERROR_DPS] = None
  119. self.dps[HVACMODE_DPS] = True
  120. self.dps[AIRCLEAN_DPS] = True
  121. self.assertEqual(self.subject.icon, "mdi:air-purifier")
  122. @skip("Icon customisation not supported yet")
  123. def test_icon_is_tshirt_when_dry_clothes_is_active(self):
  124. self.dps[ERROR_DPS] = None
  125. self.dps[HVACMODE_DPS] = True
  126. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  127. self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
  128. @skip("Icon customisation not supported yet")
  129. def test_icon_is_always_melting_snowflake_when_defrosting_and_tank_not_full(self):
  130. self.dps[DEFROST_DPS] = True
  131. self.dps[HVACMODE_DPS] = False
  132. self.assertEqual(self.subject.icon, "mdi:snowflake-melt")
  133. self.dps[HVACMODE_DPS] = True
  134. self.assertEqual(self.subject.icon, "mdi:snowflake-melt")
  135. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  136. self.assertEqual(self.subject.icon, "mdi:snowflake-melt")
  137. self.dps[AIRCLEAN_DPS] = True
  138. self.dps[PRESET_DPS] = PRESET_NORMAL
  139. self.assertEqual(self.subject.icon, "mdi:snowflake-melt")
  140. @skip("Icon customisation not supported yet")
  141. def test_icon_is_always_tank_when_tank_full_error_is_present(self):
  142. self.dps[ERROR_DPS] = 8
  143. self.dps[HVACMODE_DPS] = False
  144. self.assertEqual(self.subject.icon, "mdi:cup-water")
  145. self.dps[HVACMODE_DPS] = True
  146. self.assertEqual(self.subject.icon, "mdi:cup-water")
  147. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  148. self.assertEqual(self.subject.icon, "mdi:cup-water")
  149. self.dps[AIRCLEAN_DPS] = True
  150. self.dps[PRESET_DPS] = PRESET_NORMAL
  151. self.assertEqual(self.subject.icon, "mdi:cup-water")
  152. self.dps[DEFROST_DPS] = True
  153. self.assertEqual(self.subject.icon, "mdi:cup-water")
  154. def test_current_humidity(self):
  155. self.dps[CURRENTHUMID_DPS] = 47
  156. self.assertEqual(self.subject.current_humidity, 47)
  157. def test_min_target_humidity(self):
  158. self.assertEqual(self.subject.min_humidity, 30)
  159. self.assertEqual(self.humidifier.min_humidity, 30)
  160. def test_max_target_humidity(self):
  161. self.assertEqual(self.subject.max_humidity, 80)
  162. self.assertEqual(self.humidifier.max_humidity, 80)
  163. def test_target_humidity_in_normal_preset(self):
  164. self.dps[PRESET_DPS] = PRESET_NORMAL
  165. self.dps[HUMIDITY_DPS] = 55
  166. self.assertEqual(self.subject.target_humidity, 55)
  167. def test_target_humidity_in_humidifier(self):
  168. self.dps[PRESET_DPS] = PRESET_NORMAL
  169. self.dps[HUMIDITY_DPS] = 45
  170. self.assertEqual(self.humidifier.target_humidity, 45)
  171. @skip("Conditions not supported yet")
  172. def test_target_humidity_outside_normal_preset(self):
  173. self.dps[HUMIDITY_DPS] = 55
  174. self.dps[PRESET_DPS] = PRESET_HIGH
  175. self.assertIs(self.subject.target_humidity, None)
  176. self.dps[PRESET_DPS] = PRESET_LOW
  177. self.assertIs(self.subject.target_humidity, None)
  178. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  179. self.assertIs(self.subject.target_humidity, None)
  180. self.dps[PRESET_DPS] = PRESET_NORMAL
  181. self.dps[AIRCLEAN_DPS] = True
  182. self.assertIs(self.subject.target_humidity, None)
  183. async def test_set_target_humidity_in_normal_preset_rounds_up_to_5_percent(self):
  184. self.dps[PRESET_DPS] = PRESET_NORMAL
  185. async with assert_device_properties_set(
  186. self.subject._device,
  187. {HUMIDITY_DPS: 55},
  188. ):
  189. await self.subject.async_set_humidity(53)
  190. async def test_set_target_humidity_in_normal_preset_rounds_down_to_5_percent(self):
  191. self.dps[PRESET_DPS] = PRESET_NORMAL
  192. async with assert_device_properties_set(
  193. self.subject._device,
  194. {HUMIDITY_DPS: 50},
  195. ):
  196. await self.subject.async_set_humidity(52)
  197. async def test_set_humidity_in_humidifier_rounds_up_to_5_percent(self):
  198. self.dps[PRESET_DPS] = PRESET_NORMAL
  199. async with assert_device_properties_set(
  200. self.humidifier._device,
  201. {HUMIDITY_DPS: 45},
  202. ):
  203. await self.humidifier.async_set_humidity(43)
  204. async def test_set_humidity_in_humidifier_rounds_down_to_5_percent(self):
  205. self.dps[PRESET_DPS] = PRESET_NORMAL
  206. async with assert_device_properties_set(
  207. self.humidifier._device,
  208. {HUMIDITY_DPS: 40},
  209. ):
  210. await self.humidifier.async_set_humidity(42)
  211. @skip("Conditions not supported yet")
  212. async def test_set_target_humidity_raises_error_outside_of_normal_preset(self):
  213. self.dps[PRESET_DPS] = PRESET_LOW
  214. with self.assertRaisesRegex(
  215. ValueError, "Target humidity can only be changed while in Normal mode"
  216. ):
  217. await self.subject.async_set_humidity(50)
  218. self.dps[PRESET_DPS] = PRESET_HIGH
  219. with self.assertRaisesRegex(
  220. ValueError, "Target humidity can only be changed while in Normal mode"
  221. ):
  222. await self.subject.async_set_humidity(50)
  223. self.dps[PRESET_DPS] = PRESET_LOW
  224. with self.assertRaisesRegex(
  225. ValueError, "Target humidity can only be changed while in Normal mode"
  226. ):
  227. await self.subject.async_set_humidity(50)
  228. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  229. with self.assertRaisesRegex(
  230. ValueError, "Target humidity can only be changed while in Normal mode"
  231. ):
  232. await self.subject.async_set_humidity(50)
  233. self.dps[PRESET_DPS] = PRESET_NORMAL
  234. self.dps[AIRCLEAN_DPS] = True
  235. with self.assertRaisesRegex(
  236. ValueError, "Target humidity can only be changed while in Normal mode"
  237. ):
  238. await self.subject.async_set_humidity(50)
  239. def test_temperature_unit_returns_device_temperature_unit(self):
  240. self.assertEqual(
  241. self.subject.temperature_unit, self.subject._device.temperature_unit
  242. )
  243. def test_minimum_target_temperature(self):
  244. self.assertIs(self.subject.min_temp, None)
  245. def test_maximum_target_temperature(self):
  246. self.assertIs(self.subject.max_temp, None)
  247. def test_current_temperature(self):
  248. self.dps[CURRENTTEMP_DPS] = 25
  249. self.assertEqual(self.subject.current_temperature, 25)
  250. def test_hvac_mode(self):
  251. self.dps[HVACMODE_DPS] = True
  252. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_DRY)
  253. self.dps[HVACMODE_DPS] = False
  254. self.assertEqual(self.subject.hvac_mode, HVAC_MODE_OFF)
  255. self.dps[HVACMODE_DPS] = None
  256. self.assertEqual(self.subject.hvac_mode, STATE_UNAVAILABLE)
  257. def test_hvac_modes(self):
  258. self.assertCountEqual(self.subject.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_DRY])
  259. async def test_turn_on(self):
  260. async with assert_device_properties_set(
  261. self.subject._device, {HVACMODE_DPS: True}
  262. ):
  263. await self.subject.async_set_hvac_mode(HVAC_MODE_DRY)
  264. async def test_turn_off(self):
  265. async with assert_device_properties_set(
  266. self.subject._device, {HVACMODE_DPS: False}
  267. ):
  268. await self.subject.async_set_hvac_mode(HVAC_MODE_OFF)
  269. def test_humidifier_is_on(self):
  270. self.dps[HVACMODE_DPS] = True
  271. self.assertTrue(self.humidifier.is_on)
  272. self.dps[HVACMODE_DPS] = False
  273. self.assertFalse(self.humidifier.is_on)
  274. async def test_dehumidifier_turn_on(self):
  275. async with assert_device_properties_set(
  276. self.subject._device, {HVACMODE_DPS: True}
  277. ):
  278. await self.humidifier.async_turn_on()
  279. async def test_dehumidifier_turn_off(self):
  280. async with assert_device_properties_set(
  281. self.subject._device, {HVACMODE_DPS: False}
  282. ):
  283. await self.humidifier.async_turn_off()
  284. def test_preset_mode(self):
  285. self.dps[PRESET_DPS] = PRESET_NORMAL
  286. self.assertEqual(self.subject.preset_mode, "Normal")
  287. self.assertEqual(self.humidifier.mode, "Normal")
  288. self.dps[PRESET_DPS] = PRESET_LOW
  289. self.assertEqual(self.subject.preset_mode, "Low")
  290. self.assertEqual(self.humidifier.mode, "Low")
  291. self.dps[PRESET_DPS] = PRESET_HIGH
  292. self.assertEqual(self.subject.preset_mode, "High")
  293. self.assertEqual(self.humidifier.mode, "High")
  294. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  295. self.assertEqual(self.subject.preset_mode, "Dry clothes")
  296. self.assertEqual(self.humidifier.mode, "Dry clothes")
  297. self.dps[PRESET_DPS] = None
  298. self.assertEqual(self.subject.preset_mode, None)
  299. self.assertEqual(self.humidifier.mode, None)
  300. @skip("Conditions not supported yet")
  301. def test_air_clean_is_surfaced_in_preset_mode(self):
  302. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  303. self.dps[AIRCLEAN_DPS] = True
  304. self.assertEqual(self.subject.preset_mode, "Air clean")
  305. @skip("Conditions not supported yet")
  306. def test_preset_modes(self):
  307. self.assertCountEqual(
  308. self.subject.preset_modes,
  309. [
  310. "Normal",
  311. "Low",
  312. "High",
  313. "Dry clothes",
  314. "Air clean",
  315. ],
  316. )
  317. async def test_set_preset_mode_to_normal(self):
  318. async with assert_device_properties_set(
  319. self.subject._device,
  320. {
  321. PRESET_DPS: PRESET_NORMAL,
  322. },
  323. ):
  324. await self.subject.async_set_preset_mode("Normal")
  325. self.subject._device.anticipate_property_value.assert_not_called()
  326. @skip("Conditions not supported yet")
  327. async def test_set_preset_mode_to_low(self):
  328. async with assert_device_properties_set(
  329. self.subject._device,
  330. {
  331. PRESET_DPS: PRESET_LOW,
  332. },
  333. ):
  334. await self.subject.async_set_preset_mode("Low")
  335. self.subject._device.anticipate_property_value.assert_called_once_with(
  336. FANMODE_DPS, "1"
  337. )
  338. @skip("Conditions not supported yet")
  339. async def test_set_preset_mode_to_high(self):
  340. async with assert_device_properties_set(
  341. self.subject._device,
  342. {
  343. PRESET_DPS: PRESET_HIGH,
  344. },
  345. ):
  346. await self.subject.async_set_preset_mode("High")
  347. self.subject._device.anticipate_property_value.assert_called_once_with(
  348. FANMODE_DPS, "3"
  349. )
  350. @skip("Conditions not supported yet")
  351. async def test_set_preset_mode_to_dry_clothes(self):
  352. async with assert_device_properties_set(
  353. self.subject._device,
  354. {
  355. PRESET_DPS: PRESET_DRY_CLOTHES,
  356. },
  357. ):
  358. await self.subject.async_set_preset_mode("Dry clothes")
  359. self.subject._device.anticipate_property_value.assert_called_once_with(
  360. FANMODE_DPS, "3"
  361. )
  362. @skip("Conditions not supported yet")
  363. async def test_set_preset_mode_to_air_clean(self):
  364. async with assert_device_properties_set(
  365. self.subject._device, {AIRCLEAN_DPS: True}
  366. ):
  367. await self.subject.async_set_preset_mode("Air clean")
  368. self.subject._device.anticipate_property_value.assert_called_once_with(
  369. FANMODE_DPS, "1"
  370. )
  371. @skip("Conditions not supported yet")
  372. def test_fan_mode_is_forced_to_high_in_high_dry_clothes_air_clean_presets(self):
  373. self.dps[FANMODE_DPS] = "1"
  374. self.dps[PRESET_DPS] = PRESET_HIGH
  375. self.assertEqual(self.subject.fan_mode, FAN_HIGH)
  376. self.assertEqual(self.fan.preset_mode, FAN_HIGH)
  377. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  378. self.assertEqual(self.subject.fan_mode, FAN_HIGH)
  379. self.assertEqual(self.fan.preset_mode, FAN_HIGH)
  380. self.dps[PRESET_DPS] = PRESET_NORMAL
  381. self.dps[AIRCLEAN_DPS] = True
  382. self.assertEqual(self.subject.fan_mode, FAN_HIGH)
  383. self.assertEqual(self.subject.preset_mode, FAN_HIGH)
  384. @skip("Conditions not supported yet")
  385. def test_fan_mode_is_forced_to_low_in_low_preset(self):
  386. self.dps[FANMODE_DPS] = "3"
  387. self.dps[PRESET_DPS] = PRESET_LOW
  388. self.assertEqual(self.subject.fan_mode, FAN_LOW)
  389. self.assertEqual(self.fan.preset_mode, FAN_LOW)
  390. def test_fan_mode_reflects_dps_mode_in_normal_preset(self):
  391. self.dps[PRESET_DPS] = PRESET_NORMAL
  392. self.dps[FANMODE_DPS] = "1"
  393. self.assertEqual(self.subject.fan_mode, FAN_LOW)
  394. self.assertEqual(self.fan.preset_mode, FAN_LOW)
  395. self.dps[FANMODE_DPS] = "3"
  396. self.assertEqual(self.subject.fan_mode, FAN_HIGH)
  397. self.assertEqual(self.fan.preset_mode, FAN_HIGH)
  398. self.dps[FANMODE_DPS] = None
  399. self.assertEqual(self.subject.fan_mode, None)
  400. self.assertEqual(self.fan.preset_mode, None)
  401. @skip("Conditions not supported yet")
  402. def test_fan_modes_reflect_preset_mode(self):
  403. self.dps[PRESET_DPS] = PRESET_NORMAL
  404. self.assertCountEqual(self.subject.fan_modes, [FAN_LOW, FAN_HIGH])
  405. self.assertCountEqual(self.fan.preset_modes, [FAN_LOW, FAN_HIGH])
  406. self.dps[PRESET_DPS] = PRESET_LOW
  407. self.assertEqual(self.subject.fan_modes, [FAN_LOW])
  408. self.assertEqual(self.fan.preset_modes, [FAN_LOW])
  409. self.dps[PRESET_DPS] = PRESET_HIGH
  410. self.assertEqual(self.subject.fan_modes, [FAN_HIGH])
  411. self.assertEqual(self.fan.preset_modes, [FAN_HIGH])
  412. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  413. self.assertEqual(self.subject.fan_modes, [FAN_HIGH])
  414. self.assertEqual(self.fan.preset_modes, [FAN_HIGH])
  415. self.dps[PRESET_DPS] = PRESET_NORMAL
  416. self.dps[AIRCLEAN_DPS] = True
  417. self.assertEqual(self.subject.fan_modes, [FAN_HIGH])
  418. self.assertEqual(self.fan.preset_modes, [FAN_HIGH])
  419. async def test_set_fan_mode_to_low_succeeds_in_normal_preset(self):
  420. self.dps[PRESET_DPS] = PRESET_NORMAL
  421. async with assert_device_properties_set(
  422. self.subject._device,
  423. {FANMODE_DPS: "1"},
  424. ):
  425. await self.subject.async_set_fan_mode(FAN_LOW)
  426. async def test_set_fan_mode_to_high_succeeds_in_normal_preset(self):
  427. self.dps[PRESET_DPS] = PRESET_NORMAL
  428. async with assert_device_properties_set(
  429. self.subject._device,
  430. {FANMODE_DPS: "3"},
  431. ):
  432. await self.subject.async_set_fan_mode(FAN_HIGH)
  433. async def test_set_fan_preset_to_low_succeeds_in_normal_preset(self):
  434. self.dps[PRESET_DPS] = PRESET_NORMAL
  435. async with assert_device_properties_set(
  436. self.fan._device,
  437. {FANMODE_DPS: "1"},
  438. ):
  439. await self.fan.async_set_preset_mode(FAN_LOW)
  440. async def test_set_fan_preset_to_high_succeeds_in_normal_preset(self):
  441. self.dps[PRESET_DPS] = PRESET_NORMAL
  442. async with assert_device_properties_set(
  443. self.fan._device,
  444. {FANMODE_DPS: "3"},
  445. ):
  446. await self.fan.async_set_preset_mode(FAN_HIGH)
  447. @skip("Restriction to listed options not supported yet")
  448. async def test_set_fan_mode_fails_with_invalid_mode(self):
  449. self.dps[PRESET_DPS] = PRESET_NORMAL
  450. with self.assertRaisesRegex(ValueError, "Invalid fan mode: something"):
  451. await self.subject.async_set_fan_mode("something")
  452. @skip("Conditions not supported yet")
  453. async def test_set_fan_mode_fails_outside_normal_preset(self):
  454. self.dps[PRESET_DPS] = PRESET_LOW
  455. with self.assertRaisesRegex(
  456. ValueError, "Fan mode can only be changed while in Normal preset mode"
  457. ):
  458. await self.subject.async_set_fan_mode(FAN_HIGH)
  459. self.dps[PRESET_DPS] = PRESET_HIGH
  460. with self.assertRaisesRegex(
  461. ValueError, "Fan mode can only be changed while in Normal preset mode"
  462. ):
  463. await self.subject.async_set_fan_mode(FAN_HIGH)
  464. self.dps[PRESET_DPS] = PRESET_DRY_CLOTHES
  465. with self.assertRaisesRegex(
  466. ValueError, "Fan mode can only be changed while in Normal preset mode"
  467. ):
  468. await self.subject.async_set_fan_mode(FAN_HIGH)
  469. self.dps[PRESET_DPS] = PRESET_NORMAL
  470. self.dps[AIRCLEAN_DPS] = True
  471. with self.assertRaisesRegex(
  472. ValueError, "Fan mode can only be changed while in Normal preset mode"
  473. ):
  474. await self.subject.async_set_fan_mode(FAN_HIGH)
  475. @skip("Redirection not supported yet")
  476. def test_tank_full_or_missing(self):
  477. self.dps[ERROR_DPS] = None
  478. self.assertEqual(self.subject.tank_full_or_missing, False)
  479. self.dps[ERROR_DPS] = 8
  480. self.assertEqual(self.subject.tank_full_or_missing, True)
  481. def test_device_state_attributes(self):
  482. self.dps[ERROR_DPS] = None
  483. self.dps[DEFROST_DPS] = False
  484. self.dps[AIRCLEAN_DPS] = False
  485. self.dps[UNKNOWN12_DPS] = "something"
  486. self.dps[UNKNOWN101_DPS] = False
  487. self.assertCountEqual(
  488. self.subject.device_state_attributes,
  489. {
  490. "error": STATE_UNAVAILABLE,
  491. "defrosting": False,
  492. "air_clean_on": False,
  493. "unknown_12": "something",
  494. "unknown_101": False,
  495. },
  496. )
  497. self.dps[ERROR_DPS] = 8
  498. self.dps[DEFROST_DPS] = True
  499. self.dps[AIRCLEAN_DPS] = True
  500. self.dps[UNKNOWN12_DPS] = "something else"
  501. self.dps[UNKNOWN101_DPS] = True
  502. self.assertCountEqual(
  503. self.subject.device_state_attributes,
  504. {
  505. "error": ERROR_TANK,
  506. "defrosting": True,
  507. "air_clean_on": True,
  508. "unknown_12": "something else",
  509. "unknown_101": True,
  510. },
  511. )
  512. async def test_update(self):
  513. result = AsyncMock()
  514. self.subject._device.async_refresh.return_value = result()
  515. await self.subject.async_update()
  516. self.subject._device.async_refresh.assert_called_once()
  517. result.assert_awaited()
  518. def test_lock_was_created(self):
  519. self.assertIsInstance(self.lock, TuyaLocalLock)
  520. def test_lock_is_same_device(self):
  521. self.assertEqual(self.lock._device, self.subject._device)
  522. def test_lock_state(self):
  523. self.dps[LOCK_DPS] = True
  524. self.assertEqual(self.lock.state, STATE_LOCKED)
  525. self.dps[LOCK_DPS] = False
  526. self.assertEqual(self.lock.state, STATE_UNLOCKED)
  527. self.dps[LOCK_DPS] = None
  528. self.assertEqual(self.lock.state, STATE_UNAVAILABLE)
  529. def test_lock_is_locked(self):
  530. self.dps[LOCK_DPS] = True
  531. self.assertTrue(self.lock.is_locked)
  532. self.dps[LOCK_DPS] = False
  533. self.assertFalse(self.lock.is_locked)
  534. self.dps[LOCK_DPS] = None
  535. self.assertFalse(self.lock.is_locked)
  536. async def async_test_lock_locks(self):
  537. async with assert_device_properties_set(self.lock._device, {LOCK_DPS: True}):
  538. await self.subject.async_lock()
  539. async def async_test_lock_unlocks(self):
  540. async with assert_device_properties_set(self.lock._device, {LOCK_DPS: False}):
  541. await self.subject.async_unlock()
  542. async def async_test_lock_update(self):
  543. result = AsyncMock()
  544. self.lock._device.async_refresh.return_value = result()
  545. await self.lock.async_update()
  546. self.lock._device.async_refresh.assert_called_once()
  547. result.assert_awaited()
  548. def test_light_was_created(self):
  549. self.assertIsInstance(self.light, TuyaLocalLight)
  550. def test_light_is_same_device(self):
  551. self.assertEqual(self.light._device, self.subject._device)
  552. def test_light_icon(self):
  553. self.dps[LIGHTOFF_DPS] = False
  554. self.assertEqual(self.light.icon, "mdi:led-on")
  555. self.dps[LIGHTOFF_DPS] = True
  556. self.assertEqual(self.light.icon, "mdi:led-off")
  557. def test_light_is_on(self):
  558. self.dps[LIGHTOFF_DPS] = False
  559. self.assertEqual(self.light.is_on, True)
  560. self.dps[LIGHTOFF_DPS] = True
  561. self.assertEqual(self.light.is_on, False)
  562. def test_light_state_attributes(self):
  563. self.assertEqual(self.light.device_state_attributes, {})
  564. async def test_light_turn_on(self):
  565. async with assert_device_properties_set(
  566. self.light._device, {LIGHTOFF_DPS: False}
  567. ):
  568. await self.light.async_turn_on()
  569. async def test_light_turn_off(self):
  570. async with assert_device_properties_set(
  571. self.light._device, {LIGHTOFF_DPS: True}
  572. ):
  573. await self.light.async_turn_off()
  574. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  575. self.dps[LIGHTOFF_DPS] = True
  576. async with assert_device_properties_set(
  577. self.light._device, {LIGHTOFF_DPS: False}
  578. ):
  579. await self.light.async_toggle()
  580. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  581. self.dps[LIGHTOFF_DPS] = False
  582. async with assert_device_properties_set(
  583. self.light._device, {LIGHTOFF_DPS: True}
  584. ):
  585. await self.light.async_toggle()
  586. async def test_light_update(self):
  587. result = AsyncMock()
  588. self.light._device.async_refresh.return_value = result()
  589. await self.light.async_update()
  590. self.light._device.async_refresh.assert_called_once()
  591. result.assert_awaited()