test_eanons_humidifier.py 12 KB

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