test_kogan_dehumidifier.py 7.9 KB

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