test_goldair_dehumidifier.py 23 KB

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