test_eanons_humidifier.py 6.9 KB

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