test_kogan_dehumidifier.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. from homeassistant.components.fan import SUPPORT_OSCILLATE, SUPPORT_SET_SPEED
  2. from homeassistant.components.humidifier import SUPPORT_MODES
  3. from homeassistant.const import STATE_UNAVAILABLE
  4. from ..const import KOGAN_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. SWING_DPS = "8"
  11. ERROR_DPS = "11"
  12. TIMER_DPS = "12"
  13. COUNTDOWN_DPS = "13"
  14. HUMIDITY_DPS = "101"
  15. class TestKoganDehumidifier(TuyaDeviceTestCase):
  16. __test__ = True
  17. def setUp(self):
  18. self.setUpForConfig("kogan_dehumidifier.yaml", KOGAN_DEHUMIDIFIER_PAYLOAD)
  19. self.subject = self.entities.get("humidifier")
  20. self.fan = self.entities.get("fan")
  21. def test_supported_features(self):
  22. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  23. self.assertEqual(
  24. self.fan.supported_features,
  25. SUPPORT_OSCILLATE | SUPPORT_SET_SPEED,
  26. )
  27. def test_icon(self):
  28. """Test that the icon is as expected."""
  29. self.dps[SWITCH_DPS] = True
  30. self.dps[MODE_DPS] = "low"
  31. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  32. self.dps[SWITCH_DPS] = False
  33. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  34. self.dps[MODE_DPS] = "quickdry"
  35. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  36. self.dps[SWITCH_DPS] = True
  37. self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
  38. self.dps[ERROR_DPS] = 1
  39. self.assertEqual(self.subject.icon, "mdi:cup-water")
  40. def test_min_target_humidity(self):
  41. self.assertEqual(self.subject.min_humidity, 0)
  42. def test_max_target_humidity(self):
  43. self.assertEqual(self.subject.max_humidity, 80)
  44. def test_target_humidity(self):
  45. self.dps[HUMIDITY_DPS] = 55
  46. self.assertEqual(self.subject.target_humidity, 55)
  47. def test_is_on(self):
  48. self.dps[SWITCH_DPS] = True
  49. self.assertTrue(self.subject.is_on)
  50. self.assertTrue(self.fan.is_on)
  51. self.dps[SWITCH_DPS] = False
  52. self.assertFalse(self.subject.is_on)
  53. self.assertFalse(self.fan.is_on)
  54. self.dps[SWITCH_DPS] = None
  55. self.assertEqual(self.subject.is_on, STATE_UNAVAILABLE)
  56. self.assertEqual(self.fan.is_on, STATE_UNAVAILABLE)
  57. async def test_turn_on(self):
  58. async with assert_device_properties_set(
  59. self.subject._device, {SWITCH_DPS: True}
  60. ):
  61. await self.subject.async_turn_on()
  62. async def test_turn_off(self):
  63. async with assert_device_properties_set(
  64. self.subject._device, {SWITCH_DPS: False}
  65. ):
  66. await self.subject.async_turn_off()
  67. async def test_fan_turn_on(self):
  68. async with assert_device_properties_set(
  69. self.subject._device, {SWITCH_DPS: True}
  70. ):
  71. await self.fan.async_turn_on()
  72. async def test_fan_turn_off(self):
  73. async with assert_device_properties_set(
  74. self.subject._device, {SWITCH_DPS: False}
  75. ):
  76. await self.fan.async_turn_off()
  77. def test_modes(self):
  78. self.assertCountEqual(
  79. self.subject.available_modes,
  80. {
  81. "Low",
  82. "Medium",
  83. "High",
  84. "Dry Clothes",
  85. },
  86. )
  87. def test_mode(self):
  88. self.dps[MODE_DPS] = "low"
  89. self.assertEqual(self.subject.mode, "Low")
  90. self.dps[MODE_DPS] = "middle"
  91. self.assertEqual(self.subject.mode, "Medium")
  92. self.dps[MODE_DPS] = "high"
  93. self.assertEqual(self.subject.mode, "High")
  94. self.dps[MODE_DPS] = "quickdry"
  95. self.assertEqual(self.subject.mode, "Dry Clothes")
  96. async def test_set_mode_to_low(self):
  97. async with assert_device_properties_set(
  98. self.subject._device,
  99. {
  100. MODE_DPS: "low",
  101. },
  102. ):
  103. await self.subject.async_set_mode("Low")
  104. self.subject._device.anticipate_property_value.assert_not_called()
  105. async def test_set_mode_to_medium(self):
  106. async with assert_device_properties_set(
  107. self.subject._device,
  108. {
  109. MODE_DPS: "middle",
  110. },
  111. ):
  112. await self.subject.async_set_mode("Medium")
  113. self.subject._device.anticipate_property_value.assert_not_called()
  114. async def test_set_mode_to_high(self):
  115. async with assert_device_properties_set(
  116. self.subject._device,
  117. {
  118. MODE_DPS: "high",
  119. },
  120. ):
  121. await self.subject.async_set_mode("High")
  122. self.subject._device.anticipate_property_value.assert_not_called()
  123. async def test_set_mode_to_clothes(self):
  124. async with assert_device_properties_set(
  125. self.subject._device,
  126. {
  127. MODE_DPS: "quickdry",
  128. },
  129. ):
  130. await self.subject.async_set_mode("Dry Clothes")
  131. self.subject._device.anticipate_property_value.assert_not_called()
  132. def test_fan_speed_steps(self):
  133. self.assertEqual(self.fan.speed_count, 3)
  134. def test_fan_speed(self):
  135. self.dps[MODE_DPS] = "low"
  136. self.assertAlmostEqual(self.fan.percentage, 33.3, 1)
  137. self.dps[MODE_DPS] = "middle"
  138. self.assertAlmostEqual(self.fan.percentage, 66.7, 1)
  139. self.dps[MODE_DPS] = "high"
  140. self.assertEqual(self.fan.percentage, 100)
  141. self.dps[MODE_DPS] = "quickdry"
  142. self.assertEqual(self.fan.percentage, 100)
  143. async def test_fan_set_speed_to_low(self):
  144. async with assert_device_properties_set(
  145. self.subject._device,
  146. {
  147. MODE_DPS: "low",
  148. },
  149. ):
  150. await self.fan.async_set_percentage(33)
  151. async def test_fan_set_speed_to_medium(self):
  152. async with assert_device_properties_set(
  153. self.subject._device,
  154. {
  155. MODE_DPS: "middle",
  156. },
  157. ):
  158. await self.fan.async_set_percentage(66)
  159. async def test_fan_set_speed_to_high(self):
  160. async with assert_device_properties_set(
  161. self.subject._device,
  162. {
  163. MODE_DPS: "high",
  164. },
  165. ):
  166. await self.fan.async_set_percentage(100)
  167. def test_fan_oscillating(self):
  168. self.dps[SWING_DPS] = True
  169. self.assertTrue(self.fan.oscillating)
  170. self.dps[SWING_DPS] = False
  171. self.assertFalse(self.fan.oscillating)
  172. async def test_set_fan_oscillate_on(self):
  173. async with assert_device_properties_set(
  174. self.subject._device,
  175. {
  176. SWING_DPS: True,
  177. },
  178. ):
  179. await self.fan.async_oscillate(True)
  180. self.subject._device.anticipate_property_value.assert_not_called()
  181. async def test_set_fan_oscillate_off(self):
  182. async with assert_device_properties_set(
  183. self.subject._device,
  184. {
  185. SWING_DPS: False,
  186. },
  187. ):
  188. await self.fan.async_oscillate(False)
  189. self.subject._device.anticipate_property_value.assert_not_called()
  190. def test_device_state_attributes(self):
  191. self.dps[CURRENTHUMID_DPS] = 55
  192. self.dps[ERROR_DPS] = 1
  193. self.dps[TIMER_DPS] = 3
  194. self.dps[COUNTDOWN_DPS] = 160
  195. self.assertCountEqual(
  196. self.subject.device_state_attributes,
  197. {
  198. "current_humidity": 55,
  199. "error": "Tank full",
  200. "timer_hr": 3,
  201. "timer": 160,
  202. },
  203. )
  204. self.assertEqual(self.fan.device_state_attributes, {})