test_electriq_cd20_dehumidifier.py 9.7 KB

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