test_eanons_humidifier.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. from homeassistant.components.binary_sensor import BinarySensorDeviceClass
  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=BinarySensorDeviceClass.PROBLEM,
  82. testdata=(1, 0),
  83. )
  84. self.mark_secondary(["select_timer", "sensor_timer", "binary_sensor_tank"])
  85. def test_supported_features(self):
  86. self.assertEqual(
  87. self.climate.supported_features,
  88. SUPPORT_TARGET_HUMIDITY | SUPPORT_PRESET_MODE | SUPPORT_FAN_MODE,
  89. )
  90. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  91. self.assertEqual(self.fan.supported_features, SUPPORT_SET_SPEED)
  92. def test_climate_icon_is_humidifier(self):
  93. """Test that the icon is as expected."""
  94. self.dps[HVACMODE_DPS] = True
  95. self.assertEqual(self.climate.icon, "mdi:air-humidifier")
  96. self.dps[HVACMODE_DPS] = False
  97. self.assertEqual(self.climate.icon, "mdi:air-humidifier-off")
  98. def test_icon_is_humidifier(self):
  99. """Test that the icon is as expected."""
  100. self.dps[HVACMODE_DPS] = True
  101. self.assertEqual(self.subject.icon, "mdi:air-humidifier")
  102. self.dps[HVACMODE_DPS] = False
  103. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  104. def test_current_humidity(self):
  105. self.dps[CURRENTHUMID_DPS] = 47
  106. self.assertEqual(self.climate.current_humidity, 47)
  107. def test_min_target_humidity(self):
  108. self.assertEqual(self.climate.min_humidity, 40)
  109. self.assertEqual(self.subject.min_humidity, 40)
  110. def test_max_target_humidity(self):
  111. self.assertEqual(self.climate.max_humidity, 90)
  112. self.assertEqual(self.subject.max_humidity, 90)
  113. def test_target_humidity(self):
  114. self.dps[HUMIDITY_DPS] = 55
  115. self.assertEqual(self.climate.target_humidity, 55)
  116. self.assertEqual(self.subject.target_humidity, 55)
  117. def test_climate_hvac_mode(self):
  118. self.dps[HVACMODE_DPS] = True
  119. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_DRY)
  120. self.dps[HVACMODE_DPS] = False
  121. self.assertEqual(self.climate.hvac_mode, HVAC_MODE_OFF)
  122. self.dps[HVACMODE_DPS] = None
  123. self.assertEqual(self.climate.hvac_mode, STATE_UNAVAILABLE)
  124. def test_climate_hvac_modes(self):
  125. self.assertCountEqual(self.climate.hvac_modes, [HVAC_MODE_OFF, HVAC_MODE_DRY])
  126. async def test_climate_turn_on(self):
  127. async with assert_device_properties_set(
  128. self.climate._device, {HVACMODE_DPS: True}
  129. ):
  130. await self.climate.async_set_hvac_mode(HVAC_MODE_DRY)
  131. async def test_climate_turn_off(self):
  132. async with assert_device_properties_set(
  133. self.climate._device, {HVACMODE_DPS: False}
  134. ):
  135. await self.climate.async_set_hvac_mode(HVAC_MODE_OFF)
  136. async def test_fan_turn_on(self):
  137. async with assert_device_properties_set(
  138. self.subject._device, {HVACMODE_DPS: True}
  139. ):
  140. await self.fan.async_turn_on()
  141. async def test_fan_turn_off(self):
  142. async with assert_device_properties_set(
  143. self.subject._device, {HVACMODE_DPS: False}
  144. ):
  145. await self.fan.async_turn_off()
  146. def test_preset_mode(self):
  147. self.dps[PRESET_DPS] = "sleep"
  148. self.assertEqual(self.climate.preset_mode, MODE_SLEEP)
  149. self.assertEqual(self.subject.mode, MODE_SLEEP)
  150. self.dps[PRESET_DPS] = "humidity"
  151. self.assertEqual(self.climate.preset_mode, MODE_AUTO)
  152. self.assertEqual(self.subject.mode, MODE_AUTO)
  153. self.dps[PRESET_DPS] = "work"
  154. self.assertEqual(self.climate.preset_mode, MODE_NORMAL)
  155. self.assertEqual(self.subject.mode, MODE_NORMAL)
  156. self.dps[PRESET_DPS] = None
  157. self.assertEqual(self.climate.preset_mode, None)
  158. self.assertEqual(self.subject.mode, None)
  159. def test_preset_modes(self):
  160. self.assertCountEqual(
  161. self.climate.preset_modes,
  162. [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
  163. )
  164. self.assertCountEqual(
  165. self.subject.available_modes,
  166. [MODE_NORMAL, MODE_SLEEP, MODE_AUTO],
  167. )
  168. async def test_set_climate_preset_to_auto(self):
  169. async with assert_device_properties_set(
  170. self.climate._device,
  171. {
  172. PRESET_DPS: "humidity",
  173. },
  174. ):
  175. await self.climate.async_set_preset_mode(MODE_AUTO)
  176. self.climate._device.anticipate_property_value.assert_not_called()
  177. async def test_set_climate_preset_to_sleep(self):
  178. async with assert_device_properties_set(
  179. self.climate._device,
  180. {
  181. PRESET_DPS: "sleep",
  182. },
  183. ):
  184. await self.climate.async_set_preset_mode(MODE_SLEEP)
  185. self.climate._device.anticipate_property_value.assert_not_called()
  186. async def test_set_climate_preset_to_normal(self):
  187. async with assert_device_properties_set(
  188. self.climate._device,
  189. {
  190. PRESET_DPS: "work",
  191. },
  192. ):
  193. await self.climate.async_set_preset_mode(MODE_NORMAL)
  194. self.climate._device.anticipate_property_value.assert_not_called()
  195. async def test_set_mode_to_auto(self):
  196. async with assert_device_properties_set(
  197. self.subject._device,
  198. {
  199. PRESET_DPS: "humidity",
  200. },
  201. ):
  202. await self.subject.async_set_mode(MODE_AUTO)
  203. self.subject._device.anticipate_property_value.assert_not_called()
  204. async def test_set_mode_to_sleep(self):
  205. async with assert_device_properties_set(
  206. self.subject._device,
  207. {
  208. PRESET_DPS: "sleep",
  209. },
  210. ):
  211. await self.subject.async_set_mode(MODE_SLEEP)
  212. self.subject._device.anticipate_property_value.assert_not_called()
  213. async def test_set_mode_to_normal(self):
  214. async with assert_device_properties_set(
  215. self.subject._device,
  216. {
  217. PRESET_DPS: "work",
  218. },
  219. ):
  220. await self.subject.async_set_mode(MODE_NORMAL)
  221. self.subject._device.anticipate_property_value.assert_not_called()
  222. def test_climate_extra_state_attributes(self):
  223. self.dps[ERROR_DPS] = 0
  224. self.dps[TIMERHR_DPS] = "cancel"
  225. self.dps[TIMER_DPS] = 0
  226. self.assertDictEqual(
  227. self.climate.extra_state_attributes,
  228. {
  229. "error": "OK",
  230. "timer_hr": "cancel",
  231. "timer_min": 0,
  232. },
  233. )
  234. self.dps[ERROR_DPS] = 1
  235. self.dps[TIMERHR_DPS] = "1"
  236. self.dps[TIMER_DPS] = 60
  237. self.assertDictEqual(
  238. self.climate.extra_state_attributes,
  239. {
  240. "error": "Water Level Low",
  241. "timer_hr": "1",
  242. "timer_min": 60,
  243. },
  244. )
  245. def test_extra_state_attributes(self):
  246. self.dps[ERROR_DPS] = 0
  247. self.dps[TIMERHR_DPS] = "cancel"
  248. self.dps[TIMER_DPS] = 0
  249. self.dps[CURRENTHUMID_DPS] = 50
  250. self.dps[FANMODE_DPS] = "middle"
  251. self.assertDictEqual(
  252. self.subject.extra_state_attributes,
  253. {
  254. "error": "OK",
  255. "timer_hr": "cancel",
  256. "timer_min": 0,
  257. "current_humidity": 50,
  258. },
  259. )
  260. def test_fan_speed(self):
  261. self.dps[FANMODE_DPS] = "small"
  262. self.assertEqual(self.fan.percentage, 33)
  263. self.dps[FANMODE_DPS] = "middle"
  264. self.assertEqual(self.fan.percentage, 67)
  265. self.dps[FANMODE_DPS] = "large"
  266. self.assertEqual(self.fan.percentage, 100)
  267. def test_climate_fan_mode(self):
  268. self.dps[FANMODE_DPS] = "small"
  269. self.assertEqual(self.climate.fan_mode, FAN_LOW)
  270. self.dps[FANMODE_DPS] = "middle"
  271. self.assertEqual(self.climate.fan_mode, FAN_MEDIUM)
  272. self.dps[FANMODE_DPS] = "large"
  273. self.assertEqual(self.climate.fan_mode, FAN_HIGH)
  274. self.dps[FANMODE_DPS] = None
  275. self.assertEqual(self.climate.fan_mode, None)
  276. def test_fan_speed_count(self):
  277. self.assertEqual(self.fan.speed_count, 3)
  278. def test_fan_percentage_step(self):
  279. self.assertAlmostEqual(self.fan.percentage_step, 33, 0)
  280. def test_climate_fan_modes(self):
  281. self.assertCountEqual(
  282. self.climate.fan_modes,
  283. [FAN_LOW, FAN_MEDIUM, FAN_HIGH],
  284. )
  285. async def test_fan_set_speed(self):
  286. async with assert_device_properties_set(
  287. self.fan._device,
  288. {FANMODE_DPS: "small"},
  289. ):
  290. await self.fan.async_set_percentage(33)
  291. async def test_fan_set_speed_snaps(self):
  292. async with assert_device_properties_set(
  293. self.fan._device,
  294. {FANMODE_DPS: "middle"},
  295. ):
  296. await self.fan.async_set_percentage(60)
  297. async def test_climate_set_fan_mode(self):
  298. async with assert_device_properties_set(
  299. self.climate._device,
  300. {FANMODE_DPS: "small"},
  301. ):
  302. await self.climate.async_set_fan_mode(FAN_LOW)