test_kogan_dehumidifier.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. self.mark_secondary(["binary_sensor_tank"])
  45. def test_supported_features(self):
  46. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  47. self.assertEqual(
  48. self.fan.supported_features,
  49. SUPPORT_OSCILLATE | SUPPORT_SET_SPEED,
  50. )
  51. def test_icon(self):
  52. """Test that the icon is as expected."""
  53. self.dps[SWITCH_DPS] = True
  54. self.dps[MODE_DPS] = "low"
  55. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  56. self.dps[SWITCH_DPS] = False
  57. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  58. self.dps[MODE_DPS] = "quickdry"
  59. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  60. self.dps[SWITCH_DPS] = True
  61. self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
  62. self.dps[ERROR_DPS] = 1
  63. self.assertEqual(self.subject.icon, "mdi:cup-water")
  64. def test_min_target_humidity(self):
  65. self.assertEqual(self.subject.min_humidity, 0)
  66. def test_max_target_humidity(self):
  67. self.assertEqual(self.subject.max_humidity, 80)
  68. def test_target_humidity(self):
  69. self.dps[HUMIDITY_DPS] = 55
  70. self.assertEqual(self.subject.target_humidity, 55)
  71. async def test_fan_turn_on(self):
  72. async with assert_device_properties_set(
  73. self.subject._device, {SWITCH_DPS: True}
  74. ):
  75. await self.fan.async_turn_on()
  76. async def test_fan_turn_off(self):
  77. async with assert_device_properties_set(
  78. self.subject._device, {SWITCH_DPS: False}
  79. ):
  80. await self.fan.async_turn_off()
  81. def test_modes(self):
  82. self.assertCountEqual(
  83. self.subject.available_modes,
  84. [
  85. "Low",
  86. "Medium",
  87. "High",
  88. "Dry Clothes",
  89. ],
  90. )
  91. def test_mode(self):
  92. self.dps[MODE_DPS] = "low"
  93. self.assertEqual(self.subject.mode, "Low")
  94. self.dps[MODE_DPS] = "middle"
  95. self.assertEqual(self.subject.mode, "Medium")
  96. self.dps[MODE_DPS] = "high"
  97. self.assertEqual(self.subject.mode, "High")
  98. self.dps[MODE_DPS] = "quickdry"
  99. self.assertEqual(self.subject.mode, "Dry Clothes")
  100. async def test_set_mode_to_low(self):
  101. async with assert_device_properties_set(
  102. self.subject._device,
  103. {
  104. MODE_DPS: "low",
  105. },
  106. ):
  107. await self.subject.async_set_mode("Low")
  108. self.subject._device.anticipate_property_value.assert_not_called()
  109. async def test_set_mode_to_medium(self):
  110. async with assert_device_properties_set(
  111. self.subject._device,
  112. {
  113. MODE_DPS: "middle",
  114. },
  115. ):
  116. await self.subject.async_set_mode("Medium")
  117. self.subject._device.anticipate_property_value.assert_not_called()
  118. async def test_set_mode_to_high(self):
  119. async with assert_device_properties_set(
  120. self.subject._device,
  121. {
  122. MODE_DPS: "high",
  123. },
  124. ):
  125. await self.subject.async_set_mode("High")
  126. self.subject._device.anticipate_property_value.assert_not_called()
  127. async def test_set_mode_to_clothes(self):
  128. async with assert_device_properties_set(
  129. self.subject._device,
  130. {
  131. MODE_DPS: "quickdry",
  132. },
  133. ):
  134. await self.subject.async_set_mode("Dry Clothes")
  135. self.subject._device.anticipate_property_value.assert_not_called()
  136. def test_fan_speed_steps(self):
  137. self.assertEqual(self.fan.speed_count, 3)
  138. def test_fan_speed(self):
  139. self.dps[MODE_DPS] = "low"
  140. self.assertAlmostEqual(self.fan.percentage, 33.3, 1)
  141. self.dps[MODE_DPS] = "middle"
  142. self.assertAlmostEqual(self.fan.percentage, 66.7, 1)
  143. self.dps[MODE_DPS] = "high"
  144. self.assertEqual(self.fan.percentage, 100)
  145. self.dps[MODE_DPS] = "quickdry"
  146. self.assertEqual(self.fan.percentage, 100)
  147. async def test_fan_set_speed_to_low(self):
  148. async with assert_device_properties_set(
  149. self.subject._device,
  150. {
  151. MODE_DPS: "low",
  152. },
  153. ):
  154. await self.fan.async_set_percentage(33)
  155. async def test_fan_set_speed_to_medium(self):
  156. async with assert_device_properties_set(
  157. self.subject._device,
  158. {
  159. MODE_DPS: "middle",
  160. },
  161. ):
  162. await self.fan.async_set_percentage(66)
  163. async def test_fan_set_speed_to_high(self):
  164. async with assert_device_properties_set(
  165. self.subject._device,
  166. {
  167. MODE_DPS: "high",
  168. },
  169. ):
  170. await self.fan.async_set_percentage(100)
  171. def test_fan_oscillating(self):
  172. self.dps[SWING_DPS] = True
  173. self.assertTrue(self.fan.oscillating)
  174. self.dps[SWING_DPS] = False
  175. self.assertFalse(self.fan.oscillating)
  176. async def test_set_fan_oscillate_on(self):
  177. async with assert_device_properties_set(
  178. self.subject._device,
  179. {
  180. SWING_DPS: True,
  181. },
  182. ):
  183. await self.fan.async_oscillate(True)
  184. self.subject._device.anticipate_property_value.assert_not_called()
  185. async def test_set_fan_oscillate_off(self):
  186. async with assert_device_properties_set(
  187. self.subject._device,
  188. {
  189. SWING_DPS: False,
  190. },
  191. ):
  192. await self.fan.async_oscillate(False)
  193. self.subject._device.anticipate_property_value.assert_not_called()
  194. def test_extra_state_attributes(self):
  195. self.dps[CURRENTHUMID_DPS] = 55
  196. self.dps[ERROR_DPS] = 1
  197. self.dps[TIMER_DPS] = 3
  198. self.dps[COUNTDOWN_DPS] = 160
  199. self.assertDictEqual(
  200. self.subject.extra_state_attributes,
  201. {
  202. "current_humidity": 55,
  203. "error": "Tank full",
  204. "timer_hr": 3,
  205. "timer": 160,
  206. },
  207. )
  208. self.assertEqual(self.fan.extra_state_attributes, {})