test_goldair_dehumidifier.py 25 KB

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