test_eanons_humidifier.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. from homeassistant.components.binary_sensor import DEVICE_CLASS_PROBLEM
  2. from homeassistant.components.climate.const import (
  3. FAN_HIGH,
  4. FAN_MEDIUM,
  5. FAN_LOW,
  6. HVAC_MODE_DRY,
  7. HVAC_MODE_OFF,
  8. SUPPORT_FAN_MODE,
  9. SUPPORT_PRESET_MODE,
  10. SUPPORT_TARGET_HUMIDITY,
  11. )
  12. from homeassistant.components.fan import (
  13. SUPPORT_SET_SPEED,
  14. )
  15. from homeassistant.components.humidifier.const import (
  16. MODE_NORMAL,
  17. MODE_AUTO,
  18. MODE_SLEEP,
  19. SUPPORT_MODES,
  20. )
  21. from homeassistant.const import STATE_UNAVAILABLE
  22. from ..const import EANONS_HUMIDIFIER_PAYLOAD
  23. from ..helpers import assert_device_properties_set
  24. from ..mixins.binary_sensor import BasicBinarySensorTests
  25. from ..mixins.select import BasicSelectTests
  26. from ..mixins.sensor import BasicSensorTests
  27. from ..mixins.switch import BasicSwitchTests, SwitchableTests
  28. from .base_device_tests import TuyaDeviceTestCase
  29. FANMODE_DPS = "2"
  30. TIMERHR_DPS = "3"
  31. TIMER_DPS = "4"
  32. ERROR_DPS = "9"
  33. HVACMODE_DPS = "10"
  34. PRESET_DPS = "12"
  35. HUMIDITY_DPS = "15"
  36. CURRENTHUMID_DPS = "16"
  37. SWITCH_DPS = "22"
  38. class TestEanonsHumidifier(
  39. BasicBinarySensorTests,
  40. BasicSelectTests,
  41. BasicSensorTests,
  42. BasicSwitchTests,
  43. SwitchableTests,
  44. TuyaDeviceTestCase,
  45. ):
  46. __test__ = True
  47. def setUp(self):
  48. self.setUpForConfig("eanons_humidifier.yaml", EANONS_HUMIDIFIER_PAYLOAD)
  49. self.subject = self.entities.get("humidifier")
  50. self.setUpSwitchable(HVACMODE_DPS, self.subject)
  51. self.climate = self.entities.get("climate")
  52. self.fan = self.entities.get("fan_intensity")
  53. self.setUpBasicSwitch(SWITCH_DPS, self.entities.get("switch_uv_sterilization"))
  54. self.setUpBasicSelect(
  55. TIMERHR_DPS,
  56. self.entities.get("select_timer"),
  57. {
  58. "cancel": "Off",
  59. "1": "1 hour",
  60. "2": "2 hours",
  61. "3": "3 hours",
  62. "4": "4 hours",
  63. "5": "5 hours",
  64. "6": "6 hours",
  65. "7": "7 hours",
  66. "8": "8 hours",
  67. "9": "9 hours",
  68. "10": "10 hours",
  69. "11": "11 hours",
  70. "12": "12 hours",
  71. },
  72. )
  73. self.setUpBasicSensor(
  74. TIMER_DPS,
  75. self.entities.get("sensor_timer"),
  76. unit="min",
  77. )
  78. self.setUpBasicBinarySensor(
  79. ERROR_DPS,
  80. self.entities.get("binary_sensor_tank"),
  81. device_class=DEVICE_CLASS_PROBLEM,
  82. testdata=(1, 0),
  83. )
  84. def test_supported_features(self):
  85. self.assertEqual(
  86. self.climate.supported_features,
  87. SUPPORT_TARGET_HUMIDITY | SUPPORT_PRESET_MODE | SUPPORT_FAN_MODE,
  88. )
  89. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  90. self.assertEqual(self.fan.supported_features, SUPPORT_SET_SPEED)
  91. def test_climate_icon_is_humidifier(self):
  92. """Test that the icon is as expected."""
  93. self.dps[HVACMODE_DPS] = True
  94. self.assertEqual(self.climate.icon, "mdi:air-humidifier")
  95. self.dps[HVACMODE_DPS] = False
  96. self.assertEqual(self.climate.icon, "mdi:air-humidifier-off")
  97. def test_icon_is_humidifier(self):
  98. """Test that the icon is as expected."""
  99. self.dps[HVACMODE_DPS] = True
  100. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  101. self.dps[HVACMODE_DPS] = False
  102. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  103. def test_current_humidity(self):
  104. self.dps[CURRENTHUMID_DPS] = 47
  105. self.assertEqual(self.climate.current_humidity, 47)
  106. def test_min_target_humidity(self):
  107. self.assertEqual(self.climate.min_humidity, 40)
  108. self.assertEqual(self.subject.min_humidity, 40)
  109. def test_max_target_humidity(self):
  110. self.assertEqual(self.climate.max_humidity, 90)
  111. self.assertEqual(self.subject.max_humidity, 90)
  112. def test_target_humidity(self):
  113. self.dps[HUMIDITY_DPS] = 55
  114. self.assertEqual(self.climate.target_humidity, 55)
  115. self.assertEqual(self.subject.target_humidity, 55)
  116. def test_climate_hvac_mode(self):
  117. self.dps[HVACMODE_DPS] = True
  118. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_DRY)
  119. self.dps[HVACMODE_DPS] = False
  120. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_OFF)
  121. self.dps[HVACMODE_DPS] = None
  122. self.assertEqual(self.climate.hvac_mode, STATE_UNAVAILABLE)
  123. def test_climate_hvac_modes(self):
  124. self.assertCountEqual(self.climate.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_DRY])
  125. async def test_climate_turn_on(self):
  126. async with assert_device_properties_set(
  127. self.climate._device, {HVACMODE_DPS: True}
  128. ):
  129. await self.climate.async_set_hvac_mode(HVAC_MODE_DRY)
  130. async def test_climate_turn_off(self):
  131. async with assert_device_properties_set(
  132. self.climate._device, {HVACMODE_DPS: False}
  133. ):
  134. await self.climate.async_set_hvac_mode(HVAC_MODE_OFF)
  135. async def test_fan_turn_on(self):
  136. async with assert_device_properties_set(
  137. self.subject._device, {HVACMODE_DPS: True}
  138. ):
  139. await self.fan.async_turn_on()
  140. async def test_fan_turn_off(self):
  141. async with assert_device_properties_set(
  142. self.subject._device, {HVACMODE_DPS: False}
  143. ):
  144. await self.fan.async_turn_off()
  145. def test_preset_mode(self):
  146. self.dps[PRESET_DPS] = "sleep"
  147. self.assertEqual(self.climate.preset_mode, MODE_SLEEP)
  148. self.assertEqual(self.subject.mode, MODE_SLEEP)
  149. self.dps[PRESET_DPS] = "humidity"
  150. self.assertEqual(self.climate.preset_mode, MODE_AUTO)
  151. self.assertEqual(self.subject.mode, MODE_AUTO)
  152. self.dps[PRESET_DPS] = "work"
  153. self.assertEqual(self.climate.preset_mode, MODE_NORMAL)
  154. self.assertEqual(self.subject.mode, MODE_NORMAL)
  155. self.dps[PRESET_DPS] = None
  156. self.assertEqual(self.climate.preset_mode, None)
  157. self.assertEqual(self.subject.mode, None)
  158. def test_preset_modes(self):
  159. self.assertCountEqual(
  160. self.climate.preset_modes,
  161. [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
  162. )
  163. self.assertCountEqual(
  164. self.subject.available_modes,
  165. [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
  166. )
  167. async def test_set_climate_preset_to_auto(self):
  168. async with assert_device_properties_set(
  169. self.climate._device,
  170. {
  171. PRESET_DPS: "humidity",
  172. },
  173. ):
  174. await self.climate.async_set_preset_mode(MODE_AUTO)
  175. self.climate._device.anticipate_property_value.assert_not_called()
  176. async def test_set_climate_preset_to_sleep(self):
  177. async with assert_device_properties_set(
  178. self.climate._device,
  179. {
  180. PRESET_DPS: "sleep",
  181. },
  182. ):
  183. await self.climate.async_set_preset_mode(MODE_SLEEP)
  184. self.climate._device.anticipate_property_value.assert_not_called()
  185. async def test_set_climate_preset_to_normal(self):
  186. async with assert_device_properties_set(
  187. self.climate._device,
  188. {
  189. PRESET_DPS: "work",
  190. },
  191. ):
  192. await self.climate.async_set_preset_mode(MODE_NORMAL)
  193. self.climate._device.anticipate_property_value.assert_not_called()
  194. async def test_set_mode_to_auto(self):
  195. async with assert_device_properties_set(
  196. self.subject._device,
  197. {
  198. PRESET_DPS: "humidity",
  199. },
  200. ):
  201. await self.subject.async_set_mode(MODE_AUTO)
  202. self.subject._device.anticipate_property_value.assert_not_called()
  203. async def test_set_mode_to_sleep(self):
  204. async with assert_device_properties_set(
  205. self.subject._device,
  206. {
  207. PRESET_DPS: "sleep",
  208. },
  209. ):
  210. await self.subject.async_set_mode(MODE_SLEEP)
  211. self.subject._device.anticipate_property_value.assert_not_called()
  212. async def test_set_mode_to_normal(self):
  213. async with assert_device_properties_set(
  214. self.subject._device,
  215. {
  216. PRESET_DPS: "work",
  217. },
  218. ):
  219. await self.subject.async_set_mode(MODE_NORMAL)
  220. self.subject._device.anticipate_property_value.assert_not_called()
  221. def test_climate_device_state_attributes(self):
  222. self.dps[ERROR_DPS] = 0
  223. self.dps[TIMERHR_DPS] = "cancel"
  224. self.dps[TIMER_DPS] = 0
  225. self.assertDictEqual(
  226. self.climate.device_state_attributes,
  227. {
  228. "error": "OK",
  229. "timer_hr": "cancel",
  230. "timer_min": 0,
  231. },
  232. )
  233. self.dps[ERROR_DPS] = 1
  234. self.dps[TIMERHR_DPS] = "1"
  235. self.dps[TIMER_DPS] = 60
  236. self.assertDictEqual(
  237. self.climate.device_state_attributes,
  238. {
  239. "error": "Water Level Low",
  240. "timer_hr": "1",
  241. "timer_min": 60,
  242. },
  243. )
  244. def test_device_state_attributes(self):
  245. self.dps[ERROR_DPS] = 0
  246. self.dps[TIMERHR_DPS] = "cancel"
  247. self.dps[TIMER_DPS] = 0
  248. self.dps[CURRENTHUMID_DPS] = 50
  249. self.dps[FANMODE_DPS] = "middle"
  250. self.assertDictEqual(
  251. self.subject.device_state_attributes,
  252. {
  253. "error": "OK",
  254. "timer_hr": "cancel",
  255. "timer_min": 0,
  256. "current_humidity": 50,
  257. },
  258. )
  259. def test_fan_speed(self):
  260. self.dps[FANMODE_DPS] = "small"
  261. self.assertEqual(self.fan.percentage, 33)
  262. self.dps[FANMODE_DPS] = "middle"
  263. self.assertEqual(self.fan.percentage, 67)
  264. self.dps[FANMODE_DPS] = "large"
  265. self.assertEqual(self.fan.percentage, 100)
  266. def test_climate_fan_mode(self):
  267. self.dps[FANMODE_DPS] = "small"
  268. self.assertEqual(self.climate.fan_mode, FAN_LOW)
  269. self.dps[FANMODE_DPS] = "middle"
  270. self.assertEqual(self.climate.fan_mode, FAN_MEDIUM)
  271. self.dps[FANMODE_DPS] = "large"
  272. self.assertEqual(self.climate.fan_mode, FAN_HIGH)
  273. self.dps[FANMODE_DPS] = None
  274. self.assertEqual(self.climate.fan_mode, None)
  275. def test_fan_speed_count(self):
  276. self.assertEqual(self.fan.speed_count, 3)
  277. def test_fan_percentage_step(self):
  278. self.assertAlmostEqual(self.fan.percentage_step, 33, 0)
  279. def test_climate_fan_modes(self):
  280. self.assertCountEqual(
  281. self.climate.fan_modes,
  282. [FAN_LOW, FAN_MEDIUM, FAN_HIGH],
  283. )
  284. async def test_fan_set_speed(self):
  285. async with assert_device_properties_set(
  286. self.fan._device,
  287. {FANMODE_DPS: "small"},
  288. ):
  289. await self.fan.async_set_percentage(33)
  290. async def test_fan_set_speed_snaps(self):
  291. async with assert_device_properties_set(
  292. self.fan._device,
  293. {FANMODE_DPS: "middle"},
  294. ):
  295. await self.fan.async_set_percentage(60)
  296. async def test_climate_set_fan_mode(self):
  297. async with assert_device_properties_set(
  298. self.climate._device,
  299. {FANMODE_DPS: "small"},
  300. ):
  301. await self.climate.async_set_fan_mode(FAN_LOW)