test_goldair_dehumidifier.py 23 KB

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