test_goldair_dehumidifier.py 22 KB

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