test_eanons_humidifier.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. from homeassistant.components.fan import FanEntityFeature
  2. from homeassistant.components.humidifier import HumidifierEntityFeature
  3. from homeassistant.components.humidifier.const import MODE_AUTO, MODE_NORMAL, MODE_SLEEP
  4. from homeassistant.components.sensor import SensorDeviceClass
  5. from ..const import EANONS_HUMIDIFIER_PAYLOAD
  6. from ..helpers import assert_device_properties_set
  7. from ..mixins.binary_sensor import MultiBinarySensorTests
  8. from ..mixins.select import BasicSelectTests
  9. from ..mixins.sensor import BasicSensorTests
  10. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  11. from .base_device_tests import TuyaDeviceTestCase
  12. FANMODE_DPS = "2"
  13. TIMERHR_DPS = "3"
  14. TIMER_DPS = "4"
  15. ERROR_DPS = "9"
  16. HVACMODE_DPS = "10"
  17. PRESET_DPS = "12"
  18. HUMIDITY_DPS = "15"
  19. CURRENTHUMID_DPS = "16"
  20. SWITCH_DPS = "22"
  21. class TestEanonsHumidifier(
  22. BasicSelectTests,
  23. BasicSensorTests,
  24. BasicSwitchTests,
  25. MultiBinarySensorTests,
  26. SwitchableTests,
  27. TuyaDeviceTestCase,
  28. ):
  29. def setUp(self):
  30. self.setUpForConfig("eanons_humidifier.yaml", EANONS_HUMIDIFIER_PAYLOAD)
  31. self.subject = self.entities.get("humidifier_humidifier")
  32. self.setUpSwitchable(HVACMODE_DPS, self.subject)
  33. self.fan = self.entities.get("fan_intensity")
  34. self.setUpBasicSwitch(SWITCH_DPS, self.entities.get("switch_uv_sterilization"))
  35. self.setUpBasicSelect(
  36. TIMERHR_DPS,
  37. self.entities.get("select_timer"),
  38. {
  39. "cancel": "cancel",
  40. "1": "1h",
  41. "2": "2h",
  42. "3": "3h",
  43. "4": "4h",
  44. "5": "5h",
  45. "6": "6h",
  46. "7": "7h",
  47. "8": "8h",
  48. "9": "9h",
  49. "10": "10h",
  50. "11": "11h",
  51. "12": "12h",
  52. },
  53. )
  54. self.setUpBasicSensor(
  55. TIMER_DPS,
  56. self.entities.get("sensor_time_remaining"),
  57. unit="min",
  58. device_class=SensorDeviceClass.DURATION,
  59. )
  60. self.setUpMultiBinarySensors(
  61. [
  62. {
  63. "name": "binary_sensor_tank_empty",
  64. "dps": ERROR_DPS,
  65. "testdata": (1, 0),
  66. },
  67. {
  68. "name": "binary_sensor_problem",
  69. "dps": ERROR_DPS,
  70. "device_class": "problem",
  71. "testdata": (2, 0),
  72. },
  73. ],
  74. )
  75. self.mark_secondary(
  76. [
  77. "select_timer",
  78. "sensor_time_remaining",
  79. "binary_sensor_problem",
  80. "binary_sensor_tank_empty",
  81. ]
  82. )
  83. def test_supported_features(self):
  84. self.assertEqual(
  85. self.subject.supported_features,
  86. HumidifierEntityFeature.MODES,
  87. )
  88. self.assertEqual(
  89. self.fan.supported_features,
  90. FanEntityFeature.SET_SPEED
  91. | FanEntityFeature.TURN_OFF
  92. | FanEntityFeature.TURN_ON,
  93. )
  94. def test_current_humidity(self):
  95. self.dps[CURRENTHUMID_DPS] = 75
  96. self.assertEqual(self.subject.current_humidity, 75)
  97. def test_min_target_humidity(self):
  98. self.assertEqual(self.subject.min_humidity, 40)
  99. def test_max_target_humidity(self):
  100. self.assertEqual(self.subject.max_humidity, 90)
  101. def test_target_humidity(self):
  102. self.dps[HUMIDITY_DPS] = 55
  103. self.assertEqual(self.subject.target_humidity, 55)
  104. async def test_fan_turn_on(self):
  105. async with assert_device_properties_set(
  106. self.subject._device, {HVACMODE_DPS: True}
  107. ):
  108. await self.fan.async_turn_on()
  109. async def test_fan_turn_off(self):
  110. async with assert_device_properties_set(
  111. self.subject._device, {HVACMODE_DPS: False}
  112. ):
  113. await self.fan.async_turn_off()
  114. def test_preset_mode(self):
  115. self.dps[PRESET_DPS] = "sleep"
  116. self.assertEqual(self.subject.mode, MODE_SLEEP)
  117. self.dps[PRESET_DPS] = "humidity"
  118. self.assertEqual(self.subject.mode, MODE_AUTO)
  119. self.dps[PRESET_DPS] = "work"
  120. self.assertEqual(self.subject.mode, MODE_NORMAL)
  121. self.dps[PRESET_DPS] = None
  122. self.assertEqual(self.subject.mode, None)
  123. def test_preset_modes(self):
  124. self.assertCountEqual(
  125. self.subject.available_modes,
  126. [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
  127. )
  128. async def test_set_mode_to_auto(self):
  129. async with assert_device_properties_set(
  130. self.subject._device,
  131. {
  132. PRESET_DPS: "humidity",
  133. },
  134. ):
  135. await self.subject.async_set_mode(MODE_AUTO)
  136. self.subject._device.anticipate_property_value.assert_not_called()
  137. async def test_set_mode_to_sleep(self):
  138. async with assert_device_properties_set(
  139. self.subject._device,
  140. {
  141. PRESET_DPS: "sleep",
  142. },
  143. ):
  144. await self.subject.async_set_mode(MODE_SLEEP)
  145. self.subject._device.anticipate_property_value.assert_not_called()
  146. async def test_set_mode_to_normal(self):
  147. async with assert_device_properties_set(
  148. self.subject._device,
  149. {
  150. PRESET_DPS: "work",
  151. },
  152. ):
  153. await self.subject.async_set_mode(MODE_NORMAL)
  154. self.subject._device.anticipate_property_value.assert_not_called()
  155. def test_fan_speed(self):
  156. self.dps[FANMODE_DPS] = "small"
  157. self.assertEqual(self.fan.percentage, 33)
  158. self.dps[FANMODE_DPS] = "middle"
  159. self.assertEqual(self.fan.percentage, 67)
  160. self.dps[FANMODE_DPS] = "large"
  161. self.assertEqual(self.fan.percentage, 100)
  162. def test_fan_speed_count(self):
  163. self.assertEqual(self.fan.speed_count, 3)
  164. def test_fan_percentage_step(self):
  165. self.assertAlmostEqual(self.fan.percentage_step, 33, 0)
  166. async def test_fan_set_speed(self):
  167. async with assert_device_properties_set(
  168. self.fan._device,
  169. {FANMODE_DPS: "small"},
  170. ):
  171. await self.fan.async_set_percentage(33)
  172. async def test_fan_set_speed_snaps(self):
  173. async with assert_device_properties_set(
  174. self.fan._device,
  175. {FANMODE_DPS: "middle"},
  176. ):
  177. await self.fan.async_set_percentage(60)
  178. def test_multi_bsensor_extra_state_attributes(self):
  179. self.dps[ERROR_DPS] = 2
  180. self.assertEqual(
  181. self.multiBSensor["binary_sensor_tank_empty"].extra_state_attributes, {}
  182. )
  183. self.assertEqual(
  184. self.multiBSensor["binary_sensor_problem"].extra_state_attributes,
  185. {"fault_code": 2},
  186. )