test_kyvol_e30_vacuum.py 11 KB

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