test_electriq_cd25_dehumidifier.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. from homeassistant.components.fan import SUPPORT_PRESET_MODE
  2. from homeassistant.components.humidifier import SUPPORT_MODES
  3. from homeassistant.components.light import COLOR_MODE_ONOFF
  4. from homeassistant.const import STATE_UNAVAILABLE
  5. from ..const import ELECTRIQ_DEHUMIDIFIER_PAYLOAD
  6. from ..helpers import assert_device_properties_set
  7. from .base_device_tests import TuyaDeviceTestCase
  8. SWITCH_DPS = "1"
  9. MODE_DPS = "2"
  10. CURRENTHUMID_DPS = "3"
  11. HUMIDITY_DPS = "4"
  12. LOCK_DPS = "7"
  13. LIGHT_DPS = "10"
  14. PRESET_DPS = "102"
  15. CURRENTTEMP_DPS = "103"
  16. IONIZER_DPS = "104"
  17. class TestElectriqCD25ProDehumidifier(TuyaDeviceTestCase):
  18. __test__ = True
  19. def setUp(self):
  20. self.setUpForConfig(
  21. "electriq_cd25pro_dehumidifier.yaml", ELECTRIQ_DEHUMIDIFIER_PAYLOAD
  22. )
  23. self.subject = self.entities.get("humidifier")
  24. self.fan = self.entities.get("fan")
  25. self.light = self.entities.get("light")
  26. self.lock = self.entities.get("lock")
  27. self.switch = self.entities.get("switch")
  28. def test_supported_features(self):
  29. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  30. self.assertEqual(self.fan.supported_features, SUPPORT_PRESET_MODE)
  31. def test_icon(self):
  32. """Test that the icon is as expected."""
  33. self.dps[SWITCH_DPS] = True
  34. self.dps[MODE_DPS] = "auto"
  35. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  36. self.dps[SWITCH_DPS] = False
  37. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  38. self.dps[MODE_DPS] = "fan"
  39. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  40. self.dps[SWITCH_DPS] = True
  41. self.assertEqual(self.subject.icon, "mdi:air-purifier")
  42. self.dps[MODE_DPS] = "high"
  43. self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
  44. self.assertEqual(self.light.icon, "mdi:solar-power")
  45. self.assertEqual(self.switch.icon, "mdi:creation")
  46. def test_min_target_humidity(self):
  47. self.assertEqual(self.subject.min_humidity, 35)
  48. def test_max_target_humidity(self):
  49. self.assertEqual(self.subject.max_humidity, 80)
  50. def test_target_humidity(self):
  51. self.dps[HUMIDITY_DPS] = 55
  52. self.assertEqual(self.subject.target_humidity, 55)
  53. async def test_set_target_humidity_rounds_up_to_5_percent(self):
  54. async with assert_device_properties_set(
  55. self.subject._device,
  56. {HUMIDITY_DPS: 55},
  57. ):
  58. await self.subject.async_set_humidity(53)
  59. async def test_set_target_humidity_rounds_down_to_5_percent(self):
  60. async with assert_device_properties_set(
  61. self.subject._device,
  62. {HUMIDITY_DPS: 50},
  63. ):
  64. await self.subject.async_set_humidity(52)
  65. def test_is_on(self):
  66. self.dps[SWITCH_DPS] = True
  67. self.assertTrue(self.subject.is_on)
  68. self.assertTrue(self.fan.is_on)
  69. self.dps[SWITCH_DPS] = False
  70. self.assertFalse(self.subject.is_on)
  71. self.assertFalse(self.fan.is_on)
  72. self.dps[SWITCH_DPS] = None
  73. self.assertEqual(self.subject.is_on, STATE_UNAVAILABLE)
  74. self.assertEqual(self.fan.is_on, STATE_UNAVAILABLE)
  75. async def test_turn_on(self):
  76. async with assert_device_properties_set(
  77. self.subject._device, {SWITCH_DPS: True}
  78. ):
  79. await self.subject.async_turn_on()
  80. async def test_turn_off(self):
  81. async with assert_device_properties_set(
  82. self.subject._device, {SWITCH_DPS: False}
  83. ):
  84. await self.subject.async_turn_off()
  85. async def test_fan_turn_on(self):
  86. async with assert_device_properties_set(
  87. self.subject._device, {SWITCH_DPS: True}
  88. ):
  89. await self.fan.async_turn_on()
  90. async def test_fan_turn_off(self):
  91. async with assert_device_properties_set(
  92. self.subject._device, {SWITCH_DPS: False}
  93. ):
  94. await self.fan.async_turn_off()
  95. def test_mode(self):
  96. self.dps[MODE_DPS] = "low"
  97. self.assertEqual(self.subject.mode, "Low")
  98. self.dps[MODE_DPS] = "high"
  99. self.assertEqual(self.subject.mode, "High")
  100. self.dps[MODE_DPS] = "auto"
  101. self.assertEqual(self.subject.mode, "Auto")
  102. self.dps[MODE_DPS] = "fan"
  103. self.assertEqual(self.subject.mode, "Air clean")
  104. async def test_set_mode_to_auto(self):
  105. async with assert_device_properties_set(
  106. self.subject._device,
  107. {
  108. MODE_DPS: "auto",
  109. },
  110. ):
  111. await self.subject.async_set_mode("Auto")
  112. self.subject._device.anticipate_property_value.assert_not_called()
  113. async def test_set_mode_to_low(self):
  114. async with assert_device_properties_set(
  115. self.subject._device,
  116. {
  117. MODE_DPS: "low",
  118. },
  119. ):
  120. await self.subject.async_set_mode("Low")
  121. self.subject._device.anticipate_property_value.assert_not_called()
  122. async def test_set_mode_to_high(self):
  123. async with assert_device_properties_set(
  124. self.subject._device,
  125. {
  126. MODE_DPS: "high",
  127. },
  128. ):
  129. await self.subject.async_set_mode("High")
  130. self.subject._device.anticipate_property_value.assert_not_called()
  131. async def test_set_mode_to_fan(self):
  132. async with assert_device_properties_set(
  133. self.subject._device,
  134. {
  135. MODE_DPS: "fan",
  136. },
  137. ):
  138. await self.subject.async_set_mode("Air clean")
  139. self.subject._device.anticipate_property_value.assert_not_called()
  140. def test_fan_preset_mode(self):
  141. self.dps[PRESET_DPS] = "45"
  142. self.assertEqual(self.fan.preset_mode, "Half open")
  143. self.dps[PRESET_DPS] = "90"
  144. self.assertEqual(self.fan.preset_mode, "Fully open")
  145. self.dps[PRESET_DPS] = "0_90"
  146. self.assertEqual(self.fan.preset_mode, "Oscillate")
  147. async def test_set_fan_to_half_open(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {
  151. PRESET_DPS: "45",
  152. },
  153. ):
  154. await self.fan.async_set_preset_mode("Half open")
  155. self.subject._device.anticipate_property_value.assert_not_called()
  156. async def test_set_fan_to_fully_open(self):
  157. async with assert_device_properties_set(
  158. self.subject._device,
  159. {
  160. PRESET_DPS: "90",
  161. },
  162. ):
  163. await self.fan.async_set_preset_mode("Fully open")
  164. self.subject._device.anticipate_property_value.assert_not_called()
  165. async def test_set_fan_to_oscillate(self):
  166. async with assert_device_properties_set(
  167. self.subject._device,
  168. {
  169. PRESET_DPS: "0_90",
  170. },
  171. ):
  172. await self.fan.async_set_preset_mode("Oscillate")
  173. self.subject._device.anticipate_property_value.assert_not_called()
  174. def test_lock_is_locked(self):
  175. self.dps[LOCK_DPS] = True
  176. self.assertTrue(self.lock.is_locked)
  177. self.dps[LOCK_DPS] = False
  178. self.assertFalse(self.lock.is_locked)
  179. self.dps[LOCK_DPS] = None
  180. self.assertFalse(self.lock.is_locked)
  181. async def test_lock_locks(self):
  182. async with assert_device_properties_set(self.lock._device, {LOCK_DPS: True}):
  183. await self.lock.async_lock()
  184. async def test_lock_unlocks(self):
  185. async with assert_device_properties_set(self.lock._device, {LOCK_DPS: False}):
  186. await self.lock.async_unlock()
  187. def test_light_supported_color_modes(self):
  188. self.assertCountEqual(
  189. self.light.supported_color_modes,
  190. [COLOR_MODE_ONOFF],
  191. )
  192. def test_light_color_mode(self):
  193. self.assertEqual(self.light.color_mode, COLOR_MODE_ONOFF)
  194. def test_light_is_on(self):
  195. self.dps[LIGHT_DPS] = True
  196. self.assertTrue(self.light.is_on)
  197. self.dps[LIGHT_DPS] = False
  198. self.assertFalse(self.light.is_on)
  199. async def test_light_turn_on(self):
  200. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: True}):
  201. await self.light.async_turn_on()
  202. async def test_light_turn_off(self):
  203. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: False}):
  204. await self.light.async_turn_off()
  205. async def test_toggle_turns_the_light_on_when_it_was_off(self):
  206. self.dps[LIGHT_DPS] = False
  207. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: True}):
  208. await self.light.async_toggle()
  209. async def test_toggle_turns_the_light_off_when_it_was_on(self):
  210. self.dps[LIGHT_DPS] = True
  211. async with assert_device_properties_set(self.light._device, {LIGHT_DPS: False}):
  212. await self.light.async_toggle()
  213. def test_switch_is_on(self):
  214. self.dps[IONIZER_DPS] = True
  215. self.assertTrue(self.switch.is_on)
  216. self.dps[IONIZER_DPS] = False
  217. self.assertFalse(self.switch.is_on)
  218. async def test_switch_turn_on(self):
  219. async with assert_device_properties_set(
  220. self.switch._device, {IONIZER_DPS: True}
  221. ):
  222. await self.switch.async_turn_on()
  223. async def test_switch_turn_off(self):
  224. async with assert_device_properties_set(
  225. self.switch._device, {IONIZER_DPS: False}
  226. ):
  227. await self.switch.async_turn_off()
  228. async def test_toggle_turns_the_switch_on_when_it_was_off(self):
  229. self.dps[IONIZER_DPS] = False
  230. async with assert_device_properties_set(
  231. self.switch._device, {IONIZER_DPS: True}
  232. ):
  233. await self.switch.async_toggle()
  234. async def test_toggle_turns_the_switch_off_when_it_was_on(self):
  235. self.dps[IONIZER_DPS] = True
  236. async with assert_device_properties_set(
  237. self.switch._device, {IONIZER_DPS: False}
  238. ):
  239. await self.switch.async_toggle()
  240. def test_state_attributes(self):
  241. self.dps[CURRENTHUMID_DPS] = 50
  242. self.dps[CURRENTTEMP_DPS] = 21
  243. self.assertDictEqual(
  244. self.subject.device_state_attributes,
  245. {"current_humidity": 50, "current_temperature": 21},
  246. )
  247. self.assertEqual(self.fan.device_state_attributes, {})
  248. self.assertEqual(self.light.device_state_attributes, {})
  249. self.assertEqual(self.lock.device_state_attributes, {})
  250. self.assertEqual(self.switch.device_state_attributes, {})