test_kyvol_e30_vacuum.py 10 KB

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