test_goldair_dehumidifier.py 25 KB

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