test_electriq_cd20_dehumidifier.py 10 KB

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