4
0

test_jjpro_jpd01_dehumidifier.py 8.4 KB

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