test_electriq_cd25_dehumidifier.py 10 KB

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