test_kyvol_e30_vacuum.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. from homeassistant.components.vacuum import (
  2. STATE_CLEANING,
  3. STATE_DOCKED,
  4. STATE_ERROR,
  5. STATE_RETURNING,
  6. VacuumEntityFeature,
  7. )
  8. from homeassistant.const import (
  9. TIME_MINUTES,
  10. PERCENTAGE,
  11. )
  12. from ..const import KYVOL_E30_VACUUM_PAYLOAD
  13. from ..helpers import assert_device_properties_set
  14. from ..mixins.sensor import MultiSensorTests
  15. from ..mixins.switch import MultiSwitchTests
  16. from .base_device_tests import TuyaDeviceTestCase
  17. POWER_DPS = "1"
  18. SWITCH_DPS = "2"
  19. COMMAND_DPS = "3"
  20. DIRECTION_DPS = "4"
  21. STATUS_DPS = "5"
  22. BATTERY_DPS = "6"
  23. EDGE_DPS = "7"
  24. ROLL_DPS = "8"
  25. FILTER_DPS = "9"
  26. RSTEDGE_DPS = "10"
  27. RSTROLL_DPS = "11"
  28. RSTFILTER_DPS = "12"
  29. LOCATE_DPS = "13"
  30. FAN_DPS = "14"
  31. TIME_DPS = "17"
  32. ERROR_DPS = "18"
  33. UNKNOWN101_DPS = "101"
  34. UNKNOWN102_DPS = "102"
  35. UNKNOWN104_DPS = "104"
  36. UNKNOWN106_DPS = "107"
  37. class TestKyvolE30Vacuum(MultiSensorTests, MultiSwitchTests, TuyaDeviceTestCase):
  38. __test__ = True
  39. def setUp(self):
  40. self.setUpForConfig("kyvol_e30_vacuum.yaml", KYVOL_E30_VACUUM_PAYLOAD)
  41. self.subject = self.entities.get("vacuum")
  42. self.setUpMultiSensors(
  43. [
  44. {
  45. "dps": TIME_DPS,
  46. "name": "sensor_clean_time",
  47. "unit": TIME_MINUTES,
  48. },
  49. {
  50. "dps": EDGE_DPS,
  51. "name": "sensor_edge_brush",
  52. "unit": PERCENTAGE,
  53. },
  54. {
  55. "dps": ROLL_DPS,
  56. "name": "sensor_roll_brush",
  57. "unit": PERCENTAGE,
  58. },
  59. {
  60. "dps": FILTER_DPS,
  61. "name": "sensor_filter",
  62. "unit": PERCENTAGE,
  63. },
  64. {
  65. "dps": STATUS_DPS,
  66. "name": "sensor_status",
  67. },
  68. ],
  69. )
  70. self.setUpMultiSwitch(
  71. [
  72. {
  73. "dps": RSTEDGE_DPS,
  74. "name": "switch_edge_brush_reset",
  75. },
  76. {
  77. "dps": RSTROLL_DPS,
  78. "name": "switch_roll_brush_reset",
  79. },
  80. {
  81. "dps": RSTFILTER_DPS,
  82. "name": "switch_filter_reset",
  83. },
  84. ],
  85. )
  86. self.mark_secondary(
  87. [
  88. "sensor_clean_time",
  89. "sensor_edge_brush",
  90. "sensor_roll_brush",
  91. "sensor_filter",
  92. "sensor_status",
  93. "switch_edge_brush_reset",
  94. "switch_roll_brush_reset",
  95. "switch_filter_reset",
  96. ]
  97. )
  98. def test_supported_features(self):
  99. self.assertEqual(
  100. self.subject.supported_features,
  101. (
  102. VacuumEntityFeature.STATE
  103. | VacuumEntityFeature.STATUS
  104. | VacuumEntityFeature.SEND_COMMAND
  105. | VacuumEntityFeature.BATTERY
  106. | VacuumEntityFeature.FAN_SPEED
  107. | VacuumEntityFeature.TURN_ON
  108. | VacuumEntityFeature.TURN_OFF
  109. | VacuumEntityFeature.START
  110. | VacuumEntityFeature.PAUSE
  111. | VacuumEntityFeature.LOCATE
  112. | VacuumEntityFeature.RETURN_HOME
  113. | VacuumEntityFeature.CLEAN_SPOT
  114. ),
  115. )
  116. def test_battery_level(self):
  117. self.dps[BATTERY_DPS] = 50
  118. self.assertEqual(self.subject.battery_level, 50)
  119. def test_status(self):
  120. self.dps[COMMAND_DPS] = "standby"
  121. self.assertEqual(self.subject.status, "standby")
  122. self.dps[COMMAND_DPS] = "smart"
  123. self.assertEqual(self.subject.status, "smart")
  124. self.dps[COMMAND_DPS] = "chargego"
  125. self.assertEqual(self.subject.status, "return_to_base")
  126. self.dps[COMMAND_DPS] = "random"
  127. self.assertEqual(self.subject.status, "random")
  128. self.dps[COMMAND_DPS] = "wall_follow"
  129. self.assertEqual(self.subject.status, "wall_follow")
  130. self.dps[COMMAND_DPS] = "spiral"
  131. self.assertEqual(self.subject.status, "clean_spot")
  132. def test_state(self):
  133. self.dps[POWER_DPS] = True
  134. self.dps[SWITCH_DPS] = True
  135. self.dps[ERROR_DPS] = 0
  136. self.dps[COMMAND_DPS] = "return_to_base"
  137. self.assertEqual(self.subject.state, STATE_RETURNING)
  138. self.dps[COMMAND_DPS] = "standby"
  139. self.assertEqual(self.subject.state, STATE_DOCKED)
  140. self.dps[COMMAND_DPS] = "random"
  141. self.assertEqual(self.subject.state, STATE_CLEANING)
  142. self.dps[POWER_DPS] = False
  143. self.assertEqual(self.subject.state, STATE_DOCKED)
  144. self.dps[POWER_DPS] = True
  145. self.dps[SWITCH_DPS] = False
  146. self.assertEqual(self.subject.state, STATE_DOCKED)
  147. self.dps[ERROR_DPS] = 1
  148. self.assertEqual(self.subject.state, STATE_ERROR)
  149. async def test_async_turn_on(self):
  150. async with assert_device_properties_set(
  151. self.subject._device,
  152. {POWER_DPS: True},
  153. ):
  154. await self.subject.async_turn_on()
  155. async def test_async_turn_off(self):
  156. async with assert_device_properties_set(
  157. self.subject._device,
  158. {POWER_DPS: False},
  159. ):
  160. await self.subject.async_turn_off()
  161. async def test_async_toggle(self):
  162. self.dps[POWER_DPS] = False
  163. async with assert_device_properties_set(
  164. self.subject._device,
  165. {POWER_DPS: True},
  166. ):
  167. await self.subject.async_toggle()
  168. async def test_async_start(self):
  169. async with assert_device_properties_set(
  170. self.subject._device,
  171. {SWITCH_DPS: True},
  172. ):
  173. await self.subject.async_start()
  174. async def test_async_pause(self):
  175. async with assert_device_properties_set(
  176. self.subject._device,
  177. {SWITCH_DPS: False},
  178. ):
  179. await self.subject.async_pause()
  180. async def test_async_return_to_base(self):
  181. async with assert_device_properties_set(
  182. self.subject._device,
  183. {COMMAND_DPS: "chargego"},
  184. ):
  185. await self.subject.async_return_to_base()
  186. async def test_async_clean_spot(self):
  187. async with assert_device_properties_set(
  188. self.subject._device,
  189. {COMMAND_DPS: "spiral"},
  190. ):
  191. await self.subject.async_clean_spot()
  192. async def test_async_locate(self):
  193. async with assert_device_properties_set(
  194. self.subject._device,
  195. {LOCATE_DPS: True},
  196. ):
  197. await self.subject.async_locate()
  198. async def test_async_send_standby_command(self):
  199. async with assert_device_properties_set(
  200. self.subject._device,
  201. {COMMAND_DPS: "standby"},
  202. ):
  203. await self.subject.async_send_command("standby")
  204. async def test_async_send_smart_command(self):
  205. async with assert_device_properties_set(
  206. self.subject._device,
  207. {COMMAND_DPS: "smart"},
  208. ):
  209. await self.subject.async_send_command("smart")
  210. async def test_async_send_random_command(self):
  211. async with assert_device_properties_set(
  212. self.subject._device,
  213. {COMMAND_DPS: "random"},
  214. ):
  215. await self.subject.async_send_command("random")
  216. async def test_async_send_wall_follow_command(self):
  217. async with assert_device_properties_set(
  218. self.subject._device,
  219. {COMMAND_DPS: "wall_follow"},
  220. ):
  221. await self.subject.async_send_command("wall_follow")
  222. async def test_async_send_reverse_command(self):
  223. async with assert_device_properties_set(
  224. self.subject._device,
  225. {DIRECTION_DPS: "backward"},
  226. ):
  227. await self.subject.async_send_command("reverse")
  228. async def test_async_send_left_command(self):
  229. async with assert_device_properties_set(
  230. self.subject._device,
  231. {DIRECTION_DPS: "turn_left"},
  232. ):
  233. await self.subject.async_send_command("left")
  234. async def test_async_send_right_command(self):
  235. async with assert_device_properties_set(
  236. self.subject._device,
  237. {DIRECTION_DPS: "turn_right"},
  238. ):
  239. await self.subject.async_send_command("right")
  240. async def test_async_send_stop_command(self):
  241. async with assert_device_properties_set(
  242. self.subject._device,
  243. {DIRECTION_DPS: "stop"},
  244. ):
  245. await self.subject.async_send_command("stop")
  246. def test_fan_speed(self):
  247. self.dps[FAN_DPS] = "2"
  248. self.assertEqual(self.subject.fan_speed, "quiet")
  249. def test_fan_speed_list(self):
  250. self.assertCountEqual(
  251. self.subject.fan_speed_list,
  252. [
  253. "strong",
  254. "normal",
  255. "quiet",
  256. "gentle",
  257. "closed",
  258. ],
  259. )
  260. async def test_async_set_fan_speed(self):
  261. async with assert_device_properties_set(self.subject._device, {FAN_DPS: "3"}):
  262. await self.subject.async_set_fan_speed(fan_speed="gentle")