test_jjpro_jpd01_dehumidifier.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. from homeassistant.components.binary_sensor import (
  2. DEVICE_CLASS_COLD,
  3. DEVICE_CLASS_PROBLEM,
  4. )
  5. from homeassistant.components.fan import SUPPORT_SET_SPEED
  6. from homeassistant.components.humidifier import SUPPORT_MODES
  7. from homeassistant.const import (
  8. DEVICE_CLASS_HUMIDITY,
  9. DEVICE_CLASS_TEMPERATURE,
  10. PERCENTAGE,
  11. TIME_HOURS,
  12. TEMP_CELSIUS,
  13. )
  14. from ..const import JJPRO_JPD01_PAYLOAD
  15. from ..helpers import assert_device_properties_set
  16. from ..mixins.binary_sensor import MultiBinarySensorTests
  17. from ..mixins.number import BasicNumberTests
  18. from ..mixins.sensor import MultiSensorTests
  19. from ..mixins.switch import MultiSwitchTests, SwitchableTests
  20. from .base_device_tests import TuyaDeviceTestCase
  21. SWITCH_DPS = "1"
  22. MODE_DPS = "2"
  23. HUMIDITY_DPS = "4"
  24. ANION_DPS = "5"
  25. FAN_DPS = "6"
  26. ERROR_DPS = "11"
  27. TIMER_DPS = "12"
  28. UNKNOWN101_DPS = "101"
  29. SLEEP_DPS = "102"
  30. CURRENTTEMP_DPS = "103"
  31. CURRENTHUMID_DPS = "104"
  32. DEFROST_DPS = "105"
  33. class TestJJProJPD01Dehumidifier(
  34. BasicNumberTests,
  35. MultiBinarySensorTests,
  36. MultiSensorTests,
  37. MultiSwitchTests,
  38. SwitchableTests,
  39. TuyaDeviceTestCase,
  40. ):
  41. __test__ = True
  42. def setUp(self):
  43. self.setUpForConfig("jjpro_jpd01_dehumidifier.yaml", JJPRO_JPD01_PAYLOAD)
  44. self.subject = self.entities.get("humidifier")
  45. self.setUpSwitchable(SWITCH_DPS, self.subject)
  46. self.fan = self.entities.get("fan")
  47. self.setUpBasicNumber(
  48. TIMER_DPS,
  49. self.entities.get("number_timer"),
  50. max=24,
  51. unit=TIME_HOURS,
  52. )
  53. self.setUpMultiBinarySensors(
  54. [
  55. {
  56. "dps": ERROR_DPS,
  57. "name": "binary_sensor_tank",
  58. "device_class": DEVICE_CLASS_PROBLEM,
  59. "testdata": (1, 0),
  60. },
  61. {
  62. "dps": DEFROST_DPS,
  63. "name": "binary_sensor_defrost",
  64. "device_class": DEVICE_CLASS_COLD,
  65. },
  66. ]
  67. )
  68. self.setUpMultiSensors(
  69. [
  70. {
  71. "dps": CURRENTHUMID_DPS,
  72. "name": "sensor_current_humidity",
  73. "device_class": DEVICE_CLASS_HUMIDITY,
  74. "state_class": "measurement",
  75. "unit": PERCENTAGE,
  76. },
  77. {
  78. "dps": CURRENTTEMP_DPS,
  79. "name": "sensor_current_temperature",
  80. "device_class": DEVICE_CLASS_TEMPERATURE,
  81. "state_class": "measurement",
  82. "unit": TEMP_CELSIUS,
  83. },
  84. ]
  85. )
  86. self.setUpMultiSwitch(
  87. [
  88. {
  89. "dps": SLEEP_DPS,
  90. "name": "switch_sleep",
  91. },
  92. {
  93. "dps": ANION_DPS,
  94. "name": "switch_ionizer",
  95. },
  96. ]
  97. )
  98. self.mark_secondary(
  99. [
  100. "binary_sensor_tank",
  101. "binary_sensor_defrost",
  102. "number_timer",
  103. ]
  104. )
  105. def test_supported_features(self):
  106. self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
  107. self.assertEqual(self.fan.supported_features, SUPPORT_SET_SPEED)
  108. def test_icon(self):
  109. """Test that the icon is as expected."""
  110. self.dps[SWITCH_DPS] = True
  111. self.dps[ANION_DPS] = False
  112. self.dps[SLEEP_DPS] = False
  113. self.dps[DEFROST_DPS] = False
  114. self.dps[MODE_DPS] = "0"
  115. self.assertEqual(self.subject.icon, "mdi:water-outline")
  116. self.dps[SWITCH_DPS] = False
  117. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  118. self.dps[MODE_DPS] = "1"
  119. self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
  120. self.dps[SWITCH_DPS] = True
  121. self.assertEqual(self.subject.icon, "mdi:water-plus-outline")
  122. self.dps[MODE_DPS] = "2"
  123. self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
  124. self.dps[MODE_DPS] = "3"
  125. self.assertEqual(self.subject.icon, "mdi:tailwind")
  126. self.dps[ERROR_DPS] = 8
  127. self.assertEqual(self.subject.icon, "mdi:cup-water")
  128. self.dps[DEFROST_DPS] = True
  129. self.assertEqual(self.subject.icon, "mdi:cup-water")
  130. self.dps[ERROR_DPS] = 0
  131. self.assertEqual(self.subject.icon, "mdi:snowflake-melt")
  132. def test_min_target_humidity(self):
  133. self.assertEqual(self.subject.min_humidity, 30)
  134. def test_max_target_humidity(self):
  135. self.assertEqual(self.subject.max_humidity, 80)
  136. def test_target_humidity(self):
  137. self.dps[HUMIDITY_DPS] = 55
  138. self.assertEqual(self.subject.target_humidity, 55)
  139. async def test_fan_turn_on(self):
  140. async with assert_device_properties_set(
  141. self.subject._device, {SWITCH_DPS: True}
  142. ):
  143. await self.fan.async_turn_on()
  144. async def test_fan_turn_off(self):
  145. async with assert_device_properties_set(
  146. self.subject._device, {SWITCH_DPS: False}
  147. ):
  148. await self.fan.async_turn_off()
  149. def test_modes(self):
  150. self.assertCountEqual(
  151. self.subject.available_modes,
  152. [
  153. "Normal",
  154. "Continuous",
  155. "Strong",
  156. "Ventilation",
  157. ],
  158. )
  159. def test_mode(self):
  160. self.dps[MODE_DPS] = "0"
  161. self.assertEqual(self.subject.mode, "Normal")
  162. self.dps[MODE_DPS] = "1"
  163. self.assertEqual(self.subject.mode, "Continuous")
  164. self.dps[MODE_DPS] = "2"
  165. self.assertEqual(self.subject.mode, "Strong")
  166. self.dps[MODE_DPS] = "3"
  167. self.assertEqual(self.subject.mode, "Ventilation")
  168. async def test_set_mode_to_normal(self):
  169. async with assert_device_properties_set(
  170. self.subject._device,
  171. {
  172. MODE_DPS: "0",
  173. },
  174. ):
  175. await self.subject.async_set_mode("Normal")
  176. self.subject._device.anticipate_property_value.assert_not_called()
  177. async def test_set_mode_to_continuous(self):
  178. async with assert_device_properties_set(
  179. self.subject._device,
  180. {
  181. MODE_DPS: "1",
  182. },
  183. ):
  184. await self.subject.async_set_mode("Continuous")
  185. self.subject._device.anticipate_property_value.assert_not_called()
  186. async def test_set_mode_to_strong(self):
  187. async with assert_device_properties_set(
  188. self.subject._device,
  189. {
  190. MODE_DPS: "2",
  191. },
  192. ):
  193. await self.subject.async_set_mode("Strong")
  194. self.subject._device.anticipate_property_value.assert_not_called()
  195. async def test_set_mode_to_ventilation(self):
  196. async with assert_device_properties_set(
  197. self.subject._device,
  198. {
  199. MODE_DPS: "3",
  200. },
  201. ):
  202. await self.subject.async_set_mode("Ventilation")
  203. self.subject._device.anticipate_property_value.assert_not_called()
  204. def test_fan_speed_steps(self):
  205. self.assertEqual(self.fan.speed_count, 2)
  206. def test_fan_speed(self):
  207. self.dps[FAN_DPS] = "1"
  208. self.assertEqual(self.fan.percentage, 50)
  209. self.dps[FAN_DPS] = "3"
  210. async def test_fan_set_speed_to_low(self):
  211. async with assert_device_properties_set(
  212. self.subject._device,
  213. {
  214. FAN_DPS: "1",
  215. },
  216. ):
  217. await self.fan.async_set_percentage(50)
  218. async def test_fan_set_speed_to_high(self):
  219. async with assert_device_properties_set(
  220. self.subject._device,
  221. {
  222. FAN_DPS: "3",
  223. },
  224. ):
  225. await self.fan.async_set_percentage(100)
  226. def test_extra_state_attributes(self):
  227. self.dps[UNKNOWN101_DPS] = True
  228. self.dps[ERROR_DPS] = 5
  229. self.assertDictEqual(
  230. self.subject.extra_state_attributes,
  231. {
  232. "error": 5,
  233. "unknown_101": True,
  234. },
  235. )
  236. self.assertEqual(self.fan.extra_state_attributes, {})