test_kogan_dehumidifier.py 8.0 KB

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