test_electriq_dehumidifier.py 10 KB

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