test_kyvol_e30_vacuum.py 11 KB

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