test_kogan_dehumidifier.py 7.8 KB

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