test_goldair_dehumidifier.py 24 KB

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