4
0

test_kyvol_e30_vacuum.py 9.7 KB

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